Skip to content
Closed
2 changes: 1 addition & 1 deletion docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ The code index's network git (clone, fetch, ls-remote, submodule update) through
| --- | --- | --- | --- | --- |
| `LOOM_CODE_TRACE_LOG_ENABLED` | `bool` | `True` | | Fire-and-forget code_search_trace/code_search_outcome telemetry. |
| `LOOM_CODE_FUSION_SIGNALS` | `bool` | `True` | | Post-fusion rank priors in code.search (path-noise penalty, query↔path stem affinity, file coherence), applied after RRF and before the outcome boost. Kill switch. |
| `LOOM_CODE_SEARCH_QUERY_MAX_TOKENS` | `int` | `48` | | Long-question trim: past this many lexemes the question is treated as an issue body (template headings stripped, the rarest 32 tokens gate, the first 512 cleaned words embed). Under the cap nothing changes. 0 = off. |
| `LOOM_CODE_SEARCH_QUERY_MAX_TOKENS` | `int` | `48` | | Long-question trim: past this many lexemes the question is treated as an issue body (template headings stripped, at most 32 tokens gate: its identifiers and its words, those it repeats first; the first 512 cleaned words embed). Under the cap nothing changes. 0 = off. |
| `LOOM_CODE_SEARCH_FILE_SATURATION` | `float` | `0.5` | | Per-file saturation: the 2nd, 3rd... unit from one path is multiplied by decay^excess before the cut; a file's best unit never decays. 0 = off. Skipped under path_prefix, symbol routes and test intent. |
| `LOOM_CODE_SEARCH_VECTOR_MODELS` | `str` | `''` | | CSV of vector-model specs a request may name as `vector_model` (e.g. "prefix:512:text-embedding-3-large"); only the vector leg switches. Empty = the override is refused. |
| `LOOM_CODE_VECTOR_TABLES` | `str` | `''` | | JSON {label: {"table": "loom.x", "dim": 256}}: where a label's chunk rows live (the coded vector column is fixed-width). Absent label = loom.code_chunks. Inserts and the vector leg route by it. |
Expand Down
5 changes: 3 additions & 2 deletions loom.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1971,8 +1971,9 @@ settings:
# code_fusion_signals: true

# Long-question trim: past this many lexemes the question is treated as an issue body
# (template headings stripped, the rarest 32 tokens gate, the first 512 cleaned words
# embed). Under the cap nothing changes. 0 = off. [restart]
# (template headings stripped, at most 32 tokens gate: its identifiers and its words,
# those it repeats first; the first 512 cleaned words embed). Under the cap nothing
# changes. 0 = off. [restart]
# code_search_query_max_tokens: 48

# Per-file saturation: the 2nd, 3rd... unit from one path is multiplied by
Expand Down
2 changes: 1 addition & 1 deletion schemas/loom-settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@
"code_search_query_max_tokens": {
"default": 48,
"type": "integer",
"description": "Long-question trim: past this many lexemes the question is treated as an issue body (template headings stripped, the rarest 32 tokens gate, the first 512 cleaned words embed). Under the cap nothing changes. 0 = off."
"description": "Long-question trim: past this many lexemes the question is treated as an issue body (template headings stripped, at most 32 tokens gate: its identifiers and its words, those it repeats first; the first 512 cleaned words embed). Under the cap nothing changes. 0 = off."
},
"code_search_rerank_default": {
"default": "",
Expand Down
5 changes: 3 additions & 2 deletions server/code/api/models_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
class CodeSearchInput(_CodeIdentity, _ResultLessons):
# The question, identifier or phrase to search for; a symbol-shaped query tries the
# symbol table first (`route` says which path answered). A long one (a pasted issue
# body) is clipped to QUERY_MAX_CHARS, never refused: the search keeps its rarest
# terms (code_search_query_max_tokens) whatever its length.
# body) is clipped to QUERY_MAX_CHARS, never refused: the search keeps its identifiers
# and its words, those it repeats first (code_search_query_max_tokens), whatever its
# length.
query: str = Field(
min_length=1,
description="Issue, task, behavior question or identifier to locate in indexed code.",
Expand Down
5 changes: 2 additions & 3 deletions server/code/app/search/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ async def _concept_leg_rows(
work["concept_terms"] = len(terms)
concept_stats["terms"] = terms
if terms:
plan2 = query_trim.plan(
" ".join(terms), None, settings.code_search_query_max_tokens, {}
)
# chosen terms, all kept: not a question to pick words from
plan2 = query_trim.plan("", terms, settings.code_search_query_max_tokens, {})
c_tokens, c_idfs = await _lexical_terms(
repo,
org,
Expand Down
4 changes: 2 additions & 2 deletions server/code/app/search/gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ async def _gather_legs(
work, scope, constrained, shape, model = st.work, st.scope, st.constrained, st.shape, st.model
# extra_terms extend the LEXICAL leg only (code.ask query expansion: proposed
# identifiers bridge natural-language -> codebase vocabulary; the vector leg keeps
# embedding the user's actual question). A long question is asked with its rarest
# words and its cleaned first page
# embedding the user's actual question). A long question is asked with its
# identifiers, the words it repeats and its cleaned first page
trim = query_trim.plan(query, extra_terms, settings.code_search_query_max_tokens, work)
tokens = st.tokens = trim.tokens
# one query embedding per embedder per call: _QueryVecMemo
Expand Down
14 changes: 12 additions & 2 deletions server/code/app/search/lexical.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ async def _lexical_terms(
"""The lexical leg's (tokens, idfs): one corpus-stats read.

Under an active trim plan the stats read probes EVERY token of the cleaned question
and the leg keeps the rarest `trim.cap` of them (identifiers always)."""
and the leg keeps at most `trim.cap`: its identifiers and its words, those it repeats
first."""
from server.code.app.index import corpus_stats

trimming = trim is not None and trim.active
Expand All @@ -91,7 +92,16 @@ async def _lexical_terms(
df, n_chunks, _avgdl = await corpus_stats.stats(repo, org, ns, base, work)
lex_tokens = tokens
if trimming and trim is not None:
lex_tokens = query_trim.select_rarest(base, df, trim.cap, trim.keep)
lex_tokens = query_trim.select_terms(
base,
df,
n_chunks,
trim.cap,
keep=trim.keep,
said=trim.said,
own=trim.own,
named=trim.named,
)
work["query_trimmed_tokens_used"] = len(lex_tokens)
idfs = [bm25.idf(df.get(t, 0), max(n_chunks, 1)) for t in lex_tokens]
return lex_tokens, idfs
Loading