Intermediate

AI-Powered Search

Move beyond keyword matching to semantic understanding. AI-powered search finds what users mean, not just what they type, transforming how teams discover and access knowledge.

From Keywords to Semantics

Traditional keyword search fails when users do not know the exact terminology. AI-powered semantic search solves this by understanding meaning:

User QueryKeyword Search ResultSemantic Search Result
"how to handle angry customers"Matches docs containing "angry customers"Finds de-escalation guides, complaint procedures, customer retention policies
"deployment process"Matches "deployment" OR "process"Finds CI/CD pipeline docs, release checklists, infrastructure runbooks
"why did we choose PostgreSQL?"Few or no resultsFinds architecture decision records, database evaluation documents

How Semantic Search Works

  1. Embed Documents

    Convert all documents into vector embeddings using a model like Voyage AI or text-embedding-3-large. Each embedding captures the semantic meaning of the text.

  2. Embed the Query

    When a user searches, convert their query into an embedding using the same model.

  3. Find Nearest Neighbors

    Use approximate nearest neighbor (ANN) algorithms to find the document embeddings closest to the query embedding.

  4. Re-rank Results

    Use a cross-encoder model to re-score the top candidates for higher precision.

Hybrid Search

The best enterprise search systems combine semantic and keyword approaches:

Python
def hybrid_search(query, alpha=0.7):
    # Semantic search (vector similarity)
    semantic_results = vector_db.search(
        embed(query), top_k=20
    )

    # Keyword search (BM25)
    keyword_results = bm25_index.search(
        query, top_k=20
    )

    # Combine with Reciprocal Rank Fusion
    combined = reciprocal_rank_fusion(
        semantic_results, keyword_results,
        weights=[alpha, 1 - alpha]
    )

    # Re-rank top candidates
    return reranker.rerank(query, combined[:10])

Search UX Patterns

  • Instant answers: Show a generated answer at the top with source citations, followed by traditional results
  • Faceted search: Allow filtering by source, date, team, document type, and other metadata
  • Auto-suggest: Use query logs and embeddings to suggest related queries as users type
  • Conversational search: Let users ask follow-up questions that maintain context from previous queries
  • Federated search: Search across multiple backends (wiki, Slack, Jira, code) in a single query

Measuring Search Quality

MetricWhat It MeasuresHow to Compute
NDCG@kQuality of ranking in top k resultsCompare against human-judged relevance scores
Recall@kFraction of relevant docs found in top kRequires known relevant doc set
MRRHow high the first relevant result appears1/rank of first relevant result
Click-through rateUser satisfaction signalTrack clicks on search results
Zero-result rateHow often search returns nothing usefulTrack queries with no clicks
Start with evaluation: Before building, create a test set of 50-100 real user queries with expected results. This lets you measure every change objectively rather than relying on anecdotal feedback.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.