Lexical Search
Lexical search retrieves information by comparing the actual words in a search query with the words contained in documents, records, or other searchable content.
It is the foundation of traditional keyword and full-text search systems and remains highly useful in modern AI applications because exact language often matters.
What Is Lexical Search?
Lexical search focuses primarily on text matching.
When a user enters a query, the search system analyzes the words and finds documents containing the same or related terms.
A basic example is:
Query: cancellation policy
A lexical search system will prioritize content containing words such as "cancellation" and "policy."
More advanced lexical search systems can also account for:
- Word frequency
- Document frequency
- Phrase matches
- Word variations
- Field importance
- Proximity
- Term weighting
- Boolean operators
Lexical search is therefore more sophisticated than simply checking whether two strings are identical.
How Lexical Search Works
Many lexical search systems use an inverted index.
Instead of scanning every document each time a query is submitted, the system builds an index showing where individual terms appear.
For example:
appointment
- Document 2
- Document 6
- Document 11
cancellation
- Document 4
- Document 6
- Document 9
When a query is submitted, the system can quickly identify documents containing the relevant terms.
Lexical Search Ranking
Finding a matching word is only the first step.
The system must also rank results.
Common ranking signals include:
Term Frequency
How often does the query term appear in the document?
Inverse Document Frequency
How rare or distinctive is the term across the full collection?
A rare term can carry more ranking value than a common word.
Field Weighting
A match in a title may be considered more important than a match in a body paragraph.
Phrase Matching
A document containing the exact phrase "airport shuttle" may rank more highly for that query than a document containing the words separately.
BM25
BM25 is a widely used ranking algorithm for lexical search. It balances term frequency with document length and term rarity to estimate relevance.
Lexical Search vs. Keyword Search
The terms are often used interchangeably.
Keyword search usually describes the user experience of searching with words or phrases.
Lexical search describes the underlying retrieval approach based on textual matching.
A modern lexical search system can handle much more than exact keyword equality while still fundamentally relying on the words present in the query and source.
Where Lexical Search Performs Well
Lexical search is particularly strong when exact wording carries meaning.
Examples include:
Product Names
A query for a specific model or product name should usually favor exact matches.
Error Codes
ERR-1024 should match the exact identifier.
Policy Numbers
Exact reference values are not primarily semantic concepts.
Acronyms
Terms such as "SLA" or "API" may need exact matching.
Proper Names
Business names, locations, people, and branded terms benefit from lexical precision.
Technical Terminology
Specialized vocabulary can be difficult for a semantic model to interpret correctly if it is rare or highly domain-specific.
Limitations of Lexical Search
Lexical search can struggle when the query and document express the same meaning using different words.
For example:
Query: "Can I change my booking?"
Document: "Reservations may be modified up to 24 hours before arrival."
The words "change" and "booking" do not appear in the document.
A lexical system may still find the result through stemming, synonyms, or query expansion, but the connection is less direct than in semantic retrieval.
Other challenges include:
- Synonyms
- Paraphrasing
- Natural-language questions
- Vocabulary mismatch
- Conceptual relationships
Lexical Search vs. Semantic Search
Semantic search retrieves information based on meaning rather than primarily on word overlap.
Consider:
Query: "Where do I leave my car?"
Document: "Guest parking is available behind the building."
Lexical search sees limited overlap.
Semantic search can recognize that "leave my car" relates to "parking."
Neither approach is always superior.
Lexical search is often stronger for exact terms, while semantic search is often stronger for paraphrases and conceptual similarity.
Lexical Search vs. Hybrid Search
Hybrid search combines lexical search with semantic search.
The lexical component preserves exact-term precision.
The semantic component adds meaning-based retrieval.
For many business search systems, this combination is useful because datasets contain both precise terminology and natural-language explanations.
Lexical Search in AI Systems
Lexical search remains important even when an AI system uses large language models.
An AI agent may need to retrieve:
- Exact product names
- Account types
- Service codes
- Policy references
- Technical terms
- Location names
- Identifiers
A semantic-only retrieval system can sometimes miss or under-rank these exact matches.
Lexical retrieval provides a complementary signal.
Lexical Search in AskHandle
AskHandle uses lexical retrieval as one component of hybrid search in Document Search and Data Search.
The lexical signal helps the system identify precise textual matches in business information.
It works alongside semantic retrieval, which helps match information based on meaning when the user's wording differs from the source.
The combination is designed to improve retrieval precision across different types of queries rather than relying entirely on one search method.
Improving Lexical Search
Lexical search quality can be improved through techniques such as:
- Better tokenization
- Stemming
- Lemmatization
- Synonym dictionaries
- Phrase matching
- Field weighting
- Stop-word handling
- Domain-specific analyzers
- Query expansion
- Relevance tuning
The correct configuration depends on the language, dataset, and types of queries users make.
When to Use Lexical Search
Lexical search is particularly useful when:
- Exact terminology matters
- Users search by names or codes
- The dataset contains specialized vocabulary
- Search results must strongly reward literal matches
- The domain includes many acronyms
- Queries are short and specific
It is also useful as part of hybrid retrieval when natural-language queries are common.