Skip to main content
Keyword search finds content by matching exact words and phrases. It uses your database’s full-text search capabilities to find documents containing specific terms.
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector, SearchType

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="docs",
        db_url=db_url,
        search_type=SearchType.keyword,
    ),
)

How It Works

  1. Text parsing: Your query is broken into searchable terms
  2. Index lookup: The system finds documents containing those terms
  3. Ranking: Results are ordered by relevance (term frequency, document length, etc.)
When using PgVector, this leverages PostgreSQL’s built-in full-text search. Other databases use their native text search capabilities.
ScenarioWhy Keyword Search Works
Searching for specific termsExact match on product names, codes, IDs
Error codes and identifiersPrecise matching without semantic interpretation
Technical terminologyUsers know the exact terms to search
Structured data queriesMatching specific field values
Use vector search if users phrase things differently than your docs. Use hybrid search if you want both exact matching and semantic understanding.

Configuration

Basic Setup

from agno.vectordb.pgvector import PgVector, SearchType

vector_db = PgVector(
    table_name="docs",
    db_url=db_url,
    search_type=SearchType.keyword,
)

With Reranking

Add a reranker to improve result ordering:
from agno.knowledge.reranker.cohere import CohereReranker

vector_db = PgVector(
    table_name="docs",
    db_url=db_url,
    search_type=SearchType.keyword,
    reranker=CohereReranker(),
)

Example

keyword_search.py
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector, SearchType

db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"

knowledge = Knowledge(
    vector_db=PgVector(
        table_name="recipes",
        db_url=db_url,
        search_type=SearchType.keyword,
    ),
)

# Load content
knowledge.insert(
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
)

# Search by exact terms
results = knowledge.search("chicken coconut soup", max_results=5)
for doc in results:
    print(doc.content[:200])

Next Steps