Skip to content

feat(knowledge): HNSW vector search optimization#10

Merged
webdevcom01-cell merged 3 commits into
mainfrom
feat/hnsw-vector-search-optimization
Mar 28, 2026
Merged

feat(knowledge): HNSW vector search optimization#10
webdevcom01-cell merged 3 commits into
mainfrom
feat/hnsw-vector-search-optimization

Conversation

@webdevcom01-cell
Copy link
Copy Markdown
Owner

Summary

  • 4 database indexes created on Supabase (HNSW + GIN + filtered B-tree) for ~15-50x faster search
  • Dynamic ef_search tuning — adjusts HNSW search precision per query complexity (40/60/100)
  • Latency metricsvector_query_ms and keyword_query_ms for benchmarking pre/post improvement

Database indexes created (already live on Supabase)

Index Type Table Purpose
kbchunk_embedding_hnsw_idx HNSW (m=16, ef=64) KBChunk Semantic vector search
agentmemory_embedding_hnsw_idx HNSW (m=16, ef=64) AgentMemory Memory semantic search
kbchunk_content_fts_idx GIN KBChunk Full-text keyword search
kbchunk_source_embedding_ready_idx B-tree (filtered) KBChunk Scoped vector queries

Files changed

  • src/lib/knowledge/search.ts — ef_search tuning + latency metrics
  • src/lib/runtime/handlers/memory-read-handler.ts — ef_search for memory lookups
  • CLAUDE.md — documented HNSW index configuration
  • docs/hnsw-implementation-plan.md — full implementation plan

Test plan

  • All 2154 unit tests pass (pnpm precheck)
  • Indexes verified via pg_indexes query on Supabase
  • Monitor kb.search.vector_query_ms metric after deploy for latency improvement

🤖 Generated with Claude Code

webdevcom01-cell and others added 3 commits March 28, 2026 19:59
Prevent Dependabot from auto-creating PRs for major version upgrades
(e.g. Prisma 6→7, eslint 9→10, vitest 3→4). Major bumps require manual
review and code updates before merging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extend major-version ignore rule to GitHub Actions and Docker in addition
to npm. This prevents PRs for Node Alpine upgrades (20→25) and major
GitHub Actions version bumps since we use SHA-pinned actions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uning

- Add HNSW indexes on KBChunk.embedding and AgentMemory.embedding (m=16, ef_construction=64)
- Add GIN index for full-text keyword search on KBChunk.content
- Add filtered B-tree index on KBChunk.sourceId for scoped vector queries
- Implement dynamic SET LOCAL hnsw.ef_search per query complexity (40/60/100)
- Add vector_query_ms and keyword_query_ms latency metrics for benchmarking
- Document HNSW index configuration in CLAUDE.md
- Include full implementation plan in docs/hnsw-implementation-plan.md

Expected improvement: ~15-50x faster semantic search (O(n) seq scan → O(log n) HNSW)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-studio Ready Ready Preview, Comment Mar 28, 2026 9:07pm

Request Review

@webdevcom01-cell webdevcom01-cell merged commit 0fe3ad5 into main Mar 28, 2026
10 checks passed
@webdevcom01-cell webdevcom01-cell deleted the feat/hnsw-vector-search-optimization branch March 29, 2026 22:23
webdevcom01-cell added a commit that referenced this pull request May 24, 2026
Migration 20260604000000: TENANT_DIRECT RLS on ApprovalPolicy.
Pre-auth lookups (loadPolicy, decisions pre-auth) use withAdminBypass —
same pattern as loadDepartment/loadGoal from migrations #4/#5.
CRUD routes use withOrgContext with org ID from loadPolicy result.
checkPolicies gains optional organizationId param; requestApproval wraps
the policy findUnique in withOrgContext.
processTimeouts unchanged — cross-org cron relies on DATABASE_URL BYPASSRLS.
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.

1 participant