NIP-50 field filters are silently dropped when the search string also contains free text (fail-open in chunk-rerank path) #22
Loading…
Reference in a new issue
No description provided.
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?
Symptom (verified live on wss://amb-relay.edufeed.org, 2026-08-19)
A search combining free text with a field filter ignores the filter entirely:
{"kinds":[30142],"search":"LADEN publisher.name:zzz-bogus-control-xyz","limit":2}→ returns free-text hits forLADEN(bogus control should force 0 results){"kinds":[30142],"search":"publisher.name:zzz-bogus-control-xyz"}(filter only) → correctly returns 0{"kinds":[30142],"search":"publisher.name:e-teaching.org"}(filter only) → correctly filtered resultsSo pure field-filter searches take the plain Typesense path and fail closed, but as soon as a free-text term is present the filter is dropped and the query gets wider — exactly the fail-open class the typesense30142 README warns about for tag filters ("Unsupported filters fail closed").
Cause
main.go,relay.QueryStored: searches matchingreg.targetsChunked(filter) && searchHasFreeText(filter.Search)are routed tocalendarRerankQuery→ chunk searcher (amb-indexer). The comment there already documents the hazard for pure field-filter searches ("rerank would send the raw string to the chunk index and drop the field filter — those must take the plain field-filter path too") — but a combined search (free text + field filter) still goes down the rerank path, where thefield.path:valuetokens are not honoured as filters.Impact
Any client that follows the documented "Combined Queries" section of the typesense30142 README (e.g.
"forschung publisher.name:e-teaching.org") silently gets unfiltered results. For MCP agents this presents as confidently wrong answers — indistinguishable from an honest match. This broke the "topic + publisher" agent flow that triggered this investigation (amb-mcp side: gitworkshop.dev issue "Field-filter values with spaces are not quoted").Fix options
ParseSearchQuery(filter.Search).FieldFiltersis non-empty, take the plainreg.fetchpath even when free text is present — correctness over passage re-ranking.Option 1 is a small, safe change; option 2 preserves snippet ranking for combined queries and could follow later.