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.
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
The quickquick brown foxfox jumped over the lazy dog
matchQuickquick brown foxesfox leap over lazy dogs in summer
matchText 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
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
The first lunar landing occurred in July of 1969.
The first man on the moon was Neil Armstrong.
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 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
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
It stores the embeddings and allows searching them by semantic similarity.1
Your text string goes here→-0.006929283495992422-0.005336422007530928-4.547132266452536e-5-0.024047505110502243… 1,536 numbers in all
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
RAG stops here. It retrieves facts about Alice only (no semantic similarity to “issues”).14
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 search | Semantic search | Knowledge 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 by | Words: precise word or phrase matches1 | Meaning: the stored vectors nearest to the query10 | Connections: the links between entities4 |
| Built before searching | An inverted index of tokens2 | One embedding per chunk, in a vector database1 | A graph of the entities and relationships found in the text16 |
| Finds well | Unique identifiers and technical terms;1 product codes, jargon, dates and names5 | Paraphrases and synonyms: “meeting” matches “conference”4 | Indirect relationships across several entities;4 questions about a dataset as a whole19 |
| Weak point | A relevant text that shares no words with the query3 | Exact matches, such as one error code1 | Building 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
- BM25 searchFinds the top chunks based on exact matches.1
- Embedding searchFinds the top chunks based on semantic similarity.1
- Rank fusionCombines the two result lists and removes duplicates.1
- 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
- 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
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
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.
Retrieval in AI agents
Six products for agents and for RAG show the range, from one keyword search to four searches in parallel:
| Product | Searches by | How |
|---|---|---|
| Hermes Agent | Keyword | Its 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 |
| OpenClaw | Semantic and keyword | Memory search runs a vector search and a BM25 keyword search in parallel and merges the results.24 |
| Hindsight | Semantic, keyword, graph and time | Four searches in parallel, fused by rank and reranked.4 |
| Graphiti | Semantic, keyword and graph | Hybrid retrieval that combines semantic embeddings, keyword search (BM25) and graph traversal.25 |
| Microsoft GraphRAG | Graph | Local search for questions about specific entities, global search for questions about the dataset as a whole.19 |
| Azure AI Search | Keyword, vector or hybrid | In agentic retrieval, an LLM can break a complex query into smaller subqueries, which run in parallel and are reranked.26 |
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
- 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.
| Situation | Search that fits | Reason |
|---|---|---|
| Queries with product codes, error codes, names or dates | Keyword | It identifies exact matches.5 1 |
| Questions worded differently from the documents | Semantic | It finds conceptually similar text without a keyword match.5 |
| Question answering over documents, with both kinds of query | Hybrid: keyword and semantic, then a reranker | In 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 connected | Add a graph search | It follows the relationships across several entities.14 |
| Questions about a whole collection | A graph with community summaries | GraphRAG's global search is made for questions that require an understanding of the dataset as a whole.19 |
| An AI assistant with persistent memory | Semantic, keyword, graph and temporal search together | Hindsight'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 repository | Search by the agent while it runs: grep and semantic search | Cursor 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 pages | None | The 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
- Introducing Contextual Retrieval Anthropic
- How full-text search works Elastic Docs
- Retrieval OpenAI docs
- Recall: How Hindsight Retrieves Memories Hindsight docs
- Hybrid search using vectors and full-text search in Azure AI Search Microsoft Learn
- Hybrid search Weaviate docs
- Building effective agents Anthropic
- Full-text search Elastic Docs
- Inverted Index Elasticsearch: The Definitive Guide
- What is semantic search? Elastic
- Vector embeddings OpenAI docs
- Enhancing hybrid retrieval with graph traversal using the GraphRAG Python package Neo4j Developer Blog
- What is a knowledge graph? IBM
- RAG vs Memory Hindsight docs
- Retain: How Hindsight Stores Memories Hindsight docs
- Welcome to GraphRAG GraphRAG docs
- microsoft/graphrag GitHub
- Local Search GraphRAG docs
- Query Engine GraphRAG docs
- Relevance scoring in hybrid search using Reciprocal Rank Fusion (RRF) Microsoft Learn
- Reciprocal rank fusion Elastic Docs
- Sessions Hermes Agent docs
- Persistent Memory Hermes Agent docs
- Memory search OpenClaw docs
- getzep/graphiti GitHub
- Agentic retrieval in Azure AI Search Microsoft Learn
- Effective context engineering for AI agents Anthropic
- Improving agent with semantic search Cursor
Written by Rahmatullah Musawi with the help of an AI assistant.