Repository navigation
Expand file tree
/
Copy pathllms.txt
More file actions
105 lines (73 loc) · 3.34 KB
/
Copy pathllms.txt
File metadata and controls
105 lines (73 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# isotrieve
> Migrate a vector database to a new embedding model without re-embedding the corpus. Fits a linear map from ~2K calibration texts; 87-91% retrieval retention measured on BEIR.
## Install
pip install isotrieve
Python >= 3.10. Core deps: numpy, scikit-learn, typer, rich.
Optional extras: [chroma], [langchain], [sentence-transformers], [qdrant], [openai], [voyage], [cohere], [gemini], [mlp], [all]. Planned: pgvector.
## API
### RidgeMapping (primary)
from isotrieve import RidgeMapping
m = RidgeMapping(alpha="auto", seed=0)
m.fit(X_cal, Y_cal) # X_cal: (K, d_src), Y_cal: (K, d_tgt)
Z = m.transform(source_vectors) # (N, d_tgt)
m.save("mapping.isotrieve")
### QueryAdapter (serve mode)
from isotrieve.serve import QueryAdapter
qa = QueryAdapter.load("mapping.isotrieve")
legacy_vec = qa.map_query(new_model_vector)
calibrated_scores = qa.recalibrate_scores(raw_scores)
### ChromaDB Adapter (v0.2)
from isotrieve.adapters.chroma import IsotrieveChromaFunction, migrate_collection
# Serve mode
ef = IsotrieveChromaFunction(mapping, new_model_embedder=my_embed_fn)
col = client.get_collection("docs", embedding_function=ef)
# Offline migration
report = migrate_collection(client, "docs", mapping, new_collection="docs_v2")
### LangChain Adapter (v0.2)
from isotrieve.adapters.langchain import IsotrieveEmbeddings
ae = IsotrieveEmbeddings(mapping, base_embeddings)
results = db.similarity_search("query", embedding=ae)
### Confidence Scoring (v0.2)
from isotrieve.reranking import ConfidenceScorer
scorer = ConfidenceScorer(margin_high=0.955, margin_low=0.637)
result = scorer.score(query_vector, top_scores)
# result.flag: "high" / "medium" / "low"
### QualityGate
from isotrieve.quality.gate import QualityGate
gate = QualityGate()
report = gate.evaluate(m, X_holdout, Y_holdout)
# report.verdict: PASS / WARN / FAIL
# report.predicted_retention: float
### Other adapters
from isotrieve.mapping.linear import LowRankAffineMapping, OrthogonalProcrustesMapping
# OrthogonalProcrustesMapping: d_src must equal d_tgt
# LowRankAffineMapping: compressed matrix, ~1% worse than Ridge
## Benchmarks
Adapter comparison (SciFact, MiniLM->bge-large, K=4000, 3 seeds):
- Ridge: 0.866 +/- 0.008 retention
- LowRank: 0.857 +/- 0.009 retention
- MLP: 0.719 +/- 0.008 retention (no tuning)
K-sweep (all adapters averaged):
- K=500: 0.667 retention (WARN)
- K=1000: 0.732 retention (WARN)
- K=2000: 0.788 retention (PASS)
- K=4000: 0.814 retention (PASS)
Same-dim pair (bge-large->e5-large, 1024->1024):
- Floor: 0.0, Isotrieve: 0.656, Ceiling: 0.722, Retention: 0.908
Score recalibration:
- bge->e5: MAE=0.095, margin compression=0.83x
- MiniLM->bge: MAE=0.364, margin compression=0.85x, essential for rectangular pairs
Confidence flags:
- bge->e5: high-conf R@10=0.955, low-conf R@10=0.637
- MiniLM->bge: high-conf R@10=0.875, low-conf R@10=0.651
## Limits
- Requires paired calibration data (same texts embedded with both models)
- Quality depends on model pair and domain match
- K < 2000: significant quality degradation
- Gate model: trained on local model pairs only, not validated on API pairs
- Cross-encoder reranking: NOT shipped (MS MARCO domain-mismatched for sci-text)
- TSVD shrinkage: available but not recommended (quality degrades)
## Links
- Repository: https://github.com/krish1925/Isotrieve
- Issues: https://github.com/krish1925/Isotrieve/issues
- License: Apache-2.0