jasperan commited on
Commit
4cc338a
·
verified ·
1 Parent(s): f9771a9

Add fine-tune model card

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: gemma
3
+ base_model: google/embeddinggemma-300m
4
+ pipeline_tag: sentence-similarity
5
+ library_name: sentence-transformers
6
+ tags:
7
+ - sentence-transformers
8
+ - sentence-similarity
9
+ - feature-extraction
10
+ - embeddinggemma
11
+ - code-search
12
+ - matryoshka
13
+ - fine-tuned
14
+ ---
15
+
16
+ # embeddinggemma-code-search
17
+
18
+ [`google/embeddinggemma-300m`](https://huggingface.co/google/embeddinggemma-300m) fine-tuned for **code search over a real agent codebase**, using graded retrieval traces from coding-agent sessions.
19
+
20
+ This is the "custom retrieval model from agent sessions" arm of a continual-learning course: instead of hand-labeled pairs, training signal comes from **graded traces** — for each natural-language query about the codebase, candidate code chunks carry relevance grades (0–3) derived from what the agent actually needed. The encoder is trained so that its softmax similarity distribution over the candidates matches the grade distribution (a listwise KL-divergence loss, in the spirit of Cursor's "align the embedding space to what sessions proved relevant" approach).
21
+
22
+ ## Training setup
23
+
24
+ - **Base model**: `google/embeddinggemma-300m` (sentence-transformers, Matryoshka-truncatable embeddings)
25
+ - **Corpus**: 240 code chunks extracted from a real Python agent-harness source tree (signatures, docstrings, AST body summaries, import/call/co-edit context)
26
+ - **Traces**: 800 graded retrieval traces (573 train / 227 held-out), 40 candidates per trace, indirect-intent natural-language queries
27
+ - **Loss**: listwise KL divergence between softmax(similarities) and the normalized grade distribution
28
+ - **Schedule**: deliberately gentle — 1 epoch, lr 5e-6, full-parameter. (Aggressive schedules overwrite the pretrained space and hurt held-out recall.)
29
+
30
+ ## Results (held-out queries, recall@5)
31
+
32
+ | Embedding dim (MRL) | Base | Fine-tuned |
33
+ |---|---|---|
34
+ | 768 | 0.753 | **0.793** |
35
+ | 256 | 0.643 | **0.753** |
36
+ | 128 | 0.568 | **0.722** |
37
+
38
+ The biggest lift is at truncated Matryoshka dimensions — the fine-tuned 128-d embeddings match the base model's 256-d quality, which is what you want for cheap, low-latency code search indexes.
39
+
40
+ ## Usage
41
+
42
+ ```python
43
+ from sentence_transformers import SentenceTransformer
44
+
45
+ model = SentenceTransformer("jasperan/embeddinggemma-code-search")
46
+
47
+ query_emb = model.encode(["where do we retry failed tool calls?"])
48
+ doc_embs = model.encode(code_chunks)
49
+
50
+ # Matryoshka: truncate + re-normalize for a smaller index
51
+ import numpy as np
52
+ q128 = query_emb[:, :128]
53
+ q128 = q128 / np.linalg.norm(q128, axis=1, keepdims=True)
54
+ ```
55
+
56
+ ## License
57
+
58
+ EmbeddingGemma is provided under and subject to the [Gemma Terms of Use](https://ai.google.dev/gemma/terms). This fine-tune inherits those terms.