Repository navigation
fix(backend): AI Chat can't find conversations by speaker/participant names — hybrid keyword+vector search (#5072) - #7811
Conversation
Greptile SummaryFixes AI Chat's inability to find conversations by speaker/participant names by replacing pure Pinecone vector search with a hybrid keyword+vector approach at both chat retrieval paths (
Confidence Score: 4/5Safe to merge for the core bug fix; the hybrid retrieval logic is correct and the fail-open design prevents regressions. The two new helper functions are small and well-tested. The only thing worth watching is that both keyword and vector each independently pull up to The merge-without-cap pattern appears in both Important Files Changed
Sequence DiagramsequenceDiagram
participant LLM as AI Chat / LangChain
participant Tool as search_conversations_tool / search_conversations_text
participant KW as keyword_search_conversation_ids (Typesense)
participant VEC as vector_db.query_vectors (Pinecone)
participant Merge as merge_conversation_search_ids
participant FS as Firestore (get_conversations_by_id)
LLM->>Tool: query, limit, uid
par Keyword search
Tool->>KW: uid, query, limit
KW-->>Tool: keyword_ids (or [] on error)
and Vector search
Tool->>VEC: "query, uid, starts_at, ends_at, k=limit"
VEC-->>Tool: vector_ids
end
Tool->>Merge: keyword_ids, vector_ids
Merge-->>Tool: merged_ids (keyword-first, deduped, up to 2x limit)
Tool->>FS: uid, merged_ids
FS-->>Tool: conversations_data
Tool-->>LLM: formatted conversations string
Reviews (1): Last reviewed commit: "test(backend): cover hybrid conversation..." | Re-trigger Greptile |
| keyword_ids = keyword_search_conversation_ids( | ||
| uid=uid, query=query, limit=limit, start_date=starts_at, end_date=ends_at | ||
| ) | ||
| vector_ids = vector_db.query_vectors(query=query, uid=uid, starts_at=starts_at, ends_at=ends_at, k=limit) | ||
| conversation_ids = merge_conversation_search_ids(keyword_ids, vector_ids) |
There was a problem hiding this comment.
Merged result set can silently exceed
limit
Both keyword and vector search independently fetch up to limit results. After merge_conversation_search_ids, conversation_ids can contain up to 2 * limit unique entries — all of which are fetched from Firestore and passed verbatim into the LLM context. With limit=5 (the function default) this could double the context consumed; at limit=20 that's up to 40 conversations fed to the model. There is no trim step between the merge and the Firestore fetch (get_conversations_by_id). The same issue exists at the parallel call site in tool_services/conversations.py at line 185-189.
Bug
#5072 — asking AI Chat "when did I talk to Steph?" returns nothing, even when the conversation exists with the name clearly in its summary. The user can see the conversation in the feed and the app's search bar would find it, but chat cannot.
Root cause
Both chat retrieval paths are vector-search-only:
search_conversations_tool(agentic chat) →vector_db.query_vectors(Pinecone)search_conversations_text(tool_services, desktop/web REST + mobile LangChain) → samePinecone always returns the k nearest neighbors regardless of relevance, and embeddings rank proper names poorly — so a name query returns k semantically-near (wrong) conversations and the right one never surfaces. The existing Typesense keyword search (
utils/conversations/search.py,query_by: structured.overview, structured.title) that powers the app's search bar would match the name literally, but chat never calls it.(The issue's suggested fix — indexing speakers/transcripts in Typesense — requires Firestore→Typesense extension schema changes, infra-side; verified against the live collection schema that only
structured.*fields are indexed. This PR is the in-code fix that resolves the reported failure: names that appear in titles/overviews — which conversation summaries normally include — become findable by chat.)Fix
Hybrid retrieval at both call sites:
keyword_search_conversation_ids()— wraps the existing Typesense search, returns ids only, fail-open (any Typesense error →[]→ exact previous vector-only behavior).merge_conversation_search_ids()— keyword hits first (exact text matches, sorted newest-first), then vector hits, deduplicated.query_byfields already used in prod by/v1/conversations/search), so no schema risk. Locked conversations are already excluded by both halves; keyword search excludes discarded.Tests
tests/unit/test_conversation_hybrid_search.py(registered intest.sh): merge ordering/dedup/non-mutation, id extraction, fail-open on search error, filter passthrough (incl.include_discarded=False), plus structural guards that both call sites keep the hybrid path. Helper logic verified locally via stdlib harness (pytest not installed locally; CI runs the suite). black + lint_async_blockers clean. UNVERIFIED at runtime against a live chat session.Fixes #5072
🤖 automated by hourly watchdog; opened for review, not merged.
🤖 Generated with Claude Code