Skip to main content
Contents Database is an optional component that tracks what you’ve added to your knowledge base. While the vector database stores embeddings for search, Contents Database stores metadata about each piece of content: what it is, when you added it, and its processing status.
from agno.knowledge.knowledge import Knowledge
from agno.db.postgres import PostgresDb
from agno.vectordb.pgvector import PgVector

knowledge = Knowledge(
    vector_db=PgVector(table_name="vectors", db_url=db_url),
    contents_db=PostgresDb(db_url=db_url),  # Enables content tracking
)

Why Use Content DB

Without Content DB, you can search your knowledge base but can’t see what’s in it or manage individual pieces of content. With Content DB, you get:
  • Visibility: See all content that’s been added, track processing status, view metadata
  • Management: Delete specific content and automatically clean up associated vectors
  • Updates: Edit names, descriptions, and metadata without rebuilding the knowledge base
  • Filtering: Use agentic filtering to filter search results by metadata
Contents DB is required for agentic filtering and the AgentOS Knowledge UI.

Setup

Agno supports multiple database backends:
from agno.db.postgres import PostgresDb

contents_db = PostgresDb(
    db_url="postgresql+psycopg://user:pass@localhost:5432/db",
    knowledge_table="knowledge_contents"  # Optional custom table name
)
Other supported backends: PostgreSQL (recommended for production), SQLite (development), MySQL, MongoDB, Redis, DynamoDB, Firestore.

Managing Content

Add Content with Metadata

knowledge.insert(
    name="Product Manual",
    path="docs/manual.pdf",
    metadata={"department": "engineering", "version": "2.1"}
)

List Content

contents, total_count = knowledge.get_content(
    limit=20,
    page=1,
    sort_by="created_at",
    sort_order="desc"
)

for content in contents:
    print(content.name, content.status, content.created_at)

Get Content by ID

content = knowledge.get_content_by_id(content_id)

print(content.name)         # Content name
print(content.description)  # Description
print(content.metadata)     # Custom metadata
print(content.file_type)    # File type (.pdf, .txt, etc.)
print(content.size)         # File size in bytes
print(content.status)       # Processing status
print(content.created_at)   # When it was added
print(content.updated_at)   # Last modification

Delete Content

Deleting content automatically:
  1. Removes the content metadata from Content DB
  2. Deletes associated vectors from the vector database
  3. Maintains consistency between both databases
# Delete specific content
knowledge.remove_content_by_id(content_id)

# Delete all content
knowledge.remove_all_content()

Filter by Metadata

# Get available filter keys
valid_filters = knowledge.get_filters()

# Search with filters
results = knowledge.search(
    query="technical documentation",
    filters={"department": "engineering"}
)

Schema

Content DB stores the following fields for each piece of content:
FieldTypeDescription
idstrUnique identifier
namestrContent name
descriptionstrContent description
metadatadictCustom metadata
typestrContent type
sizeintFile size in bytes
linked_tostrID of linked content
access_countintNumber of times accessed
statusstrProcessing status
status_messagestrStatus details
created_atintCreated timestamp
updated_atintUpdated timestamp
external_idstrExternal ID for integrations like LightRAG

AgentOS Integration

Content DB is required for the AgentOS Knowledge UI. With it, the web interface provides:
  • Content Browser: View all uploaded content with metadata
  • Upload Interface: Add new content through the web UI
  • Status Monitoring: Real-time processing status updates
  • Metadata Editor: Update content metadata through forms
  • Search and Filtering: Find content by metadata attributes
  • Bulk Operations: Manage multiple content items at once
from agno.os import AgentOS
from agno.agent import Agent

knowledge = Knowledge(
    vector_db=PgVector(table_name="vectors", db_url=db_url),
    contents_db=PostgresDb(db_url=db_url),
)

agent = Agent(name="Knowledge Agent", knowledge=knowledge)

app = AgentOS(
    id="knowledge-demo",
    agents=[agent],
)
See AgentOS Knowledge Management for more details.

Next Steps