Find answers from the community

Updated 2 months ago

How can we restrict the LLM to answer other the data inside the vector database?

How can we restrict the LLM to answer other the data inside the vector database?
k
3 comments
Please stand by @Navagridhar Ramsait C as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
LlamaIndex provides multiple integration points with vector databases, which can be used to restrict the LLM to answer based on the data inside the vector database.

  1. LlamaIndex can use a vector store itself as an index. This index can store documents and be used to answer queries.
  1. LlamaIndex can load data from vector stores, similar to any other data connector. This data can then be used within LlamaIndex data structures.
For example, you can perform auto-retrieval in LlamaIndex. Given a natural language query, LlamaIndex first uses the LLM to infer a set of metadata filters as well as the right query string to pass to the vector database. This overall query bundle is then executed against the vector database. This allows for more dynamic, expressive forms of retrieval beyond top-k semantic search.

Here is an example of how to set up auto-retrieval with a vector database using Pinecone:

Plain Text
import pinecone
import os

api_key = os.environ["PINECONE_API_KEY"]
pinecone.init(api_key=api_key, environment="us-west1-gcp")

# dimensions are for text-embedding-ada-002
try:
    pinecone.create_index(
        "quickstart", dimension=1536, metric="euclidean", pod_type="p1"
    )
except Exception:
    # most likely index already exists
    pass

pinecone_index = pinecone.Index("quickstart")

from llama_index import VectorStoreIndex, StorageContext
from llama_index.vector_stores import PineconeVectorStore

from llama_index.schema import TextNode


This code initializes a Pinecone vector database, creates an index, and sets up the necessary imports from LlamaIndex to use this vector database.
For more details, you can refer to the documentation () and the notebook examples () provided in the extracts.
----------------------
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