Combining Text and Semantic Indexes for Search
Abstract
This paper presents a novel approach to combining full-text and semantic indexes for hybrid search by enriching the semantic hierarchical navigable small world (HNSW) graph. The goal of the research is to formulate a method of building index data structures for hybrid search over text and text embeddings, which would improve search recall compared to conventional state-of-the-art methods. The proposed graph has token-based nodes, as well as semantic nodes. The token-based nodes are generated by tokenizing the indexed text data. Each node represents a single token. The tokens are linked to the documents, which contain those tokens, represented by semantic nodes, as per the classical HNSW approach. The text nodes are also linked to other text nodes if the tokens are close to one-another based on edit distance. This data structure allows text-only, semantic-only, and hybrid queries, which gives the end user the opportunity to tune the search algorithm to their needs. The resulting graph contains three types of edges, the semantic-to-semantic (S2S) edges, the token-to-token (T2T) edges, weighted by the edit distance, and the token-to-semantic (T2S) edges, weighted by a lexical score. The hybrid search algorithm works in parallel with multiple entry points to the graph at once. The semantic entry point, just like in the classic approximate nearest neighbours search, attempts to find the closest point in the vector space of documents to the point which corresponds to the query embedding. Text entry points each start with a single token from the query text and locate it in the graph. Unlike the semantic nodes, token nodes are not grouped into levels, thus allowing the search operation to hop to the closest documents at once. The hits generated by each of the search process parts are all ranked together based on both the semantic closeness to the query embedding and the text metrics. As a result, the hybrid search concludes with fewer operations compared to a classical search and with a higher recall. As the result of the research, a novel text indexing method for text search was developed. The goals of the research are successfully met.