I have a doubt regarding the knowledge-base implementation, where we maintain two databases:
-
ContentsDB (PostgresDb)
-
VectorDB (pgvector)
In ContentsDB, we have an attribute access_count , and my expectation is that it should be updated every time a document is accessed.
Example
If in a single search I retrieve ~10 documents, then for each unique knowledge content, access_count should be incremented by 1. However, currently in the code this update is not happening which is why I am raising this issue.
Code references fix:
ContentsDB increment method (Postgres)
# libs/agno/agno/db/postgres/postgres.py
def increment_knowledge_access_count(self, id: str) -> Optional[KnowledgeRow]:
...
stmt = (
update(table)
.where(table.c.id == id)
.values(
access_count=func.coalesce(table.c.access_count, 0) + 1,
updated_at=int(time.time())
)
.returning(*table.c)
)
...
VectorDB search result construction (pgvector)
# libs/agno/agno/vectordb/pgvector/pgvector.py
search_results.append(
Document(
id=result.id,
name=result.name,
meta_data=result.meta_data,
content=result.content,
embedder=self.embedder,
embedding=result.embedding,
usage=result.usage,
content_id=result.content_id # additional select
)
)
Knowledge layer search logic
# libs/agno/agno/knowledge/knowledge.py
def search(...):
...
results = self.vector_db.search(query=query, limit=_max_results, filters=filters)
if self.contents_db:
unique_content_ids = set(item.content_id for item in results)
for content_id in unique_content_ids:
self.contents_db.increment_knowledge_access_count(content_id)
return results
Proposal
Increment access_count in ContentsDB whenever knowledge content is accessed through a search.
Only increment once per content_id per search (avoid duplicates).
This helps track document usage across both ContentsDB and VectorDB consistently.
Should we proceed with this approach, or is there a better way to handle access_count updates across ContentsDB and VectorDB?