rag

package
v0.0.0-...-d8a54d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package rag implements Retrieval-Augmented Generation (RAG) for Koopa.

The rag package provides document indexing and knowledge base integration for LLM applications. It uses Firebase Genkit's PostgreSQL plugin for vector storage and retrieval.

Overview

RAG enhances LLM responses by augmenting prompts with relevant context from a knowledge base. The rag package manages:

  • DocStore configuration for vector storage
  • Integration with Genkit's PostgreSQL DocStore

Architecture

Genkit PostgreSQL DocStore
     |
     +-- Vector embedding (via AI Embedder)
     +-- Vector storage (PostgreSQL + pgvector)
     |
     v
Genkit Retriever (ai.Retriever interface)
     |
     +-- source_type filtering (conversation, file, system)
     +-- Semantic search
     |
     v
LLM (with augmented context)

Key Components

NewDocStoreConfig: Creates configuration for the Genkit PostgreSQL DocStore.

DeleteByIDs: Removes documents by ID for UPSERT emulation.

Source Types

Documents are categorized by source_type:

  • SourceTypeConversation: Chat message history
  • SourceTypeFile: Indexed file content
  • SourceTypeSystem: Built-in system knowledge

Thread Safety

DocStore handles concurrent operations safely.

Index

Constants

View Source
const (
	// SourceTypeConversation represents chat message history.
	SourceTypeConversation = "conversation"

	// SourceTypeFile represents indexed file content.
	SourceTypeFile = "file"

	// SourceTypeSystem represents system knowledge (best practices, coding standards).
	SourceTypeSystem = "system"
)

Source type constants for knowledge documents. These define the categories of knowledge stored in the system.

View Source
const (
	DocumentsTableName    = "documents"
	DocumentsSchemaName   = "public"
	DocumentsIDColumn     = "id"
	DocumentsContentCol   = "content"
	DocumentsEmbeddingCol = "embedding"
	DocumentsMetadataCol  = "metadata"
)

Table schema constants for Genkit PostgreSQL plugin. These match the documents table in db/migrations.

View Source
const VectorDimension int32 = 768

VectorDimension is the vector dimension used by the pgvector schema. Must match the documents table migration: embedding vector(768). gemini-embedding-001 produces 3072 dimensions by default; we truncate to 768 via OutputDimensionality in EmbedderOptions.

Variables

This section is empty.

Functions

func DeleteByIDs

func DeleteByIDs(ctx context.Context, pool *pgxpool.Pool, ids []string) error

DeleteByIDs deletes documents by their IDs. Used for UPSERT emulation since Genkit DocStore only supports INSERT. Exported for testing (fuzz tests in rag_test package).

func NewDocStoreConfig

func NewDocStoreConfig(embedder ai.Embedder) *postgresql.Config

NewDocStoreConfig creates a postgresql.Config for the documents table. This factory ensures consistent configuration across production and tests. EmbedderOptions sets OutputDimensionality to match the pgvector schema.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL