Hybrid SearchKnowledge GraphAI Agent

Keyword, semantic and knowledge graph search: hybrid search explained

Keyword search, semantic search and knowledge graph search are three ways to retrieve data for an LLM or an AI agent. This guide covers how each one works, how they differ, how hybrid search combines them with rank fusion and a reranker, and the best use cases for each.

By Rahmatullah Musawi · · 9 min read · sources checked 8 October 2026

Key points

  • Keyword search finds precise word or phrase matches through an inverted index and ranks them with BM25.[1] [2]
  • Semantic search turns text into vectors called embeddings and can find a text that contains none of the words in the query.[3]
  • Knowledge graph search follows the connections between entities to find information that is only indirectly related to the query.[4]
  • Hybrid search combines keyword search and vector search to use the strengths of both: the two run in parallel and their results are merged.[5] [6]
  • In Anthropic's tests, embeddings plus BM25 is better than embeddings on their own, and reranking is better than no reranking.[1]

Retrieval finds the text an LLM needs before it answers: RAG, retrieval-augmented generation, retrieves relevant information from a knowledge base and appends it to the user's prompt.1 Anthropic counts retrieval, with tools and memory, among the augmentations that make an LLM the basic building block of agentic systems.7

Each search method is shown with a published example, from what goes in to what comes out.

What is keyword search?

Keyword search, also called full-text search5 or lexical search,8 finds a text by its words: the ranking function BM25 uses lexical matching to find precise word or phrase matches.1

Example: a keyword search finds the documents that contain the words
Two documents and the query +Quick +fox, from Elastic's guide to Elasticsearch; a preceding + means that the word must be present.9 Under each marked word stands the token it matched.
Query+Quick +fox→as tokensquickfox
1

The quickquick brown foxfox jumped over the lazy dog

match
2

Quickquick brown foxesfox leap over lazy dogs in summer

match
Step 1 · text analysis

Text is transformed into a format optimized for searching, and a query is analyzed the same way as the indexed text.2 Here Quick becomes quick, foxes becomes fox, and jumped and leap both become jump.9

Step 2 · inverted index

The index maps each token to the documents that contain it.2 The entries for quick and for fox both name Doc 1 and Doc 2. Typed as it is, the query would not match any document.9

Step 3 · BM25 ranking

BM25 calculates relevance scores from term frequency, document frequency and document length.2 It builds on TF-IDF, which measures how important a word is to a document in a collection, and also considers the length of the document.1

Keyword search is strongest where the exact string matters. For the query “Error code TS-999”, BM25 looks for this specific text string, while an embedding model might find content about error codes in general and miss the exact match.1 Product codes, highly specialized jargon, dates and people's names are further cases.5

Its limit is wording: it needs a keyword match. Information that is conceptually similar to the query but has no keyword match in the inverted index is found by the next method.5

What is semantic search?

Semantic search matches the meaning of the words in a query, not just the words themselves.10 4 It is powered by vector search: text is turned into embeddings, numerical representations of data and related contexts.10

Example: the same three sentences, ranked by keywords and by meaning
The query is “When did we go to the moon?”. The sentences and their similarity to the query are those of OpenAI's documentation.3
BY KEYWORDSBY MEANING1C40%2B27%3A0%1A65%2B43%3C28%
A

The first lunar landing occurred in July of 1969.

B

The first man on the moon was Neil Armstrong.

C

When I ate the moon cake, it was delicious.

Sentence A is the most relevant result, yet it contains none of the words in the query:3 by keywords it is last, by meaning it is first.

The same similarities as distances · the nearer a sentence, the more similar
BY KEYWORDS0%50%?A0%B27%C40%BY MEANING0%50%?A65%B43%C28%

The query is the blue point in the centre. Each sentence is drawn as far from it as it is unlike the query: a similarity of 0% lies on the outer ring. The direction of a point has no meaning. By keywords A lies on the outer ring; by meaning it is the nearest.3

Step 1 · embedding model

The documents are broken down into smaller chunks of text, and an embedding model converts each chunk into a vector that encodes its meaning.1 At search time the query is transformed into an embedding too.10

Step 2 · vector database

It stores the embeddings and allows searching them by semantic similarity.1

Step 3 · nearest neighbours

The k-nearest-neighbour algorithm matches the vector of the query to the vectors of the existing documents.10 The distance between two vectors measures their relatedness: a small distance suggests high relatedness.11

