Principle:Neuml Txtai Semantic Query
| Knowledge Sources | |
|---|---|
| Domains | NLP, Search |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
Semantic querying retrieves documents from a vector index based on meaning similarity rather than exact keyword matching, optionally combining dense and sparse signals for improved recall and precision.
Description
Traditional keyword search requires the query and the document to share the same surface-level terms. Semantic search overcomes this limitation by operating in a continuous vector space where the distance between points reflects conceptual similarity. A query is first transformed into an embedding vector using the same model that was used to index the documents, and then the nearest neighbor index is searched for the most similar document vectors.
Modern semantic search systems often employ hybrid retrieval, which combines dense vector similarity with sparse keyword scoring. Dense search excels at understanding paraphrases and synonyms but can miss exact term matches that carry high relevance. Sparse search (e.g., BM25) excels at exact matching but fails on synonyms and rephrasing. By combining both signals through a weighted fusion strategy, hybrid search achieves higher accuracy than either approach alone.
The search system also supports query routing: depending on the configuration, a query may be processed as a pure vector search, a SQL query against the document database, or a graph traversal. This routing is transparent to the user, who simply provides a natural language query or a structured SQL expression.
Usage
Use semantic querying whenever you need to find documents that are conceptually related to a query, even if the query uses different words than the stored documents. Hybrid search is recommended for production use cases where both semantic understanding and keyword precision are important. Graph search is useful for relationship-based queries such as finding connected entities.
Theoretical Basis
Cosine Similarity
The fundamental similarity metric for dense vector search is cosine similarity, which measures the angle between two vectors regardless of their magnitude:
similarity(q, d) = (q . d) / (||q|| * ||d||)
Values range from -1 (opposite) to 1 (identical). In practice, embeddings from sentence transformers are L2-normalized, so cosine similarity reduces to the dot product.
Hybrid Search Fusion
Hybrid search combines dense and sparse scores. Two common fusion strategies are:
Convex Combination (when sparse scores are normalized):
score(d) = w_dense * score_dense(d) + w_sparse * score_sparse(d)
where w_dense + w_sparse = 1.0
Reciprocal Rank Fusion (RRF) (when sparse scores are not normalized):
score(d) = sum over rankings r: w_r * 1/(rank_r(d) + 1)
RRF is more robust to score distribution differences between the dense and sparse indexes.
Query Routing
The search system routes queries through different paths based on configuration and query structure:
Query -> Is it a graph query?
Yes -> Graph search (traversal-based)
No -> Is a database configured?
Yes -> Parse as SQL, run index scan + database join
No -> Run pure index search (dense, sparse, or hybrid)
This routing enables a single search interface to support natural language queries, SQL expressions, and graph traversals.