Skip to content

feat(db): IVFFlat index on episodes.embedding [STORY-014]#13

Merged
khoks merged 1 commit intomainfrom
story/014-pgvector-index
Apr 26, 2026
Merged

feat(db): IVFFlat index on episodes.embedding [STORY-014]#13
khoks merged 1 commit intomainfrom
story/014-pgvector-index

Conversation

@khoks
Copy link
Copy Markdown
Owner

@khoks khoks commented Apr 26, 2026

Summary

  • Adds the cosine-distance IVFFlat index that EPIC-014 (RAG / agent memory) will need to build nearest-neighbour queries on top of. Declared in the Drizzle schema (so drizzle-kit owns it) and migrated as 0001_clammy_sir_ram.sql.
  • Cosine ops (vector_cosine_ops) because OpenAI text-embedding-3-* and Voyage voyage-3 return L2-normalised vectors. lists=100 is a sensible cold-start default — the index is mostly useless on an empty table; REINDEX after the first batch of episodes lands.
  • Adds 1 introspection unit test asserting the index exists with method: "ivfflat".
  • Closes STORY-014. Schema-level pgvector work is now complete; retrieval logic comes in v1 under EPIC-014.

Test plan

  • pnpm typecheck — clean.
  • pnpm lint — clean.
  • pnpm test — 20 schema tests pass (was 19; added the IVFFlat index assertion).
  • pnpm format:check — clean.
  • pnpm --filter @learnpro/db db:generate produces a 1-line CREATE INDEX IF NOT EXISTS ... USING ivfflat ... migration.
  • End-to-end migration apply against real Postgres: deferred to STORY-005 (auth shell / smoke harness).

🤖 Generated with Claude Code

Adds the cosine-distance IVFFlat index that EPIC-014 (RAG / agent memory)
will need to build nearest-neighbour queries on top of. Declared in the
Drizzle schema (so drizzle-kit owns it) and migrated as 0001_clammy_sir_ram.

Cosine ops because OpenAI text-embedding-3-* and Voyage voyage-3 return
L2-normalised vectors. lists=100 is a sensible cold-start default — the
index is mostly useless on an empty table; REINDEX after the first batch
of episodes lands.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@khoks khoks merged commit 5855a59 into main Apr 26, 2026
1 check passed
@khoks khoks deleted the story/014-pgvector-index branch April 26, 2026 20:46
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