feat: add get-related chunk similarity lookup (more-like-this)#397
Merged
feat: add get-related chunk similarity lookup (more-like-this)#397
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
3 tasks
d307a52 to
16d1ca7
Compare
Implements "more-like-this" functionality that seeds a vector similarity search from an existing chunk's stored embedding, bypassing the embedding provider entirely. Adds getRelatedChunks() to src/core/search.ts, a get-related MCP tool, and a `libscope related <chunkId>` CLI command. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Remove unnecessary async from withErrorHandling callback (no await) - Remove unused createTestDb import from test file - Replace unused catch bindings (_err) with bare catch clauses Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
16d1ca7 to
2f0288f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #395
Summary
getRelatedChunks()insrc/core/search.ts— new exported function that fetches a chunk's stored embedding fromchunk_embeddings, runs an ANN vector search via sqlite-vec directly (no embedding provider call), excludes the source document by default, and optionally blends in explicitly linked documents at a boosted scoreget-relatedMCP tool insrc/mcp/server.ts— exposesgetRelatedChunksas an MCP tool with schema fields forchunkId,limit,topic,library,tags,minScore,includeLinkedDocumentsrelated <chunkId>CLI command insrc/cli/index.ts—libscope related <chunkId>with--limit,--topic,--library,--min-score,--tagsoptions; output matchessearchcommand styletests/unit/get-related.test.ts— 9 unit tests covering: chunk-not-found error, no-embedding error, sourceChunk metadata, excludeDocumentId behavior, includeLinkedDocuments SQL logic, minScore filtering, limitKey design decisions
getRelatedChunksis synchronous (matches all other DB functions in this codebase)embedding MATCH ?(sqlite-vec ANN) rather than delegating tosearchDocuments, skipping the embedding provider entirely — fast, offline-capable, and guaranteed to use the same embedding spacevalidateRow/validateRows+ Zod schemas (consistent with existing codebase patterns)includeLinkedDocumentsfetches linked doc chunks via plain SQL and boosts their score to 0.6 so they surface even when below the vector similarity thresholdTest plan
vitest run tests/unit/get-related.test.ts)tsc --noEmit)libscope related <chunkId>with an indexed workspaceget-relatedtool via Claude Desktop / MCP client🤖 Generated with Claude Code