Step 1 in numbers · what OpenAI's embedding model returns for one text
Your text string goes here→-0.006929283495992422-0.005336422007530928-4.547132266452536e-5-0.024047505110502243… 1,536 numbers in all
The four numbers are those of the example in OpenAI's embeddings guide; by default, the model text-embedding-3-small returns 1,536 numbers for a text.11

The limit is the reverse of keyword search: embedding models capture semantic relationships well, but they can miss exact matches,1 for example when a query needs an exact date.12

What is knowledge graph search?

A knowledge graph represents a network of real-world entities, such as objects, events, situations or concepts, and the relationships between them.13 In IBM's example, the nodes IBM and Ogilvy are joined by an edge that marks a customer relationship.13 Knowledge graph search follows such connections to find information that is only indirectly related to the query.4

Example: a graph search reaches a fact that does not mention Alice
Three stored facts and one query, from the Hindsight documentation. The amber names are the stops of the path that Hindsight traverses through entity links; the words between two stops are the fact that joins them.14
Query“Was Alice affected by recent issues?”
Alice
Fact 1 is the tech lead on
Project Atlas
Fact 2 uses
Kubernetes
Fact 3 cluster had an outage Tuesday
The outage: where the path ends

RAG stops here. It retrieves facts about Alice only (no semantic similarity to “issues”).14

The graph search goes on. Hindsight links all facts that mention the same entity.15 It extracts the entities of the query and traverses Alice, Project Atlas, Kubernetes and the outage through the entity links.14

The same three facts as a graph
RAG RETRIEVES FACTS ABOUT ALICE ONLYQUERYAliceProject AtlasKubernetesthe outageis the tech lead onusescluster had an outage TuesdayTHE GRAPH SEARCH FOLLOWS THE BLUE LINKS

The amber points are the things the facts name (Alice, Project Atlas, Kubernetes), and the words on a link are the stored fact it stands for. The blue links are the path of the search, from Alice to the outage; the dashed box marks the fact that names Alice, where RAG stops.14 Showing each fact as one link, with the query entering at Alice, is this article’s own drawing.

A graph search finds what is connected, where the two other methods find what is similar in wording or in meaning. Microsoft's GraphRAG slices its input into text units and extracts all entities, relationships and key claims from them;16 the project describes itself as a pipeline that extracts structured data from unstructured text “using the power of LLMs”.17 Its local search enters the graph at the entities that are semantically related to the query.18

A graph also supports questions about a whole collection. GraphRAG clusters the graph into communities and writes a summary of each one;16 its global search answers a question such as “What are the most significant values of the herbs mentioned in this notebook?” from those community reports.19

A graph has its price: Microsoft warns that GraphRAG indexing can be an expensive operation,17 and it calls global search a resource-intensive method.19

Keyword, semantic and graph search: differences

The three methods differ in what they match, in what has to be built before the first search, and in what they miss.

Keyword searchSemantic searchKnowledge graph search
Example“Error code TS-999” finds the text with that exact string1“When did we go to the moon?” gives its highest score to “The first lunar landing occurred in July of 1969.”3“Was Alice affected by recent issues?” reaches a fact about a Kubernetes outage14
Matches byWords: precise word or phrase matches1Meaning: the stored vectors nearest to the query10Connections: the links between entities4
Built before searchingAn inverted index of tokens2One embedding per chunk, in a vector database1A graph of the entities and relationships found in the text16
Finds wellUnique identifiers and technical terms;1 product codes, jargon, dates and names5Paraphrases and synonyms: “meeting” matches “conference”4Indirect relationships across several entities;4 questions about a dataset as a whole19
Weak pointA relevant text that shares no words with the query3Exact matches, such as one error code1Building the graph can be expensive17

Hybrid search: combining the methods

The methods are combined because no single search method handles every kind of query well.4 Hybrid search combines keyword search and vector search to use the strengths of both: the two searches run in parallel, and their results are merged into one ranked list.5 6 Anthropic's pipeline for RAG is an example.1

Example: Anthropic's pipeline with two searches, rank fusion and a reranker
One query, from top to bottom. Every line is fixed in code. The numbers match the notes.
QUERYBM25 searchexact matches1Embeddingssimilar meaning2Rank fusionmerges and deduplicates3Rerankerkeeps the top 20 of 1504LLManswers from the top chunks5
  1. BM25 searchFinds the top chunks based on exact matches.1
  2. Embedding searchFinds the top chunks based on semantic similarity.1
  3. Rank fusionCombines the two result lists and removes duplicates.1
  4. RerankerA reranking model gives each chunk a score for its relevance to the query, so that only the most relevant chunks are passed on. In Anthropic's test, 150 chunks went in and the top 20 were kept.1
  5. LLMThe top chunks are passed to the model as context for the answer.1

