Back to directory

LinearAdapterTrainer

A PyTorch library that trains a linear adapter with triplet loss to align retrieval query embeddings with real user queries, improving RAG search without retraining or re-indexing the embedding model.

LinearAdapterTrainer

LinearAdapterTrainer fine-tunes retrieval for retrieval-augmented generation without retraining the underlying embedding model. It learns a small linear transform, initialized at identity, that is applied only to query embeddings at search time to move them closer to relevant chunks and further from irrelevant ones, leaving the existing vector index untouched.

It is built around two composable modules: a dataset generator that produces query, positive and negative triplets from a knowledge base, with configurable negative mining strategies and a leakage-free train and validation split, and a linear adapter trainer that fits a PyTorch linear layer on those triplets using a triplet loss, then reports retrieval gains with precision@k, recall@k, MRR and nDCG. Compared with fine-tuning the full embedding model or adding a re-ranking model, the linear adapter is CPU-friendly, requires no corpus re-indexing, and is reversible. A dependency-free hashing embedder and template query generator let the whole pipeline run offline for testing.

It is open source from Santander AI Lab, installed with pip or uv, and licensed under Apache-2.0.

More in RAG

See all 540
  • ai·rete·rag

    ai-rete-rag.com

    A platform that pairs a Rete rule engine with retrieval-augmented generation, so deterministic rules decide an outcome and grounded retrieval explains the decision in plain language.

  • Xtriever

    github.com

    A hybrid retrieval engine for retrieval-augmented generation, written in Rust to run on-device on a phone or a laptop, combining lexical BM25 search, dense embedding search, reciprocal-rank fusion and cross-encoder re-ranking with no server.

  • FileFlux

    github.com

    A .NET library that turns PDF, DOCX, HWP and other documents into optimized chunks for RAG systems, through a five-stage pipeline built on high-performance Rust FFI readers.