Find answers from the community

Updated 9 months ago

i need to connect my existing pinecone index and make a query engine from it. How can I do

@kapa.ai i need to connect my existing pinecone index and make a query engine from it. How can I do that?
k
3 comments
Please stand by @cybersmiths as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To connect to your existing Pinecone index and create a query engine from it, you can follow these steps:

  1. First, you need to initialize Pinecone with your API key. Replace <Your Pinecone API key> with your actual Pinecone API key.
Plain Text
import os
import pinecone

api_key = "<Your Pinecone API key>"
pinecone.init(api_key=api_key, environment="eu-west1-gcp")


  1. Then, you can connect to your existing Pinecone index. Replace "quickstart-index" with the name of your existing Pinecone index.
Plain Text
pinecone_index = pinecone.Index("quickstart-index")


  1. After connecting to the Pinecone index, you can create a PineconeVectorStore from it.
Plain Text
from llama_index.vector_stores.pinecone import PineconeVectorStore

vector_store = PineconeVectorStore(pinecone_index=pinecone_index)


  1. Then, you can create a VectorStoreIndex from the PineconeVectorStore.
Plain Text
from llama_index.core import VectorStoreIndex
from llama_index.core import StorageContext

storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)


  1. Finally, you can create a retriever from the VectorStoreIndex and use it as a query engine.
Plain Text
retriever = index.as_retriever()


Please note that in the step 4, documents is a variable that should contain your documents. You need to replace it with your actual documents.
Sources:
  • Jerryjliu > Llama_index > Blob > Main > Docs > Examples > Vector_stores > Existing_data > Guide: Using Vector Store Index with Existing Pinecone Vector Store ()
  • Jerryjliu > Llama_index > Blob > Main > Docs > Examples > Low_level > Building Response Synthesis from Scratch > Setup > Build Pinecone Index, Get Retriever ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord