- 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
45 lines
1.4 KiB
YAML
45 lines
1.4 KiB
YAML
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: rag-init-sql
|
|
namespace: customer1
|
|
data:
|
|
rag-db-init.sql: |
|
|
-- Enable pgvector extension
|
|
CREATE EXTENSION IF NOT EXISTS vector;
|
|
|
|
-- Documents table for RAG knowledge base
|
|
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()
|
|
);
|
|
|
|
-- HNSW index for vector similarity search (cosine distance)
|
|
CREATE INDEX IF NOT EXISTS idx_documents_embedding_hnsw
|
|
ON documents USING hnsw (embedding vector_cosine_ops);
|
|
|
|
-- Full-text search index
|
|
CREATE INDEX IF NOT EXISTS idx_documents_content
|
|
ON documents USING gin (to_tsvector('english', content));
|
|
|
|
-- Metadata filter index
|
|
CREATE INDEX IF NOT EXISTS idx_documents_metadata
|
|
ON documents USING gin (metadata);
|
|
|
|
-- Auto-update updated_at timestamp
|
|
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();
|