FR Demo

RAG

How receipts are searched, and where search is deliberately not used.

Use

flow Who answersOnly free-text questions use retrieval. Totals use SQL, sums use code, names use a dictionary then a model.“the charger with a warranty”search (RAG)“how much on food?”SQL: needs every row“do these lines add up?”code: exact sums“what is LT DEMI-ECR 1L?”dictionary, then modelflow Who answers
flow Who answersOnly free-text questions use retrieval.“the charger with a warranty”search (RAG)“how much on food?”SQL: needs every row“do these lines add up?”code: exact sums“what is LT DEMI-ECR 1L?”dictionary, then modelflow Who answers

Pipeline

Retrieval pipelineTwo searches, merged, then reordered by a slower model.your receiptspiecesper ticketand per linekeyword searchBM25meaning searchvectorsmerge thetwo rankingsrerank thebest 10answer withthe receipt
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 pieceChoiceWhy
BaseRetrieverUsedA standard shape for the search
Text splittersNot usedA receipt already splits into lines
Vector storesNot usedSQLite 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 only 0.80
Vectors only 0.37
Both, equal weight 0.63
Both, keywords x4 0.63
Keywords x4, then rerank 0.92
Setuphit@1recall@5MRRrecall@5 without names
Keywords only0.800.890.86 0.80
Vectors only0.370.410.42 0.38
Both, equal weight0.630.740.72 0.71
Both, keywords x40.630.830.74 0.80
Keywords x4, then rerank0.920.900.92 not run
recall@5 when asking forKeywordsVectorsFull
a product at a store1.000.301.00
a product in a city1.000.001.00
a product in a month1.000.140.98
an exact amount1.000.101.00
warranty, in other words0.750.530.75
returns, in other words0.730.801.00
returns of one item1.000.750.60

Limits

  1. The settings were chosen on the same questions, so real results will be lower.
  2. Warranty texts exist only in the made-up set; a real account holds receipts.
  3. New receipts are searchable after the assistant restarts.