Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
This example demonstrates how to implement Agentic RAG using LanceDB with Cohere reranking for improved search results.
Code
agentic_rag_with_reranking.py
"""
1. Run: `pip install openai agno cohere lancedb tantivy sqlalchemy pandas` to install the dependencies
2. Export your OPENAI_API_KEY and CO_API_KEY
3. Run: `python cookbook/agent_concepts/rag/agentic_rag_with_reranking.py` to run the agent
"""
from agno.agent import Agent
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reranker.cohere import CohereReranker
from agno.models.openai import OpenAIChat
from agno.vectordb.lancedb import LanceDb, SearchType
knowledge = Knowledge(
# Use LanceDB as the vector database and store embeddings in the `agno_docs` table
vector_db=LanceDb(
uri="tmp/lancedb",
table_name="agno_docs",
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(
id="text-embedding-3-small"
), # Use OpenAI for embeddings
reranker=CohereReranker(
model="rerank-multilingual-v3.0"
), # Use Cohere for reranking
),
)
knowledge.add_content_sync(
name="Agno Docs", url="https://docs.agno.com/introduction.md"
)
agent = Agent(
model=OpenAIChat(id="gpt-5-mini"),
# Agentic RAG is enabled by default when `knowledge` is provided to the Agent.
knowledge=knowledge,
markdown=True,
)
if __name__ == "__main__":
# Load the knowledge base, comment after first run
# agent.knowledge.load(recreate=True)
agent.print_response("What are Agno's key features?")
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U agno cohere lancedb tantivy sqlalchemy pandas
Set environment variables
export OPENAI_API_KEY=your_openai_api_key
export CO_API_KEY=your_cohere_api_key
Create a Python file
Create a Python file and add the above code.touch agentic_rag_with_reranking.py
Run Agent
python agentic_rag_with_reranking.py
Find All Cookbooks
Explore all the available cookbooks in the Agno repository. Click the link below to view the code on GitHub:Agno Cookbooks on GitHub