-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
29 lines (25 loc) · 1.18 KB
/
Copy pathschema.sql
File metadata and controls
29 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- grounded-rag schema. Run once against a Postgres instance with pgvector installed.
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS documents (
id SERIAL PRIMARY KEY,
source TEXT NOT NULL,
title TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- all-MiniLM-L6-v2 produces 384-dim embeddings.
CREATE TABLE IF NOT EXISTS chunks (
id SERIAL PRIMARY KEY,
document_id INTEGER NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
chunk_index INTEGER NOT NULL,
content TEXT NOT NULL,
embedding vector(384) NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- ponytail: no approximate (ivfflat/hnsw) index. IVFFlat partitions rows
-- into `lists` clusters and only probes one by default — with a small
-- corpus (dozens to low hundreds of chunks) that means most clusters are
-- empty and queries can miss real matches entirely, not just rank them
-- lower. A sequential scan is both exact and fast at this scale. Add an
-- ivfflat or hnsw index once the corpus is large enough that a full scan
-- is actually the bottleneck — pgvector's own docs recommend the same.
CREATE INDEX IF NOT EXISTS idx_chunks_document_id ON chunks(document_id);