How receipts are searched, and where search is deliberately not used.
Use
Pipeline
Retrieval pipelineTwo searches, merged, then reordered by a slower model.your receiptspiecesper ticketand per linekeyword searchBM25meaning searchvectorsmerge thetwo rankingsrerank thebest 10answer withthe receipt
Pieces
One per ticket and one per line, so a single product can be found
Indexed text
The printed abbreviation with the recognised name: Lait demi-écrémé (LT DEMI-ECR 1L)
Keywords
SQLite FTS5, BM25
Meaning
MiniLM, paraphrase-multilingual-MiniLM-L12-v2
Merge
Reciprocal rank fusion, keywords count 4 times more
Reranker
bge-reranker-v2-m3-int8 (cross-encoder)
Privacy
Models run on the machine; one user can never search another’s receipts
Example
Any of the 49 test questions, in French like the made-up documents. Shop names are replaced by generic ones.
The same question ranked by each search stageThe right document, highlighted, and where each stage ranks it.« le chargeur avec 2 ans de garantie »KeywordsMeaningMergedRerankedReranked1234chargeur USB-C 65 WMAGASIN I · warranty 3 yrchargeur USB-C 65 WMAGASIN B · warranty 2 yrlave-linge 8 kgMAGASIN B · warranty 2 yrbouilloire inoxMAGASIN E · warranty 2 yrKeywordsMeaningMergedReranked1234rank at each stage
The same question ranked by each search stageThe right document, highlighted, and where each stage ranks it.« le chargeur avec 2 ans de garantie »KeywordsMeaningMergedRerankedReranked1234chargeur USB-C 65 WMAGASIN I · warranty 3 yrchargeur USB-C 65 WMAGASIN B · warranty 2 yrlave-linge 8 kgMAGASIN B · warranty 2 yrbouilloire inoxMAGASIN E · warranty 2 yr1234rank at each stage
LangChain retriever
agent/src/costmap_agent/rag/search.py
class CostmapRetriever(BaseRetriever):
"""The same search as a LangChain retriever, so any LangChain or LangGraph chain can use it."""
model_config = ConfigDict(arbitrary_types_allowed=True)
search: HybridSearch
user_id: str
k: int = 5
mode: str = "hybrid"
rerank: bool = True
def _get_relevant_documents(self, query: str, **kwargs: Any) -> list[Document]:
hits = self.search.search(self.user_id, query, self.k, mode=self.mode, rerank=self.rerank)
return [Document(page_content=h.text, metadata={"doc_id": h.doc_id, "kind": h.kind, "score": h.score, **h.meta}) for h in hits]
LangChain piece
Choice
Why
BaseRetriever
Used
A standard shape for the search
Text splitters
Not used
A receipt already splits into lines
Vector stores
Not used
SQLite and one table of vectors are enough, and the per-user filter stays visible
Results
49 synthetic questions, 290 synthetic documents
Right document in first place (hit@1)
Keywords only0.80
Vectors only0.37
Both, equal weight0.63
Both, keywords x40.63
Keywords x4, then rerank0.92
Setup
hit@1
recall@5
MRR
recall@5 without names
Keywords only
0.80
0.89
0.86
0.80
Vectors only
0.37
0.41
0.42
0.38
Both, equal weight
0.63
0.74
0.72
0.71
Both, keywords x4
0.63
0.83
0.74
0.80
Keywords x4, then rerank
0.92
0.90
0.92
not run
recall@5 when asking for
Keywords
Vectors
Full
a product at a store
1.00
0.30
1.00
a product in a city
1.00
0.00
1.00
a product in a month
1.00
0.14
0.98
an exact amount
1.00
0.10
1.00
warranty, in other words
0.75
0.53
0.75
returns, in other words
0.73
0.80
1.00
returns of one item
1.00
0.75
0.60
Limits
The settings were chosen on the same questions, so real results will be lower.
Warranty texts exist only in the made-up set; a real account holds receipts.
New receipts are searchable after the assistant restarts.