Repository navigation
knowledge.search can rerank its fused hits, per request or by deployment default - #223
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/knowledge-contextual-lexical
branch
from
November 3, 2026 15:59
dcc15aa to
f99c415
Compare
zlareb1
force-pushed
the
feat/knowledge-search-rerank
branch
from
November 3, 2026 16:07
37a3877 to
a1be47c
Compare
zlareb1
force-pushed
the
feat/knowledge-contextual-lexical
branch
from
November 3, 2026 16:44
7ec43f2 to
b390b3d
Compare
zlareb1
changed the base branch from
feat/knowledge-contextual-lexical
to
main
November 3, 2026 16:46
zlareb1
force-pushed
the
feat/knowledge-search-rerank
branch
5 times, most recently
from
November 3, 2026 19:37
8a8d81c to
23a0d9f
Compare
…ent default A request's rerank (or LOOM_KNOWLEDGE_SEARCH_RERANK_DEFAULT) names a reranker: a builtin or an endpoint in LOOM_RERANK_ENDPOINTS_JSON, as memory.search and code.search take. The legs fetch at least the rerank head (knowledge_search_rerank_top), each candidate shows the chunk's stored context before its text, and the reranker's order is the page before sections collapse. reranked_by names the reranker that produced the order; a failed rerank keeps the fused order and leaves it empty. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y-docs leg and defaults no request may name Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nothing; a reranked answer keeps its order beside the repository's docs Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…age, and the legs fetch the rerank head once Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t checks each chunk's context reaches the reranker Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…tory merge's comment says what it gives Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y and LLM-free pages name the knowledge default Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…nothing; the shared reranker names its callers Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ked merge does Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… what a rerank orders, and a held call is tested through the search Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…time limit LOOM_KNOWLEDGE_SEARCH_RERANK_TIMEOUT_S (8 s) bounds the rerank call; a Cohere reply that is not a JSON object keeps the input order. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
feat/knowledge-search-rerank
branch
from
November 3, 2026 20:39
23a0d9f to
f30163b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #206
Related: #193
Builds on #206 (merged): it reads the chunk
contextthat PR stores.Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
knowledge.searchtakesrerank(a builtin reranker or a configured endpoint, asmemory.searchdoes) and a deployment defaultLOOM_KNOWLEDGE_SEARCH_RERANK_DEFAULT; the HTTP and MCP response'sreranked_bynames the reranker that ordered the hits.Why
memory.searchandcode.searchcan rerank their fused candidates;knowledge.searchcould not, so document retrieval stopped at reciprocal-rank fusion. On the labelled fixture of #193, fusion puts the right passage first on fewer queries than the vector leg alone, and a reranker over the fused head fixes that and more.Measured with
bench/knowledge_retrieval.py(#193: 21 synthetic documents, 76 answerable queries; text-embedding-3-large; one ingest on this branch's server, three search arms on it):hybrid(default)hybrid,rerank=builtin:openaisemanticPaired by query against the
hybridarm on the same ingest (bench.bootstrap.paired_bootstrapover the fixture's 36 query clusters, 95%): R@1 +0.342 [+0.208, +0.483], MRR +0.217 [+0.134, +0.307], nDCG@10 +0.203 [+0.136, +0.276]; 26 queries improve at R@1 and none get worse.The treatment ran: replaying the 81 fixture queries against the same server with
rerank=builtin:openai, 69 answeredreranked_by: "builtin:openai"and 12 answered"", which is the reranker handing back the fused order unchanged (the server logged no rerank failure or time-limit cut). The harness checks onlyignored_args; it does not countreranked_by. The cost is one LLM call per search over 30 candidates of up to 800 characters: about 2 s per query here, against tens of milliseconds without it. That is why the deployment default stays empty: a deployment opts in, or a caller asks per request.Design
KnowledgeSearchInput.rerank: RerankName(the typememory.searchandcode.searchuse):""takesknowledge_search_rerank_default,"none"turns it off, otherwise a builtin (builtin:openai[:<model>],builtin:cohere[:<model>]) or a name inLOOM_RERANK_ENDPOINTS_JSON. A URL is refused at validation (422).server.memory.app.rerank.rerank: named endpoints only, the model client's gateway rules, and every failure hands back the input, which the handler reports as no rerank. The call is bounded byknowledge_search_rerank_timeout_s(8 s), since abuiltin:openaicall is otherwise bounded only by the model client's timeout and retries; past it the fused order is kept andreranked_byis empty. The cut is the search's own deadline, so it records no provider failure in health.LOOM_READS_LLM_FREEa read reranks only as its request names (the deployment default is a model call), and a request-namedbuiltin:openaiis dropped before the legs widen their pool, asmemory.searchdoes.check_rerank_namea request's value passes: a URL or an unconfigured name is no reranker (logged once per value), and"none"is none, so the pool is not widened for nothing.builtin:coherebehind a required gateway fails at boot, as it already does forLOOM_CODE_SEARCH_RERANK_DEFAULT.reranked_byis set only when the reranker's order differs from the fused one (it is empty when no reranker ran, it failed, or it kept the fused order): the service hands back its input, or a copy in input order, when it fails or cannot read a reply.knowledge_search_rerank_top(30) hits (the page's own over-fetch for collapsing sections is not multiplied on top), so the reranker reads a head larger than a small page. Each candidate is the chunk's stored context (title, description, breadcrumb, from knowledge.search's lexical leg scores each chunk's title and section path with its text #206) followed by its text, cut atknowledge_search_rerank_excerpt_chars(800), with the context capped at half of it so a long description cannot crowd out the chunk's own text: the context is what tells a reranker that a "Refunds" section belongs to one product's handbook.collapse_sectionsand thetop_kcut;scorekeeps the fused value, andKnowledgeSearchOutput.reranked_bysays the order came from a reranker.LIVE, in the knowledge section next to the otherknowledge_search_*fields, ascode_search_rerank_defaultsits with the code settings.Scope and risk
knowledge.search, plus one change to the shared rerank service: abuiltin:coherereply whose JSON is not an object keeps the input order instead of raising, formemory.searchandcode.searchtoo. Callers that do not namererank(the op itself andloom_search's knowledge section) take the deployment default when one is set, and pay its latency once per call (a caller that searches again to widen its read pays again, andloom_searchthen reports the wider search'sreranked_by; eachloom_searchpage runs the knowledge leg again and pays it too). The other callers passrerank="none":memory.ask's knowledge passages and its synthesize-route probe (the ask's synthesis reads the passages, and a rerank would run before its cost cap and synthesis switch are checked),context.pack's knowledge section (a pack runs on every chat turn), andloom_search's repository-docs leg, which runs underknowledge_repo_docs_timeout_s(1.5 s), which a model call would outlast. When that leg adds hits to a reranked answer, the fused scores still decide which repository hits earn a place (the rule of the unreranked merge), and the reranked hits keep their order ahead of them. With the default empty and norerankon the request the ranking is unchanged; both legs now also select the chunk'scontextcolumn. The op's 250 ms latency budget does not hold for a call that reranks with an LLM; a deployment that sets the default accepts that.Compatibility, rollout and rollback
knowledge.searchinput gainsrerank(default""); output gainsreranked_by(default""). N-1 ignores an unknownrerankas anignored_argsread field.LOOM_KNOWLEDGE_SEARCH_RERANK_DEFAULT(for examplebuiltin:openai, or an endpoint name fromLOOM_RERANK_ENDPOINTS_JSON).knowledge.search()returns the hit list only, as it does fornamespaces_skipped; a caller passesrerankthrough its**extraand readsreranked_byfrom the raw op (loom.ops, or HTTP/MCP).Tests
tests/unit/test_knowledge_search_rerank.py: which reranker a call uses (request, default,"none", LLM-free reads, a default no request may name), a URL refused, a held model call failing the search, sections collapsing after the rerank, the head reordered with each candidate's context before its text and the tail kept, a failed rerank keeping the fused order withreranked_byempty, the legs fetching the rerank head for a smaller page, a reranker past its time limit keeping the fused order, a Cohere reply without aresultslist (a list, a string, or an object whoseresultsis not a list) keeping the input order.tests/unit/test_repo_docs.py: the repository leg passesrerank="none", and a reranked answer admits repository hits by fused score and keeps its own order.tests/unit/test_llm_gateway.py: either rerank default namingbuiltin:coherebehind a required gateway fails at boot.tests/unit/test_assistant_learnings.pyandtest_ask_knowledge_plane_tags.py: a pack's and an ask's knowledge reads passrerank="none".test_a_pinned_tokens_loom_search_serves_its_signed_bots_rules: eachloom_searchpass names its own reranker, and the section reports the last (wider) pass'sreranked_by.tests/integration/test_knowledge.py:rerank="none"answersreranked_by: ""; a URL is a 422. Ran against this branch's server on its own ClickHouse.tests/unit/snapshots/live_settings.jsonandsettings_defaults.jsonupdated.make format lint typecheck,pytest tests/analyzer; unit files around search, settings, package contracts, docs and public copy: 721 passed.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code; the measurement and the integration run were made locally.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code