LlamaIndex Vector Database
Search an existing LlamaIndex index from your Knowledge Base through a retriever.
The example uses OpenAI-backed embeddings or models. Set your key before running it:
export OPENAI_API_KEY="your-api-key"Download the sample essay before running SimpleDirectoryReader:
mkdir -p data/paul_graham
curl --fail --location https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt --output data/paul_graham/paul_graham_essay.txtSetup
uv pip install -U agno llama-index-core llama-index-readers-file llama-index-embeddings-openai openaiExample
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.llamaindex import LlamaIndexVectorDb
from llama_index.core import SimpleDirectoryReader, StorageContext, VectorStoreIndex
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.retrievers import VectorIndexRetriever
# Build a LlamaIndex index over your documents
documents = SimpleDirectoryReader("data/paul_graham").load_data()
splitter = SentenceSplitter(chunk_size=1024)
nodes = splitter.get_nodes_from_documents(documents)
storage_context = StorageContext.from_defaults()
index = VectorStoreIndex(nodes=nodes, storage_context=storage_context)
# Point Agno at the index through a retriever
knowledge = Knowledge(
vector_db=LlamaIndexVectorDb(knowledge_retriever=VectorIndexRetriever(index))
)
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
)
agent.print_response(
"Explain what this text means: low end eats the high end", markdown=True
)LlamaIndexVectorDb wraps a LlamaIndex retriever. Searches call knowledge_retriever.retrieve() and convert the returned nodes to Agno documents.
LlamaIndexVectorDb is search-only. insert() and upsert() raise NotImplementedError. Load and index documents through LlamaIndex, then wire the retriever to Agno. Search filters are not supported.
LlamaIndexVectorDb Params
| Parameter | Type | Default | Description |
|---|---|---|---|
knowledge_retriever | BaseRetriever | - | A LlamaIndex retriever, for example VectorIndexRetriever. Required. |
loader | Callable | None | Optional loader function. |
name | str | None | Name of the vector database. |
description | str | None | Description of the vector database. |
Native Agno user_id scoping is not applied by this wrapper. Configure user-specific retrieval in the external retriever or server when needed.