Find answers from the community

Updated 2 years ago

Pinecone

I have a question. When I'm building the index, all fine. Docs explain everything really well. In case, I want to build a graph based index of many types of source documents. Let's say,

  • SQL DBs
  • Speadsheets
  • PDFs
  • Webpages
In my case, I'm ingesting them in one go using llama_index. Loading documents -> creating index -> making a query engine on top -> querying it. That's easy so far.

However, when during inference, when I'm not building the index, when I just want to directly connect to Pinecone vector db and query it, there's no straightforward way. Everywhere it mentions to use load_data from document, but what if I don't want nodes from local storage, but from remote index. I think I'm missing the key conceptual understanding of llama_index. How do I make it work?
L
H
10 comments
Once you create the index, you can connect to it again by setting up the vector_store and storage context again, and do something like this

GPTVectorStoreIndex([], storage_context=storage_context)

This is true for a large majority of vector stores

Example is here actually
https://gpt-index.readthedocs.io/en/latest/how_to/storage/customization.html#vector-store-integrations-and-storage
So you just give it an empty list and a storage context?
Let me look into the link you provided.
Yea exactly, just assuming you setup the storage context to have a vector_store
Plain Text
from llama_index.storage.storage_context import StorageContext
from llama_index import LangchainEmbedding
from langchain.embeddings import OpenAIEmbeddings
from llama_index import download_loader


# Initialize the pinecone remote vector store
pinecone.init(api_key=PINECONE_API_KEY, environment=PINECONE_API_ENV)
index = pinecone.Index("websources")


# construct vector store
vector_store = PineconeVectorStore(pinecone_index=index)

# create storage context
storage_context = StorageContext.from_defaults(vector_store=vector_store)


# LLM for Service Context
chat_llm =llm = AzureOpenAI(
    deployment_name="Sample", 
    model_kwargs={
        "api_key": API_KEY,
        "api_base": API_BASE,
        "api_type": "azure",
        "api_version": "2023-03-15-preview",
    }
)

# Embedding LM for Service Context
llm_predictor = LLMPredictor(llm=chat_llm)

embedding_llm = LangchainEmbedding(
    OpenAIEmbeddings(
        model="text-embedding-ada-002",
        deployment=EMBED_DEPLOYMENT,
        openai_api_key=API_KEY,
        openai_api_base=API_BASE,
        openai_api_type = "azure",
        openai_api_version="2023-03-15-preview",
    ),
    embed_batch_size=1,
)

embed_model = embedding_llm

service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embed_model)

# load documents
# documents = SimpleDirectoryReader("./data").load_data()

# create index, which will insert documents/vectors to pinecone
index = VectorStoreIndex.from_documents([], storage_context=storage_context, service_context=service_context)
Plain Text
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("Tell me more about stroke?")


This gives me
Response(response=None, source_nodes=[], extra_info={})
Basically the problem is, I'm unable to get that remote information onto my local machine as nodes that I can then put into a graph as one piece among heterogeneous data sources and query it.
Did you create the index using llama-index first? I've ran this before and it worked.

In any case, I'll run this again tomorrow morning and share the script
Yes. I created the index with llama_index, but anyhow that shouldn't affect it.

Data can be ingested anywhere else, another API, etc into Pinecone. Once its there, there must be a way to pull and query it with llama. Here the first touch point with data is llama_index hooking up with storage_context.
Right, the data can come from anywhere yes. But it needs to be inserted with llama-index eventually in order to have the correct format πŸ‘
Add a reply
Sign up and join the conversation on Discord