This guide explains how to use the RAG (Retrieval-Augmented Generation) indexing and similarity search functionality in saigen.
The RAG system provides semantic search capabilities for:
- Repository packages: Search for similar packages across different package managers
- Existing saidata files: Find similar software definitions to use as examples
- Context building: Automatically gather relevant information for LLM-based generation
RAG functionality requires additional dependencies:
pip install saigen[rag]This installs:
sentence-transformers: For generating embeddingsfaiss-cpu: For efficient similarity searchnumpy: For numerical operations
saigen index statusShows the current state of RAG indices, including:
- Package index availability and count
- Saidata index availability and count
- Embedding model information
- Storage size
# Rebuild all indices
saigen index rebuild
# Rebuild with specific saidata directory
saigen index rebuild --saidata-dir /path/to/saidata
# Rebuild specific repositories only
saigen index rebuild --repositories apt brew
# Force rebuild even if indices exist
saigen index rebuild --forcesaigen index clear# Basic package search
saigen index search "web server"
# Advanced search with parameters
saigen index search "database" --limit 10 --min-score 0.4# Find similar saidata files
saigen index find-saidata "nginx"
# With custom parameters
saigen index find-saidata "docker" --limit 5 --min-score 0.3# Build context for software
saigen index context "web server"
# Target specific providers
saigen index context "database" --providers apt brew --max-packages 5The system extracts packages from the repository cache and creates semantic embeddings:
# Packages are indexed with their metadata
package_text = f"{name} {description} category: {category} tags: {tags} repository: {repository}"Existing saidata files are indexed to provide examples:
# Saidata is indexed with comprehensive metadata
saidata_text = f"{name} {description} category: {category} providers: {providers} packages: {package_names}"Uses sentence transformers to find semantically similar items:
- Model:
all-MiniLM-L6-v2(lightweight, fast) - Similarity: Cosine similarity with configurable thresholds
- Storage: FAISS indices for efficient search
Combines multiple sources for comprehensive context:
- Similar repository packages
- Similar existing saidata files
- Default sample saidata files
- Provider-specific filtering
RAG settings can be configured in your saigen config:
rag:
enabled: true
index_dir: "~/.saigen/rag_index"
model_name: "all-MiniLM-L6-v2"
use_default_samples: true
max_sample_examples: 3
default_samples_directory: "saigen/docs/examples/saidata_samples"The RAG system automatically enhances saidata generation by:
- Finding similar packages in repositories for accurate naming
- Providing examples from existing saidata files
- Building context that gets injected into LLM prompts
- Improving accuracy through retrieval-augmented generation
- First run: Downloads the embedding model (~90MB)
- Indexing: Processes packages/files in batches for memory efficiency
- Search: Sub-second response times for typical queries
- Storage: Indices are cached on disk for persistence
RAG functionality is not available. Install with: pip install saigen[rag]
Solution: Install the RAG dependencies as shown above.
No repository data found. Run 'saigen repositories update' first.
Solution: Update repository cache before indexing:
saigen repositories updateIf the embedding model fails to download, try:
# Clear cache and retry
rm -rf ~/.cache/huggingface/
saigen index rebuild# 1. Update repository cache
saigen repositories update
# 2. Rebuild RAG indices
saigen index rebuild --saidata-dir saidata
# 3. Check status
saigen index status
# 4. Search for similar packages
saigen index search "web server"
# 5. Find similar saidata
saigen index find-saidata "nginx"
# 6. Build context for generation
saigen index context "database server" --providers apt dnfThe RAG system automatically enhances generation:
# This will use RAG context if available
saigen generate nginx --providers apt dnfThe generation process will:
- Search for similar packages named "nginx"
- Find existing nginx saidata files
- Build comprehensive context
- Inject context into LLM prompts
- Generate more accurate saidata