Setup
Follow the instructions in the Qdrant Setup Guide to install Qdrant locally. Here is a guide to get API keys: Qdrant API Keys.Example: Custom Retriever for a PDF Knowledge Base
Below is a detailed example of how to implement a custom retriever function using theagno
library. This example demonstrates how to set up a knowledge base with PDF documents, define a custom retriever, and use it with an agent.
Asynchronous Implementation
Explanation
- Embedder and Vector Database Setup: We start by defining an embedder and initializing a connection to a vector database. This setup is crucial for converting queries into embeddings and storing them in the database.
- Loading the Knowledge Base: The knowledge base is loaded with PDF documents. This step involves converting the documents into embeddings and storing them in the vector database.
-
Custom Retriever Function: The
retriever
function is defined to handle the retrieval of documents. It takes a query, converts it into an embedding, and searches the vector database for relevant documents. - Agent Initialization: An agent is initialized with the custom retriever. The agent uses this retriever to search the knowledge base and retrieve information.
-
Example Query: The
main
function demonstrates how to use the agent to perform a query and retrieve information from the knowledge base.
Developer Resources
- View Sync Retriever
- View Async Retriever