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 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.