Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/web-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ jobs:
- run: npx --yes tsx --test src/lib/rag/*.test.ts
- run: npx --yes tsx scripts/conversation-eval.ts --check
- run: npx --yes tsx scripts/conversation-eval.ts --distractors --check
- run: npx --yes tsx scripts/learning-eval.ts --check
- run: npx --yes tsx scripts/learning-eval.ts --distractors --check
- name: CoSQA code search (search bar vs BM25)
run: |
git clone --depth 1 --filter=blob:none --sparse https://github.com/microsoft/CodeXGLUE /tmp/cxg
git -C /tmp/cxg sparse-checkout set Text-Code/NL-code-search-WebQuery/CoSQA
COSQA_DIR=/tmp/cxg/Text-Code/NL-code-search-WebQuery/CoSQA npx --yes tsx scripts/cosqa-bench.ts --check
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ One pinned README ([sindresorhus/p-queue](https://github.com/sindresorhus/p-queu

The default ties BM25 on the clean corpus and beats it by 20 points once noise documents are mixed in. The coverage packer wins one extra question on the clean corpus, but the gain's bootstrap interval is [−10, +20] points, and it loses 10 points under distractors. So it stays opt-in. Every run, including the losing ones, is in [`eval/repo-support/runs/`](eval/repo-support/runs/), and the [evaluation write-up](eval/repo-support/README.md) covers method, history and limits.

## It gets better the more it's used

Three loops improve IntelliRAG as people use it. Each is measured on held-out data, and each can only add evidence: none of them can make an unsupported question look answered.

| Loop | What it learns | Measured |
|---|---|---|
| **Conversation** ([`session-intent.ts`](web/src/lib/rag/session-intent.ts)) | A follow-up is searched with the earlier questions on its topic | Follow-ups with complete evidence: 63.6% → **86.4%**, refusals 1/3 → 2/3 ([eval](eval/conversations/README.md)) |
| **Experience** ([`experience.ts`](web/src/lib/rag/experience.ts)) | A rated answer, or a passage picked as the one that answers a question, is filed against that passage. Later questions worded like it find it. | Originals asked again: 71.4% → **81.0%**; new wordings +2.4 to +4.8 points; 20% wrong ratings cost nothing ([eval](eval/learning/README.md)) |
| **Self-improvement memory** ([`sim-optimize.ts`](web/scripts/sim-optimize.ts), after [arXiv 2611.18856](https://arxiv.org/abs/2611.18856)) | The retrieval policy is edited round by round. Each attempt is recorded with its root cause, rationale, predicted fixes and observed result. | Held-out wording 52.9% → **58.8%**. Its accepted packing edit also lifted the follow-up eval it never saw by 9 points ([write-up, including the null result](eval/sim/README.md)) |

Experience is the "file good answers back" step of [Karpathy's LLM-wiki pattern](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f), done per passage: the source is never edited, and links go stale when the passage they learned about changes. Agents get the same memory through the MCP server's `feedback` tool. It is kept per repository, so a repo keeps learning across sessions.

## Search like GitHub code search

Press ⌘K (Ctrl+K) to search every indexed source instantly. It splits identifiers
(`parseJSONResponse` matches "parse json response"), weights function names and
docstrings, and takes operators: `path:src/queue`, `lang:ts`, `sym:resume`,
`kind:prose`, `"exact words"`, `-word`. Results show the matching lines
highlighted, with "did you mean" for typos and completions from your sources.
The same engine answers `GET /api/search?q=…&corpus=…`.

On CoSQA (313 real web queries, 6,267 Python functions) it scores 46.4 nDCG@10
against 42.9 for plain BM25, with no model. Details and an honest comparison with
dense retrievers: [eval/code-search](eval/code-search/README.md).

## Research behind the design

| Paper | What we took | Status here |
Expand Down
47 changes: 47 additions & 0 deletions eval/code-search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Code search on CoSQA

The search bar (⌘K in the app, `GET /api/search`) ranks passages with
`web/src/lib/rag/code-search.ts`. This folder measures it on **CoSQA**
(Huang et al., ACL 2021): real Bing queries such as "python remove all empty
items in list" against all 6,267 unique Python functions in the dataset. The
313 dev queries labelled as answered by a function are scored by where that
function ranks.

Settings were tuned on 500 training queries only (`--tune`). The learned
associations come from CoSQA training pairs only; dev queries are never seen.

| Arm | nDCG@10 | MRR@10 | R@1 | R@5 | R@10 |
|---|---|---|---|---|---|
| BM25 with IntelliRAG's prose tokenizer | 42.86 | 37.08 | 27.16 | 52.08 | 61.34 |
| + identifier-aware tokens (`parseJSON` → parse, json) | 45.49 | 39.24 | 27.80 | 55.27 | 65.50 |
| + name and docstring fields (BM25F) | 45.82 | 39.83 | 27.80 | 53.99 | 64.86 |
| tried and left off: developer synonym lexicon | 44.18 | 38.33 | 26.20 | 52.72 | 62.62 |
| tried and left off: pseudo-relevance feedback (RM3) | 44.14 | 37.33 | 25.88 | 53.04 | 66.13 |
| **+ learned query→code associations (the search bar)** | **46.42** | **39.91** | 26.20 | **59.42** | **66.77** |

+3.56 nDCG@10 and +7.3 R@5 over plain BM25, with no model and no GPU. R@1 dips:
associations widen recall more than they sharpen the very top.

**How this compares, honestly.** These are lexical numbers. Dense code
embeddings do better on CoSQA-style queries: on NanoCoIR's CosQA (the same
6,267 functions, a different 50-query sample) BM25 scores 30.5 nDCG@10 and
a dense model 67.3. CoIR's full CosQA leaderboard tops out at 36.3 on its own
query split. The splits differ, so none of these numbers are directly
comparable to the table above. IntelliRAG fuses this lexical ranking with
embeddings when an embedding key is set; the benchmark here is the part that
runs with no key.

In the product the associations are learned from questions people confirmed
a passage answers (the experience log), so search sharpens on your own sources
the more the app is used.

Reproduce, from `web/`:

```bash
git clone --depth 1 --filter=blob:none --sparse https://github.com/microsoft/CodeXGLUE /tmp/cxg
git -C /tmp/cxg sparse-checkout set Text-Code/NL-code-search-WebQuery/CoSQA
COSQA_DIR=/tmp/cxg/Text-Code/NL-code-search-WebQuery/CoSQA npx tsx scripts/cosqa-bench.ts --check
```

CI runs the same check: the search bar must stay 2+ points above plain BM25
and match `cosqa-results.json`.
68 changes: 68 additions & 0 deletions eval/code-search/cosqa-results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"benchmark": "CoSQA dev (label 1) vs all unique CoSQA functions",
"queries": 313,
"documents": 6267,
"settings": {
"k1": 1.2,
"b": 0.75,
"nameWeight": 4,
"docWeight": 2,
"synonymWeight": 0.35,
"prfDocs": 0,
"prfTerms": 8,
"prfWeight": 0.3,
"useLexicon": false,
"associationWeight": 0.35,
"associationsPerTerm": 2
},
"arms": [
{
"arm": "BM25, IntelliRAG prose tokenizer",
"mrr10": 0.370833967239718,
"ndcg10": 0.42856262592410366,
"r1": 0.2715654952076677,
"r5": 0.5207667731629393,
"r10": 0.6134185303514377
},
{
"arm": "+ identifier-aware tokens",
"mrr10": 0.3923842486941529,
"ndcg10": 0.4549075966533442,
"r1": 0.2779552715654952,
"r5": 0.5527156549520766,
"r10": 0.6549520766773163
},
{
"arm": "+ name and docstring fields (BM25F)",
"mrr10": 0.39827957807191017,
"ndcg10": 0.4581641676708342,
"r1": 0.2779552715654952,
"r5": 0.5399361022364217,
"r10": 0.6485623003194888
},
{
"arm": " (tried, off) + developer lexicon",
"mrr10": 0.383252193316091,
"ndcg10": 0.44180910366028336,
"r1": 0.26198083067092653,
"r5": 0.5271565495207667,
"r10": 0.6261980830670927
},
{
"arm": " (tried, off) + pseudo-relevance feedback (RM3)",
"mrr10": 0.37328211369744885,
"ndcg10": 0.44135808902720697,
"r1": 0.25878594249201275,
"r5": 0.5303514376996805,
"r10": 0.6613418530351438
},
{
"arm": "+ learned query→code associations: search bar",
"mrr10": 0.39905040823571175,
"ndcg10": 0.464233407529018,
"r1": 0.26198083067092653,
"r5": 0.5942492012779552,
"r10": 0.6677316293929713
}
]
}
10 changes: 6 additions & 4 deletions eval/conversations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ npx tsx scripts/conversation-eval.ts --distractors # plus the ten seed runbooks

| Arm | Complete evidence | Follow-ups | Refused (of 3) | Complete, with distractors | Refused, with distractors |
|---|---:|---:|---:|---:|---:|
| turn-only | 61.5% | 59.1% | 1 | 64.1% | 1 |
| concat-history | **71.8%** | **77.3%** | 1 | **74.4%** | 1 |
| session-intent | **71.8%** | **77.3%** | **2** | **74.4%** | **2** |
| turn-only | 64.1% | 63.6% | 1 | 64.1% | 1 |
| concat-history | **76.9%** | **86.4%** | 1 | **76.9%** | 1 |
| session-intent | **76.9%** | **86.4%** | **2** | **76.9%** | **2** |

Session intent finds the evidence for 18 more points of follow-ups than the single-turn pipeline. It ties pasting the whole history on evidence, and refuses one more unanswerable follow-up, because context may help find a passage but never makes an unsupported question look answered.
Session intent finds the evidence for 22.8 more points of follow-ups than the single-turn pipeline. It ties pasting the whole history on evidence, and refuses one more unanswerable follow-up, because context may help find a passage but never makes an unsupported question look answered.

These numbers include `soloMargin` 1.5, an edit the self-improvement loop ([`../sim`](../sim)) found on a different evaluation. Before it, follow-ups were 77.3% (session intent) and 59.1% (turn-only).

**What lost.** The first design carried a handful of weighted terms (historical query expansion with idf weights and decay). It scored 64–69%: whole earlier questions keep the phrases BM25 and the phrase signal match on, and carried terms like "every" and "second" were noise. Weighting question terms by whether that turn's own evidence contained them made the term list a good *description* of the session, which is what the console now shows. It did not make it a better search. Both designs are in the git history of this file and `session-intent.ts`.

Expand Down
77 changes: 45 additions & 32 deletions eval/conversations/runs/clean/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
"distractors": false,
"summary": {
"turn-only": {
"completeEvidence": 0.6153846153846154,
"evidenceRecall": 0.6153846153846154,
"followUps": 0.5909090909090909,
"completeEvidence": 0.6410256410256411,
"evidenceRecall": 0.6410256410256411,
"followUps": 0.6363636363636364,
"switches": 0.3333333333333333,
"opening": 0.7142857142857143,
"refusals": "1/3"
},
"concat-history": {
"completeEvidence": 0.717948717948718,
"evidenceRecall": 0.717948717948718,
"followUps": 0.7727272727272727,
"completeEvidence": 0.7692307692307693,
"evidenceRecall": 0.7692307692307693,
"followUps": 0.8636363636363636,
"switches": 0.3333333333333333,
"opening": 0.7142857142857143,
"refusals": "1/3"
},
"session-intent": {
"completeEvidence": 0.717948717948718,
"evidenceRecall": 0.717948717948718,
"followUps": 0.7727272727272727,
"completeEvidence": 0.7692307692307693,
"evidenceRecall": 0.7692307692307693,
"followUps": 0.8636363636363636,
"switches": 0.3333333333333333,
"opening": 0.7142857142857143,
"refusals": "2/3"
Expand Down Expand Up @@ -275,7 +275,8 @@
"correctRefusal": null,
"packed": [
"p-queue:14",
"p-queue:11"
"p-queue:11",
"p-queue:4"
]
},
{
Expand Down Expand Up @@ -346,12 +347,13 @@
"carried": [],
"refused": false,
"answerable": true,
"recall": 0,
"complete": 0,
"recall": 1,
"complete": 1,
"correctRefusal": null,
"packed": [
"p-queue:15",
"p-queue:3"
"p-queue:3",
"p-queue:5"
]
},
{
Expand Down Expand Up @@ -683,7 +685,8 @@
"correctRefusal": null,
"packed": [
"p-queue:11",
"p-queue:14"
"p-queue:14",
"p-queue:5"
]
},
{
Expand Down Expand Up @@ -1004,7 +1007,8 @@
"correctRefusal": null,
"packed": [
"p-queue:6",
"p-queue:3"
"p-queue:3",
"p-queue:15"
]
},
{
Expand Down Expand Up @@ -1082,7 +1086,8 @@
"correctRefusal": null,
"packed": [
"p-queue:14",
"p-queue:11"
"p-queue:11",
"p-queue:4"
]
},
{
Expand Down Expand Up @@ -1211,12 +1216,13 @@
"carried": [],
"refused": false,
"answerable": true,
"recall": 0,
"complete": 0,
"recall": 1,
"complete": 1,
"correctRefusal": null,
"packed": [
"p-queue:7",
"p-queue:14"
"p-queue:14",
"p-queue:4"
]
},
{
Expand Down Expand Up @@ -1290,12 +1296,13 @@
"carried": [],
"refused": false,
"answerable": true,
"recall": 0,
"complete": 0,
"recall": 1,
"complete": 1,
"correctRefusal": null,
"packed": [
"p-queue:7",
"p-queue:1"
"p-queue:1",
"p-queue:3"
]
},
{
Expand Down Expand Up @@ -1487,7 +1494,8 @@
"correctRefusal": null,
"packed": [
"p-queue:11",
"p-queue:14"
"p-queue:14",
"p-queue:5"
]
},
{
Expand Down Expand Up @@ -1841,7 +1849,8 @@
"correctRefusal": null,
"packed": [
"p-queue:6",
"p-queue:3"
"p-queue:3",
"p-queue:15"
]
},
{
Expand Down Expand Up @@ -1930,7 +1939,8 @@
"correctRefusal": null,
"packed": [
"p-queue:14",
"p-queue:11"
"p-queue:11",
"p-queue:4"
]
},
{
Expand Down Expand Up @@ -2086,12 +2096,13 @@
],
"refused": false,
"answerable": true,
"recall": 0,
"complete": 0,
"recall": 1,
"complete": 1,
"correctRefusal": null,
"packed": [
"p-queue:7",
"p-queue:14"
"p-queue:14",
"p-queue:4"
]
},
{
Expand Down Expand Up @@ -2181,12 +2192,13 @@
],
"refused": false,
"answerable": true,
"recall": 0,
"complete": 0,
"recall": 1,
"complete": 1,
"correctRefusal": null,
"packed": [
"p-queue:7",
"p-queue:1"
"p-queue:1",
"p-queue:3"
]
},
{
Expand Down Expand Up @@ -2395,7 +2407,8 @@
"correctRefusal": null,
"packed": [
"p-queue:11",
"p-queue:14"
"p-queue:14",
"p-queue:5"
]
},
{
Expand Down
Loading
Loading