AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(search): use boost 4 and correct the rationale for the phrase clause
Leonid Bugaevc096634685ee
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex 293e6061f..aba005d6c 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -7210,7 +7210,7 @@ fn get_doc_response_hint(index: &str, doc_bytes: usize) -> Value {}},{"match_phrase": {"defs": {"query": "<the symbol or phrase you want>",- "boost": 8,+ "boost": 4,}}},]}},// Project the path rather than dropping `_source`: a blinddiff --git a/engine/crates/xerj-autoindex/src/catalog.rs b/engine/crates/xerj-autoindex/src/catalog.rsindex 06b0cfe65..6b465e1e6 100644--- a/engine/crates/xerj-autoindex/src/catalog.rs+++ b/engine/crates/xerj-autoindex/src/catalog.rs@@ -280,12 +280,19 @@ pub fn build_sample_queries(pd: &PlanDataset, correlations: &[KeyCorr]) -> Vec<V.to_string();// Code datasets additionally carry `defs` (newline-joined "kind// name" per symbol, identifying the file that DEFINES a symbol —- // see `dataset.rs`). `defs` is analyzed text, so `strip_shortcodes`- // tokenizes to `strip` + `shortcodes`; boosting it alone amplifies- // conceptual noise. The phrase clause requires the token sequence,- // so it contributes for a symbol definition but essentially never- // for a multi-word conceptual query. Only emit this shape when `defs`- // actually exists on the dataset — never assume it. `_source` is+ // see `dataset.rs`). `defs` indexes identifiers as WHOLE tokens:+ // `strip_shortcodes` is one term, and neither `strip` nor+ // `shortcodes` matches it. A plain `match` on `defs` is an OR over+ // the query's tokens, so a conceptual query still hits many+ // documents through incidental overlap with symbol and kind words —+ // which is what a `defs` boost amplifies. The phrase clause instead+ // requires the whole token sequence, so a symbol lookup resolves to+ // its definition while a multi-word conceptual query matches nothing+ // at all and contributes no score. Note this is gated on word count,+ // not on intent: a single-word query is one token and can still+ // match a symbol of that name, which is why the boost stays modest.+ // Only emit this shape when `defs` actually exists on the dataset —+ // never assume it. `_source` is// projected to the two fields an agent needs to act on a hit// (`ax_path`, `title` — present on every ingested document, not just// code) and `fields: ["_passage"]` asks for the matching snippet@@ -305,7 +312,7 @@ pub fn build_sample_queries(pd: &PlanDataset, correlations: &[KeyCorr]) -> Vec<V}},{"match_phrase": {"defs": {"query": word.clone(),- "boost": 8,+ "boost": 4,}}},]}},"_source": ["ax_path", "title"],diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rsindex d6ae41fcd..3e3dec046 100644--- a/engine/crates/xerj-autoindex/src/lib.rs+++ b/engine/crates/xerj-autoindex/src/lib.rs@@ -4710,7 +4710,7 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {" code was indexed — for a function/class instead of a whole file:\n\\x20 curl -s $URL/{}-*/_search -H 'Content-Type: application/json' \\\n\\x20 -d '{{\"query\":{{\"bool\":{{\"should\":[{{\"multi_match\":{{\"query\":\"<symbol or phrase>\",\- \"fields\":[\"body\",\"defs\"],\"type\":\"most_fields\"}}}},{{\"match_phrase\":{{\"defs\":{{\"query\":\"<symbol or phrase>\",\"boost\":8}}}}}}]}}}},\+ \"fields\":[\"body\",\"defs\"],\"type\":\"most_fields\"}}}},{{\"match_phrase\":{{\"defs\":{{\"query\":\"<symbol or phrase>\",\"boost\":4}}}}}}]}}}},\\"_source\":[\"ax_path\",\"title\"],\"fields\":[\"_passage\"]}}'\n\\x20 (the `match_phrase` clause ranks the file that DEFINES a symbol above files that merely call it; `_passage` returns \the enclosing block, not the file)",diff --git a/engine/crates/xerj-server/src/main.rs b/engine/crates/xerj-server/src/main.rsindex 7743e7208..558bfb9a1 100644--- a/engine/crates/xerj-server/src/main.rs+++ b/engine/crates/xerj-server/src/main.rs@@ -261,7 +261,7 @@ fn print_help() {\n\curl -s $URL/<index>/_search -H 'Content-Type: application/json' \\\n\-d '{{\"query\":{{\"bool\":{{\"should\":[{{\"multi_match\":{{\"query\":\"<symbol or phrase>\",\n\- \"fields\":[\"body\",\"defs\"],\"type\":\"most_fields\"}}}},{{\"match_phrase\":{{\"defs\":{{\"query\":\"<symbol or phrase>\",\"boost\":8}}}}}}]}}}},\n\+ \"fields\":[\"body\",\"defs\"],\"type\":\"most_fields\"}}}},{{\"match_phrase\":{{\"defs\":{{\"query\":\"<symbol or phrase>\",\"boost\":4}}}}}}]}}}},\n\\"_source\":[\"ax_path\",\"title\"],\"fields\":[\"_passage\"]}}'\n\\n\the `match_phrase` clause ranks the file that DEFINES a symbol above files that merely call it;\n\diff --git a/landing/llms-full.txt b/landing/llms-full.txtindex 94d0077f5..2b86aad0f 100644--- a/landing/llms-full.txt+++ b/landing/llms-full.txt@@ -270,7 +270,7 @@ Large documents — ask for the snippet, not the whole file (see §2):`multi_match`, and with a single semantic/kNN clause; combine with a projected`_source` for the largest size reduction. For code specifically,`bool.should` with `multi_match` over `["body","defs"]` and a- `match_phrase` on `defs` with "boost":8 (`defs` is autoindex's per-file symbol+ `match_phrase` on `defs` with "boost":4 (`defs` is autoindex's per-file symbolindex — one "kind name" line per definition) ranks a file that DEFINES a symbolover one that merely mentions it — `xerj autoindex map` prints this exact querypre-built for every code dataset it finds.diff --git a/landing/llms.txt b/landing/llms.txtindex e28713ad5..623b4f320 100644--- a/landing/llms.txt+++ b/landing/llms.txt@@ -213,7 +213,7 @@ XERJ turns reference coding — retrieving how existing projects solved a proble1. Index the project you are working on: `xerj autoindex .`2. Find the open-source projects closest to what you are building (same domain, not necessarily the same language), `git clone --depth 1` each, and `xerj autoindex <clone>`.-3. Before writing non-trivial code, search those indices for the mechanism ("how does the merge policy pick segments", not just the API name) and read the returned passages instead of re-deriving the algorithm. The strongest trigger to retrieve: you have already looped twice on the same error. A code dataset also carries `defs` (one "kind name" line per symbol, naming the file that DEFINES it) alongside `body`; query a `bool.should` with `multi_match` over `["body","defs"]` and `match_phrase` on `defs` with "boost":8, project `"_source":["ax_path","title"]`, and add `"fields":["_passage"]` so each hit is the matching snippet, not the whole file — `xerj autoindex map` prints this exact query pre-built for every code dataset it finds.+3. Before writing non-trivial code, search those indices for the mechanism ("how does the merge policy pick segments", not just the API name) and read the returned passages instead of re-deriving the algorithm. The strongest trigger to retrieve: you have already looped twice on the same error. A code dataset also carries `defs` (one "kind name" line per symbol, naming the file that DEFINES it) alongside `body`; query a `bool.should` with `multi_match` over `["body","defs"]` and `match_phrase` on `defs` with "boost":4, project `"_source":["ax_path","title"]`, and add `"fields":["_passage"]` so each hit is the matching snippet, not the whole file — `xerj autoindex map` prints this exact query pre-built for every code dataset it finds.4. Cite what you drew on (project + file:line) in your commit message, and say plainly whether you adapted or copied.License discipline is part of the method, not an afterthought: check each repository's license BEFORE copying anything. Copyleft and source-available code (GPL, AGPL, SSPL, BUSL) is approach-only — read the design, then write your own implementation. Permissive licenses (MIT, BSD, Apache-2.0) allow adaptation with attribution on their terms. And when retrieval returns nothing relevant, say so and work normally — forcing a bad match in is worse than not retrieving. Expect retrieval to pay off most on unfamiliar, niche, or internal code, and least on popular public libraries your model already knows well.