Skip to content

namespace.search_categories ignores embedding_model #1033

Closed

Description

@zlareb1

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

  1. added
    bug
    on Nov 20, 2026
  2. self-assigned this
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions