Semantic search silently ignores the \`project\` filter (Chroma path never applies a where-clause)
Summary
project is accepted, documented and forwarded by /api/search/observations, /api/search/sessions and /api/search/prompts — and then silently ignored. Semantic search returns results from every project regardless of the filter. The SQLite-backed by-type, by-file and by-concept endpoints filter correctly on the same data, so this reads as an oversight in the Chroma path rather than a design decision.
Seen on claude-mem 10.1.0.
Reproduction
Two projects, only one of which owns the matching observation (#75900 belongs to hearth-and-rampart):
curl -s 'localhost:37777/api/search/observations?query=OfflineSeedLog&project=hearth-and-rampart&limit=3'
# Found 3 observation(s) matching "OfflineSeedLog"
curl -s 'localhost:37777/api/search/observations?query=OfflineSeedLog&project=opencode-claude-mem&limit=3'
# Found 3 observation(s) matching "OfflineSeedLog" <-- same three, foreign projectopencode-claude-mem has zero observations, so a working filter would return none. The SQLite-backed endpoints on identical data behave correctly:
curl -s '.../api/search/by-type?type=bugfix&project=hearth-and-rampart' # Found 5
curl -s '.../api/search/by-type?type=bugfix&project=opencode-claude-mem' # No observations found
curl -s '.../api/search/by-file?filePath=OfflineSeedLog&project=hearth-and-rampart' # Found 1
curl -s '.../api/search/by-file?filePath=OfflineSeedLog&project=opencode-claude-mem' # No resultsCause
searchObservations destructures the normalized query into { query, ...rest } and then only ever reads rest.limit. rest.project is never used, and the Chroma call passes no where-clause:
searchObservations(e) {
let r = this.normalizeParams(e), { query: n, ...i } = r, a = [];
if (this.chromaSync) {
let c = await this.queryChroma(n, 100); // no `where`
// ...
a = this.sessionStore.getObservationsByIds(l, { orderBy: "date_desc", limit: i.limit })The capability already exists — queryChroma takes the where-clause as its third parameter, and searchSessions already uses that slot for doc_type:
async queryChroma(e, r, n) {
// ... this.collection.query({ queryTexts: [e], nResults: r, where: n, ... })
}
searchSessions: queryChroma(n, 100, { doc_type: "session_summary" })So project can be threaded through on the existing path, e.g. queryChroma(n, 100, { project: i.project }). If embeddings with a missing project make the where-clause throw, that would need a filter, but it should probably fail loudly rather than return unscoped rows — which is the current behaviour.
Two related observations
No non-Chroma fallback. searchObservations has no else branch: the if (this.chromaSync) block runs straight into the result formatting, so a stays [] when Chroma is unavailable and the endpoint answers Found 0 observation(s). Disabling Chroma doesn't yield correct filtering, it yields silence — the same "empty looks like no memories" trap the search endpoints otherwise try to avoid.
The filter-only branch is a 500. Filtering by project with no query throws Expected each document to be a string, but got undefined, so clients trying to scope without a search term get an error rather than a result.
Impact
Any client that scopes recall by project — which /api/search/help advertises as supported — silently receives every project's memories mixed in. For a client that injects results into a session's context, another project's observations surface as if they were this project's, and the client cannot tell: the response is a rendered markdown table with no project column to filter on.
Context injection via /api/context/inject is unaffected and filters correctly, so this is specific to the semantic search endpoints.
I maintain an OpenCode plugin that talks to this worker (@ephillipe/opencode-claude-mem). I worked around it by appending an explicit "these results span all projects" note to every search result and documenting the limitation. Happy to send a PR for the where-clause threading if that's useful.
Source: thedotmack/claude-mem