gcloud-lab/apps/base/customer1/hermes-db/rag-db-init.sql
Hermes Agent 4df7450461 feat(customer1): add pgvector RAG knowledge base with embedding service
- Custom PostgreSQL 15.2 image with pgvector 0.8.0 extension
- Updated pg-cluster-hermes.yaml: custom image, sharedPreloadLibraries, maintenance_work_mem
- RAG schema: documents table with vector(768) embeddings + HNSW index
- RAG init job: ConfigMap + Job to apply schema to agent_memory db
- Embedding service: FastAPI with nomic-embed-text-v1.5
  - OpenAI-compatible /v1/embeddings endpoint
  - Deployment (1 replica, 2Gi-4Gi memory) + Service manifests
- Updated kustomization.yaml to include new resources
2026-05-24 20:31:59 +00:00

35 lines
1.1 KiB
PL/PgSQL

-- RAG knowledge base initialization SQL
-- Applied to agent_memory database via CNPG Database resource
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE IF NOT EXISTS documents (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
metadata JSONB DEFAULT '{}'::jsonb,
embedding vector(768),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_documents_embedding_hnsw
ON documents USING hnsw (embedding vector_cosine_ops);
CREATE INDEX IF NOT EXISTS idx_documents_content
ON documents USING gin (to_tsvector('english', content));
CREATE INDEX IF NOT EXISTS idx_documents_metadata
ON documents USING gin (metadata);
CREATE OR REPLACE FUNCTION update_documents_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_documents_updated_at
BEFORE UPDATE ON documents
FOR EACH ROW
EXECUTE FUNCTION update_documents_updated_at();