Hi, I’m building a custom knowledge management system UI using Agno and was wondering if there’s a way to programmatically add and delete knowledge (like PDF or text files) from the vector database. For example, when a user uploads a file (e.g., report.pdf
), I’d like it to be embedded and stored so it becomes searchable. Later, if the user deletes the file, I want its corresponding embeddings removed from the vector store as well. Is there any recommended approach for handling this within Agno agent? Code examples would be really helpful. Thanks!
Hey @darshan_naidu
thanks for reaching out and supporting Agno. I’ve shared this with the team, we’re working through all requests one by one and will get back to you soon.
If it’s urgent, please let us know. We appreciate your patience!
Thanks so much, @Monali! Yes, it’s quite urgent as I’m actively working on the feature right now. I’d really appreciate any guidance or a quick workaround from the team in the meantime. Looking forward to your update!
Hi @darshan_naidu, yes for now you can add documents using either load or load_document. Here’s how-
vector_db = LanceDb(
table_name="recipes",
uri="tmp/lancedb", # You can change this path to store data elsewhere
)
# Initialize the JSONKnowledgeBase
knowledge_base = JSONKnowledgeBase(
vector_db=vector_db,
num_documents=5,
)
knowledge_base.load_document(
path="path/to/file",
metadata={"user_id": "jordan_mitchell", "document_type": "cv", "year": 2025},
recreate=True, # Set to True only for the first run, then set to False
)
# Load second document with user_2 metadata
knowledge_base.load_document(
path="path/to/file",
metadata={"user_id": "taylor_brooks", "document_type": "cv", "year": 2025},
)
or
knowledge_base = JSONKnowledgeBase(
path=Path("tmp/docs"),
vector_db=PgVector(
table_name="json_documents",
db_url=db_url,
),
num_documents=5, # Number of documents to return on search
)
# Load the knowledge base
knowledge_base.load(recreate=False, upsert=True) # <-- using upsert=True will only add new documents or if there's any update in existing document.
That said, we dont have support for delete_document as of now but adding it to feature request and will get it out asap!
Thanks
Thanks, @kausmos! Really looking forward to the delete_document feature — it would make the system much more complete for our use case. Hope it can be added soon!