Repository navigation
Description
Component
Memory and search
Describe what's wrong
namespace.search_categories ranks category embeddings with no regard to which model produced them.
namespace.register_category stores embedding_model and embedding_dim from the embedder that ran. namespace.search_categories embeds the query with the current embedder and runs:
cosineDistance(embedding, {q:Array(Float32)}) AS distance
FROM loom.categories FINAL
WHERE org = {org:String} AND namespace = {ns:String}
AND embedding_dim > 0
AND tombstoned_at IS NULL
ORDER BY distance ASC
LIMIT {top_k:UInt32}The statement has no embedding_model predicate, and the query parameters are org, ns, q and top_k. Two categories embedded by different models of the same dimension are ordered on one cosine. A stored vector whose length is not the query's is still selected, because the filter is embedding_dim > 0 rather than the query length.
Captured on commit 5fbc62c by calling handle_namespace_search_categories with a stub client and an embedder named model-b. The SQL above is the statement it sent. embedding_model does not appear in it. ClickHouse was not queried, so no distances were returned.
Does it reproduce on the latest release or main?
Yes
How to reproduce
Default settings. One namespace. Register two categories while the embedder is model A, then change LOOM embedding settings to model B of the same dimension and register a third. Call:
POST /v1/namespace.search_categories
{"org": "example", "namespace": "example", "query": "billing", "top_k": 5}The result orders A and B vectors together. The statement does not receive the current model name.
Expected behavior
Search compares the query vector only to categories whose embedding_model is the model that embedded the query, and whose embedding_dim equals that vector's length. Categories embedded by another model stay out of the ranking. namespace.register_category already stores embedding_model for this.
Environment
Source: ClickHouse/loom main, commit 5fbc62c21a, package version 1.3.0
Python: 3.14.6
Platform: macOS arm64
LOOM_STORAGE_AUTHORITY: clickhouse (the default)
ClickHouse: not queried
How this was found
An AI tool found it, and I have not reproduced it myself
Additional context
The SQL was captured from the handler. No category rows were ranked by ClickHouse.
Redaction
- I removed tokens, keys, passwords and personal or customer data from everything above.
Activity