Azure AI Search, OpenAI's Retrieval API and Hindsight merge the lists with reciprocal rank fusion (RRF).5 3 4 Each list gives a document the score 1/(rank + k), where k is a constant, and the scores are added.20 Elastic's documentation works one case through.21

Example: two ranked lists become one with reciprocal rank fusion
Five documents and two searches, from Elastic's documentation, with k = 1. Each list gives a document 1/(k + rank), and the two values are added: document 3 gets 1/(1+2) + 1/(1+1) = 0.8333.21
share from the keyword listshare from the vector listA higher rank gives a longer piece: rank 1 = 1/2, rank 2 = 1/3, rank 3 = 1/4, rank 4 = 1/5.
1Doc 3
rank 2rank 1
0.8333
2Doc 2
rank 3rank 2
0.5833
3Doc 4
rank 1
0.5000
4Doc 1
rank 4rank 3
0.4500
5Doc 5
rank 4
0.2000
Elastic's request returns the top three; the scores of all five are from its calculation.21

Document 3 gets a long piece from both lists and ranks first; document 4 is first in the keyword list, but has nothing from the vector list, and ends third. Microsoft writes that the algorithm performs best with a small k such as 60.20 RRF requires no tuning, and the relevance indicators of the searches do not have to be related to each other.21

Some systems let you weight the searches. In Weaviate, a value called alpha runs from 0, keyword search only, to 1, vector search only; the server default is 0.75.6 OpenAI's API has one weight for embedding matches and one for keyword matches inside its rank fusion.3

Anthropic measured each step in a test of its own, together with a technique it calls Contextual Retrieval: a short, chunk-specific explanation is added to each chunk before it is embedded and indexed.1

Anthropic's test: a chunk in context, and the failure rate with each added step
The first panel shows what “contextual” means: the added context is in blue. The failure rate is the percentage of relevant documents that are not retrieved within the top 20 chunks; its first row is the rate before the technique was added.1
One chunkAnthropic's example
OriginalThe company's revenue grew by 3% over the previous quarter.
In contextThis chunk is from an SEC filing on ACME corp's performance in Q2 2023; the previous quarter's revenue was $314 million. The company's revenue grew by 3% over the previous quarter.
Failure ratelower is better
Starting point5.7%
Contextual embeddings3.7%
+ contextual BM252.9%
+ reranker1.9%
Average over four kinds of text (codebases, fiction, arXiv papers and science papers) with the embedding model Gemini Text 004.1

Microsoft reports a gain from the same combination in its own product: in its benchmark testing, hybrid retrieval with a semantic ranker offers significant benefits in search relevance.5 The cost of a reranker is time: it is an extra step at runtime and adds a small amount of latency.1

A graph search can join in two places. The two examples in the figure place it beside the other searches and after them.

Examples: the graph search beside the other searches and after them
Both diagrams read from left to right.
Beside the other searches
Hindsight runs four searches in parallel (semantic, keyword, graph and temporal), fuses their results with RRF and reranks them with a cross-encoder.4
QUERYRank fusionRerankerSemanticKeywordGraphTime
After the other searches
Neo4j's HybridCypherRetriever finds a first set of nodes with a combined vector and full-text search, then retrieves additional information from the graph for each node.12
QUERYGraph traversalVector searchFull-text search
TopicWhat is Hindsight? Agent memory, knowledge graph and use cases describes how recall runs its four searches and ranks the results.

Retrieval in AI agents

Six products for agents and for RAG show the range, from one keyword search to four searches in parallel:

ProductSearches byHow
Hermes AgentKeywordIts session search is a full-text search with SQLite's FTS5 engine and makes no LLM calls. A query is keywords, a phrase in quotes or a Boolean expression such as docker OR kubernetes.22 External memory providers add capabilities such as knowledge graphs and semantic search.23
OpenClawSemantic and keywordMemory search runs a vector search and a BM25 keyword search in parallel and merges the results.24
HindsightSemantic, keyword, graph and timeFour searches in parallel, fused by rank and reranked.4
GraphitiSemantic, keyword and graphHybrid retrieval that combines semantic embeddings, keyword search (BM25) and graph traversal.25
Microsoft GraphRAGGraphLocal search for questions about specific entities, global search for questions about the dataset as a whole.19
Azure AI SearchKeyword, vector or hybridIn agentic retrieval, an LLM can break a complex query into smaller subqueries, which run in parallel and are reranked.26
TopicWhat is Hermes Agent? How it works, its structure and use cases describes what the agent keeps between two sessions.

