28 lines
1.2 KiB
SQL
28 lines
1.2 KiB
SQL
-- =====================================================================
|
|
-- knowledge service — 0001_init.sql
|
|
-- Database-per-service: owns `documents`, the pgvector-backed RAG
|
|
-- index. Requires PostgreSQL 15+ with the pgvector extension available
|
|
-- (see deploy — the knowledge database uses the pgvector/pgvector
|
|
-- Docker image rather than plain postgres).
|
|
-- =====================================================================
|
|
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
CREATE TABLE IF NOT EXISTS documents (
|
|
id BIGSERIAL PRIMARY KEY,
|
|
file_path TEXT NOT NULL,
|
|
chunk_index INT NOT NULL DEFAULT 0,
|
|
content TEXT NOT NULL,
|
|
content_hash TEXT NOT NULL, -- sha256 of `content`, used to skip re-embedding unchanged chunks
|
|
embedding vector(768) NOT NULL, -- 768 = nomic-embed-text's output size; see domain.EmbeddingDim
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
UNIQUE (file_path, chunk_index)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS documents_embedding_hnsw_idx
|
|
ON documents USING hnsw (embedding vector_cosine_ops);
|
|
|
|
CREATE INDEX IF NOT EXISTS documents_file_path_idx
|
|
ON documents (file_path);
|