vector search - #388
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
There was a problem hiding this comment.
Code Review
This pull request introduces AI embedding generation and caching capabilities. It adds a new EMBEDDING type to the GraphQL schema, implements a createEmbedding utility using Google Vertex AI with support for media chunking, and includes comprehensive tests. Feedback focuses on a breaking change in the createAIResponse utility that affects existing callers, the lack of handling for concurrent 'LOADING' states which could lead to redundant API calls, and opportunities to improve performance by parallelizing media chunk processing and reusing AI clients. Additionally, the AIEmbedding GraphQL type should include the text field to expose error messages.
| if ( | ||
| cached && | ||
| cached.status === 'SUCCESS' && | ||
| Array.isArray(cached.embeddings) && | ||
| cached.embeddings.length > 0 | ||
| ) { | ||
| return cached.embeddings as EmbeddingChunk[]; | ||
| } |
There was a problem hiding this comment.
The current logic only returns cached embeddings if the status is SUCCESS. If an embedding is currently being generated (status: 'LOADING'), this code will proceed to call createAIResponse, which likely creates a duplicate loading record and starts a redundant generation process. It should instead wait for the existing process to complete.
| fields: { | ||
| ...commonAiResponseFields, | ||
| }, |
There was a problem hiding this comment.
770f044 to
cbfc471
Compare
664a2db to
bcf2737
Compare
b88be5e to
0e01635
Compare
366b8d2 to
299be47
Compare
a42a369 to
d6ec108
Compare
Add dense-vector (kNN) retrieval to ListArticles/ListReplies, opt-in via the `embedding` similarity filter. kNN narrows the candidate set and the existing BM25 / perceptual-hash scoring ranks the results. - Embed articles and replies on create; backfill script for old docs. - Audio/video embed as a single vector capped at 80s (no duration probe). - Media queries reuse the doc-side embedding by content hash, else fetch bytes from the query URL and embed — search never persists to GCS, so no orphan files. - All Gemini calls (embeddings + transcription) use the Developer API and feed media via the Files API; Vertex AI is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
感謝這個 PR,我把 41 個檔案完整看過一輪了,混合搜尋的整體方向沒問題,mapping 也跟 cofacts/rumors-db#78 對得上(那邊我已經留了 review)。 不過在進入細部 review 之前,想先請你把它拆成 stacked PR。GitHub 的 stacked pull requests(說明)剛進 public preview,這個 PR 剛好是很適合的案子。 為什麼想拆這個 PR 目前夾了三類彼此獨立的變更,其中一類會直接影響另外兩類的驗證基準:
另外 建議的三層
好消息:現在拆是零衝突
實務上最省事的做法是反向操作:從現在這個分支開一份,把要拆走的檔案 兩個歸屬要決定的東西
另外幾個小提醒
拆完之後我會針對每一層分別留 review。先講兩個已經確定的方向,讓你在整理 PR-3 時可以一起處理:
辛苦了 🙏 Generated by Claude Code |
混合搜尋(kNN 檢索 + BM25 排序)使用說明
如何啟用
在
ListArticles/ListReplies的filter加上embedding欄位:embedding→ 純 BM25(預設,完全向後相容)。embedding是一個Float,直接給門檻值即可,不是物件。範例
文字查詢