In the pipelines above, the searches are fixed steps. An agent can also search “just in time”: it keeps only lightweight identifiers such as file paths and loads the data with tools while it runs.27

Example: a coding agent with two search tools, grep and semantic search
The two tools are those of Cursor's agent, which makes heavy use of grep as well as semantic search.28 A dashed line is a call the model decides on while the task runs; a solid line is a result that comes back.
TASKAgentcalls its search toolsANSWERgrepexact textSemantic searchby meaning
  • AgentCurrent models can generate their own search queries and select the appropriate tools.7
  • grepClaude Code uses it too: it retrieves files just in time with the tools glob and grep, which bypasses the issues of stale indexing.27
  • Semantic searchIn Cursor's own tests it raised the accuracy of the agent's answers by 12.5% on average, between 6.5% and 23.5% depending on the model.28

Searching while the task runs has a cost: runtime exploration is slower than retrieving pre-computed data. Anthropic therefore describes a mix, in which an agent retrieves some data up front for speed and explores further on its own.27

Best use cases for each search

Which search fits depends on the questions that people or agents ask and on how often the data changes. The table collects what the sources say about each case.

SituationSearch that fitsReason
Queries with product codes, error codes, names or datesKeywordIt identifies exact matches.5 1
Questions worded differently from the documentsSemanticIt finds conceptually similar text without a keyword match.5
Question answering over documents, with both kinds of queryHybrid: keyword and semantic, then a rerankerIn Anthropic's tests, embeddings plus BM25 is better than embeddings on their own, and reranking is better than no reranking.1
Questions about how people, projects or things are connectedAdd a graph searchIt follows the relationships across several entities.14
Questions about a whole collectionA graph with community summariesGraphRAG's global search is made for questions that require an understanding of the dataset as a whole.19
An AI assistant with persistent memorySemantic, keyword, graph and temporal search togetherHindsight's documentation recommends Hindsight, which combines these four searches, for this case, and RAG for document question answering over a static corpus.14
A coding agent that works in a repositorySearch by the agent while it runs: grep and semantic searchCursor reports the best outcomes from the combination of the two.28 For less dynamic content, such as legal or finance work, Anthropic writes that a mix with some data retrieved up front might be better suited.27
A knowledge base under 200,000 tokens, about 500 pagesNoneThe entire knowledge base can go into the prompt.1

Anthropic's advice to teams that build agents on Claude is short: “do the simplest thing that works”.27

The bottom line

Keyword search matches words, semantic search matches meaning, and knowledge graph search follows connections. Keyword search and semantic search each miss what the other finds, and a graph adds what is only connected, so hybrid systems run several searches, merge the ranked lists and often rerank the result. An agent can also call its searches itself while it works.

Sources

  1. Introducing Contextual Retrieval Anthropic
  2. How full-text search works Elastic Docs
  3. Retrieval OpenAI docs
  4. Recall: How Hindsight Retrieves Memories Hindsight docs
  5. Hybrid search using vectors and full-text search in Azure AI Search Microsoft Learn
  6. Hybrid search Weaviate docs
  7. Building effective agents Anthropic
  8. Full-text search Elastic Docs
  9. Inverted Index Elasticsearch: The Definitive Guide
  10. What is semantic search? Elastic
  11. Vector embeddings OpenAI docs
  12. Enhancing hybrid retrieval with graph traversal using the GraphRAG Python package Neo4j Developer Blog
  13. What is a knowledge graph? IBM
  14. RAG vs Memory Hindsight docs
  15. Retain: How Hindsight Stores Memories Hindsight docs
  16. Welcome to GraphRAG GraphRAG docs
  17. microsoft/graphrag GitHub
  18. Local Search GraphRAG docs
  19. Query Engine GraphRAG docs
  20. Relevance scoring in hybrid search using Reciprocal Rank Fusion (RRF) Microsoft Learn
  21. Reciprocal rank fusion Elastic Docs
  22. Sessions Hermes Agent docs
  23. Persistent Memory Hermes Agent docs
  24. Memory search OpenClaw docs
  25. getzep/graphiti GitHub
  26. Agentic retrieval in Azure AI Search Microsoft Learn
  27. Effective context engineering for AI agents Anthropic
  28. Improving agent with semantic search Cursor

Written by Rahmatullah Musawi with the help of an AI assistant.