Skip to content

An entity cannot be fetched by its exact name, so a lookup scans the base #1479

Done

Description

@gedaiu

An entity cannot be fetched by its exact name, so a lookup scans the base

Small one, with numbers. The entity search already puts an exact match first, which we rely on; what we miss is a way to ask for only that match.

What we see

Our mirror names every entity with its repository and path (re-cinq/lore:libs/shared/src/work/backlog/queue-ticket.ts), so a reader that wants one entity always knows its exact name. Today the only door is GET /kbs/{kb}/entities?q=, and on base 01a14133-f48c-7183-a3e2-48296b6752d6 one such lookup took 11.5 s, 12.0 s and 17.6 s in three tries this morning, against 0.8 s for the entity_detail that follows it. The lookup is most of the cost of reading a fact chain.

Why

graph::search_entities matches e.canonical_name ILIKE '%q%' (plus the known_as names), which no index serves, and then orders exact matches first with lower(e.canonical_name) = ANY($5) OR {has_name_in}. The index (kb_id, lower(canonical_name)) WHERE merged_into IS NULL from 0003_graph.sql exists and would serve the exact test on its own.

Proposed change

An optional exact=true on the same route. When set, the WHERE uses the ordering expression as the filter (exact canonical name after the usual fold, or an exact known_as name) and nothing else; total counts the same way. The default is unchanged, so no client notices.

We will add it on our fork with a test that an exact query for a.ts does not return a.ts#parse, and send it here if you would like it. Thank you for reading.

Activity

  1. gedaiu commented on Nov 5, 2026

    @gedaiu
    ContributorAuthor

    A small version is on our fork as re-cinq#51: exact=true filters on the same expression that already orders exact matches first, default unchanged, with a store test and a read-token route test. Happy to send it whenever you like.

  2. WaylandYang commented on Nov 25, 2026

    @WaylandYang
    Contributor

    Fixed by #1491 (merged into dev): exact=true fetches an entity by its exact name through the name index. Closing by hand, since closing keywords don't fire on dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions