----------------------
To connect to your existing Pinecone index and create a query engine from it, you can follow these steps:
- First, you need to initialize Pinecone with your API key. Replace
<Your Pinecone API key>
with your actual Pinecone API key.
import os
import pinecone
api_key = "<Your Pinecone API key>"
pinecone.init(api_key=api_key, environment="eu-west1-gcp")
- Then, you can connect to your existing Pinecone index. Replace
"quickstart-index"
with the name of your existing Pinecone index.
pinecone_index = pinecone.Index("quickstart-index")
- After connecting to the Pinecone index, you can create a
PineconeVectorStore
from it.
from llama_index.vector_stores.pinecone import PineconeVectorStore
vector_store = PineconeVectorStore(pinecone_index=pinecone_index)
- Then, you can create a
VectorStoreIndex
from the PineconeVectorStore
.
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)
- Finally, you can create a retriever from the
VectorStoreIndex
and use it as a query engine.
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.