Skip to content

feat(ai-partner): client-side retrieval with sqlite-vec (#1451)#1479

Merged
CraigBuckmaster merged 1 commit into
masterfrom
claude/issue-1451-client-retrieval
Apr 17, 2026
Merged

feat(ai-partner): client-side retrieval with sqlite-vec (#1451)#1479
CraigBuckmaster merged 1 commit into
masterfrom
claude/issue-1451-client-retrieval

Conversation

@CraigBuckmaster
Copy link
Copy Markdown
Owner

Closes #1451. Depends conceptually on #1448 and #1450.

Summary

  • New app/src/services/amicus/ service layer implementing the client retrieval pipeline defined in the plan §6.
  • Pipeline: embedQuery() (proxy) → searchByVector() (sqlite-vec MATCH) → rerank() (boosts + diversity) → top-10.
  • Typed errors (AmicusError.EMBED_FAILED | OFFLINE | EXTENSION_NOT_LOADED | PROXY_UNAUTHORIZED) so the UI can choose graceful fallback.

Modules

  • types.tsRetrievedChunk, RetrievalContext, CompressedProfile, ChapterRef, AmicusError
  • embed.ts — single-retry, 5-s timeout, translates proxy status to typed errors
  • vectorSearch.ts — little-endian float32 pack, similarity = 1/(1+distance), join to chunk_text + chunk_metadata
  • rerank.ts — pure boosts: current chapter ×1.5, scholar ×1.1, tradition ×1.05; 2-per-scholar diversity cap; top 10
  • retrieval.ts — orchestrator with per-phase latency timing
  • index.ts — public barrel

Test plan

  • npx tsc --noEmit — 0 errors
  • npx eslint src/services/amicus/ — 0 warnings
  • npx jest --testPathPattern=amicus — 30 tests pass across rerank / vectorSearch / embed / retrieval
  • Full app suite: 3,213 / 3,213 passing
  • EXTENSION_NOT_LOADED, OFFLINE, PROXY_UNAUTHORIZED error paths covered
  • No any types; strict mode passes

Out of scope

https://claude.ai/code/session_01Pht3kzgdvkn81DDfL9SnFe

Implements the Amicus retrieval service layer that embeds a user query,
runs sqlite-vec MATCH against scripture.db, and re-ranks with profile +
context boosts.

New modules under app/src/services/amicus/:
- types.ts       — shared types (RetrievedChunk, RetrievalContext,
                   CompressedProfile, AmicusError + AmicusErrorCode)
- embed.ts       — calls proxy /ai/embed; retries once on 5xx/network;
                   translates proxy 401/402 to PROXY_UNAUTHORIZED,
                   network failure to OFFLINE
- vectorSearch.ts — packVector (little-endian float32), distance→similarity,
                    searchByVector executing the MATCH join on
                    embeddings/chunk_text/chunk_metadata. Throws
                    EXTENSION_NOT_LOADED if sqlite-vec isn't loaded.
- rerank.ts      — pure functions: current-chapter ×1.5, preferred
                   scholars ×1.1, traditions ×1.05, 2-per-scholar
                   diversity cap, top-10
- retrieval.ts   — top-level orchestrator with latency timing
- index.ts       — tiny public barrel

30 Jest tests (4 suites) across the pipeline:
- rerank: boosts, diversity, ordering
- vectorSearch: packing, similarity, error on extension missing
- embed: shape validation, retry, 401/402, offline, timeout
- retrieval: end-to-end with fake fetch + mock DB

All 3213 app tests still pass; tsc --noEmit + eslint 0 warnings.

https://claude.ai/code/session_01Pht3kzgdvkn81DDfL9SnFe
@github-actions
Copy link
Copy Markdown

Test Results

✅ All tests passed

Passed Failed Total
Tests ✅ 3213 ❌ 0 3213
Suites ✅ 430 ❌ 0 430

Coverage

Statements Branches Functions Lines

⏱️ Duration: 61.0s

@CraigBuckmaster CraigBuckmaster merged commit 7aa38ce into master Apr 17, 2026
6 checks passed
@CraigBuckmaster CraigBuckmaster deleted the claude/issue-1451-client-retrieval branch April 17, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai-partner: client-side retrieval with sqlite-vec

2 participants