Skip to content
AnswerWell geo Documentation

Answerwell tools · 3 min read · Answerwell

Semantic Search & Embeddings

Semantic search: BM25, dual encoders, HNSW, ColBERT, hybrid ranking and relevance evaluation.

Semantic search matches an information need to a document even when the author and the user use different words. For exact SKUs, names and numbers, lexical matching remains useful. That is why the Answerwell tool combines learned representations with BM25 and tests the hybrid on its own queries.

BM25 takes into account term rarity, frequency saturation and document length [1]:

s(q,d)=∑t∈qIDF(t)ftd(k1+1)ftd+k1(1−b+b∣d∣/∣d∣‾).s(q,d)=\sum_{t\in q}IDF(t)\frac{f_{td}(k_1+1)}{f_{td}+k_1(1-b+b|d|/\overline{|d|})}.

ftdf_{td} is the term frequency, ∣d∣|d| the length, ∣d∣‾\overline{|d|} the average length, and k1,bk_1,b are parameters. The IDF variant is fixed, for example log⁡(1+(N−nt+0.5)/(nt+0.5))\log(1+(N-n_t+0.5)/(n_t+0.5)) for NN documents and ntn_t documents containing the term.

DPR trains separate encoders for the query and the passage [2]. For a relevant d+d^+ and negative examples NqN_q:

Lq=−log⁡exp⁡(s(q,d+)/τ)exp⁡(s(q,d+)/τ)+∑d−∈Nqexp⁡(s(q,d−)/τ).\mathcal L_q=-\log\frac{\exp(s(q,d^+)/\tau)}{\exp(s(q,d^+)/\tau)+\sum_{d^-\in N_q}\exp(s(q,d^-)/\tau)}.

τ>0\tau>0 is the temperature and ss the similarity of the representations. Hard negatives help training, but a useful document wrongly labelled as negative distorts the objective. The corpus is chunked so that passages keep headings, units and the context of tables.

HNSW uses a multi-layer graph for approximate nearest-neighbour search [3]. Connectivity and search-width parameters trade off memory, speed and recall. The ANN loss relative to exhaustive search over the same vectors is measured separately: index quality and embedding quality are different properties.

ColBERT models late interaction between tokens [4]:

s(q,d)=∑i=1∣q∣max⁡jqi⊤dj.s(q,d)=\sum_{i=1}^{|q|}\max_j q_i^\top d_j.

Each query token is matched to the closest document token. This is more expensive than a single vector, but it keeps a more detailed correspondence. A cross-encoder, by contrast, processes the pair jointly and is usually applied to a limited set of candidates.

To combine rankings, Reciprocal Rank Fusion applies [5]:

RRF(d)=∑r:d∈r1k+rankr(d).RRF(d)=\sum_{r:d\in r}\frac1{k+rank_r(d)}.

k>0k>0 is a smoothing constant; a document missing from a ranking gets no term. Fusing positions avoids having to compare incompatible BM25 and cosine values directly.

Stage Metric Question
Candidates Recall@100 Is the needed evidence there
Final list NDCG@10, MRR How useful the order is
Infrastructure p95, memory, index size Can search run within the budget
Abstention Quality of “not found” answers Are irrelevant results forced on the user

BEIR shows the importance of testing across different domains [6]. For our own set, say 500 queries, relevance is annotated on several grades of usefulness; similar rephrasings are not split randomly between training and test. Queries with an SKU, a negation, a date and no available answer are tested separately.

High similarity does not prove factual support: “supports export” and “does not support export” can have close vectors. Evaluating the generator without checking the first stage hides a retrieval failure. A new embedding version requires consistent reindexing, not mixing vector spaces.

Reproducibility and how Answerwell applies it

Section titled “Reproducibility and how Answerwell applies it”

In the project’s research loop, Answerwell’s own robots and ML/DL models are applied to brand data. The grounds for each architecture, corpus versions, training parameters and compute are recorded according to the general methodology. Public, acquired and internal data each keep their own provenance; describing a method does not mean a proven match with the closed weights of an external platform.

The test set is separated from training by time and by object. Raw observations, failed attempts and unknown values are kept. Models are compared on the same data and budget, with the sample size and errors by segment reported. Illustrative calculations in this article are not a claim about an experiment Answerwell has carried out.

  1. Stephen Robertson, Hugo Zaragoza. The Probabilistic Relevance Framework: BM25 and Beyond, 2009. Monograph.
  2. Vladimir Karpukhin et al. Dense Passage Retrieval, 2020. Paper.
  3. Yu. Malkov, D. Yashunin. Hierarchical Navigable Small World Graphs, 2016/2020. Paper.
  4. Omar Khattab, Matei Zaharia. ColBERT, 2020. Paper.
  5. Gordon Cormack, Charles Clarke, Stefan Buettcher. Reciprocal Rank Fusion, 2009. SIGIR.
  6. Nandan Thakur et al. BEIR, 2021. Benchmark.