llm: retrieval endpoints — /search, /similar #570
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Similarity search over the comment + corpus collections.
Scope
/search: query text + metadata filters (docket, rule, year, doctype, collection), pagination/similar/{key}: nearest neighbors of an existing bib itemAcceptance
Spec:
docs/superpowers/specs/2026-07-16-llm-module-design.mdStatus audit (2026-08-13, repo-verified): NOT DONE. api.py exposes only /health, /, /whoami, /chat. Retrieval exists internally (
llm/rag.py:29retrieve, k=6, comments collection) but no /search or /similar HTTP endpoints, no metadata filters, no pagination. Note: therulespgvector collection added by P36 (#595) will want the same filters.Done (
192274e, merged to main): GET /search?q=&collection=all|comments|rules|corpus&docket=&item_key=&year=&kind=&limit=&offset= and GET /similar/{key} on the llm service (src/llm/search.py). One embedding per request, per-collection overfetch with docket/item_key/kind pushed into the pgvector store filter and year applied on the chunk date, merged by distance, paginated; /similar averages up to three of the item's own chunk vectors and excludes the item; results are the chat's source dicts (label, kind, url, title, date, docket, item_key, p_id/seq, snippet) plus distance. Acceptance: docket-scoped search on CMS-2023-0121 returned only that docket; p50 ≈ 120 ms over 5 in-process calls (first call 2.8 s includes model warm-up). 57 tests. Note: total is the page length (no COUNT query). Needs the llm image rolled to reach the live service.