liveBook · Manning

Hybrid search

As explained in Build an AI Agent (From Scratch)

Hybrid search combines multiple retrieval methods and integrates their scores to rank results.

Hybrid search combines retrieval methods so each covers the others’ weaknesses. Keyword search finds exact names, codes, syntax, or special characters; vector search finds semantic matches despite different wording. section 5.2.2 section 5.2.4

A practical ranking pipeline normalizes scores from keyword and vector results, calculates a weighted average, and ranks the combined results. Exact queries such as get_user_by_id and semantic questions such as how to get user information can then share one retrieval path. section 5.2.4

Choose retrieval methods according to the information the query requires:

  • Use keyword search for exact words, function names, error codes, or code syntax. section 5.2.4
  • Use vector search for natural-language questions and semantic similarity, including related terms such as sofa and couch. section 5.2.2 section 5.2.4
  • Add graph search for relationship traversal and structure-based search when folders, files, or archive layouts carry useful information. section 5.2.4
Table 5.1 Recommended search methods by situation

Situation

Recommended method

Reason

Exact word/code search

Keyword search

Exact matching needed for get_user_by_id, error code 404, etc.

Natural language questions

Vector search

Semantic search needed for queries like “how to store data”

Relationship-based questions

Graph search

Relationship traversal needed for “code that calls this function”

Folder/file structure exploration

Structure-based search

When structure itself is information, like zip files or codebases

Production environments

Hybrid search

Combines the advantages of multiple methods

Compare retrieval methods by query situation, matching requirement, and production use. section 5.2.4

How Build an AI Agent (From Scratch) covers it

How deep it goes
Explains score normalization and weighted averaging, but stops short of specifying an implementation or weight-selection procedure.
Examples
Uses get_user_by_id, error code 404, natural-language storage questions, sofa and couch, codebases, and extracted zip files.
What you can do after
Apply it by combining normalized keyword and vector scores into a weighted final ranking.
How it connects
Connects keyword search, vector search, graph search, and structure-based search through situation-specific retrieval choices.

Also explained in

Compare how 8 books explain hybrid search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.