Documentation
¶
Overview ¶
Package rag constants.go defines shared constants, types, and configuration for RAG operations.
Contents:
- Source type constants (SourceTypeConversation, SourceTypeFile, SourceTypeSystem)
- Table schema constants for documents table
- NewDocStoreConfig factory for consistent DocStore configuration
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:
- System knowledge indexing (IndexSystemKnowledge function)
- Integration with Genkit's PostgreSQL DocStore
Architecture ¶
System Knowledge Docs
|
v
IndexSystemKnowledge()
|
v
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 ¶
IndexSystemKnowledge: Package-level function that indexes built-in knowledge:
- Go best practices and coding standards
- Agent capabilities and tool usage
- Architecture principles
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. IndexSystemKnowledge is called once at startup.
Package rag provides RAG (Retrieval-Augmented Generation) functionality. This file implements IndexSystemKnowledge for managing built-in knowledge about Agent capabilities, Golang best practices, and architecture principles.
Index ¶
Constants ¶
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.
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.
Variables ¶
This section is empty.
Functions ¶
func DeleteByIDs ¶
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 IndexSystemKnowledge ¶
func IndexSystemKnowledge(ctx context.Context, store *postgresql.DocStore, pool *pgxpool.Pool) (int, error)
IndexSystemKnowledge indexes all built-in system knowledge documents. Called once during application startup.
Features:
- Uses fixed document IDs (e.g., "system:golang-errors")
- UPSERT behavior via delete-then-insert (Genkit DocStore doesn't support UPSERT)
- Returns count of successfully indexed documents
Returns: (indexedCount, error) Error: returns error if indexing fails
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.
Types ¶
This section is empty.