What is semantic search in AI-assisted coding?
By Flavio
Semantic search finds related meaning rather than exact words. Learn where embeddings help, how coding tools search, and when an exact match is better.
Semantic search retrieves material by meaning, so a result can be relevant even when it uses different words from the query.
For the practical work of splitting documents and fitting retrieved text into a prompt, read RAG chunking explained.
How semantic search works
One common approach turns documents and the query into embeddings. Search ranks stored vectors by their similarity to the query vector. OpenAI’s embeddings guide describes vectors as measurements of text relatedness.
Retrieval finds candidate passages. In a RAG workflow, those passages then become context for a generated answer.
In coding tools
Cursor’s current search documentation describes exact-match Instant Grep and says it does not store codebase embeddings for search. Asking a question in natural language does not tell you which search mechanism the agent used.
Claude Code documents regex and file-pattern search. An agent can translate your question into several literal searches, then reason over the files it reads.
Codex Cloud’s overview describes working on repository tasks, without specifying a semantic code-search index. OpenAI’s separate embeddings API can support retrieval in an application you build.
Grok Build’s overview documents repository questions and file references. A semantic code-search setting is not documented there.
Details checked against each vendor’s documentation in November 2026.
A concrete example
This site has a function named publishedGlossaryEntries. A useful request is:
Find the function that keeps future-dated glossary entries off the site.
Show its file and explain the publication check. Don't edit anything.
The request describes behavior without naming the symbol. A semantic index could help find related code. An agent could also search for glossary, then follow publication helpers. Inspect its searches and the source it cites before accepting the explanation.
When to use semantic search
Use it when you know what a passage means but don’t know its vocabulary. It also helps retrieve documentation that phrases the same idea differently.
Use exact search for a known function name, config key, or error string. The spelling is useful evidence.
Pitfalls
Related text can still be the wrong text. Read the retrieved passage and its surrounding code. A similar function elsewhere in the repository may follow different rules.
When building your own retrieval system, use compatible embeddings for documents and queries. Test with real questions, including questions your documents cannot answer.
Related on flaviocopes.com
- RAG chunking explained covers retrieval chunks and context costs.
- Use AI to understand code shows how to follow behavior across files.
- Architecture Dissector helps organize your understanding after exploring a codebase.
Related glossary entries
- Embeddings: An embedding is a list of numbers that puts similar text close together. How OpenAI and xAI build them, and why Cursor search says it does not store them.
- RAG: RAG fetches relevant passages and puts them in the prompt so the model answers from those passages. How that differs from search in the coding agents.
- Codebase indexing: Codebase indexing prepares source files for search. Learn how Cursor's local index differs from embeddings, model training, and the agent's context window.
Want me to talk about your product? You can sponsor this site.