Skip to main content

Context & RAG System

NikCLI’s Context & RAG (Retrieval-Augmented Generation) system provides intelligent workspace understanding by combining semantic search, vector embeddings, and workspace analysis. This enables AI agents to access relevant code context efficiently, reducing token usage while improving response accuracy.

Architecture Overview

The Context & RAG system consists of several integrated components:

Core Components

1. Unified RAG System

The central orchestrator combining multiple search strategies:
  • Vector Search: Semantic similarity using embeddings
  • Workspace Analysis: Local file analysis and importance scoring
  • BM25 Search: Keyword-based sparse search for precise matching
  • Hybrid Mode: Combines all strategies for optimal results

2. Semantic Search Engine

Advanced query understanding with:
  • Intent detection (code search, explanation, debugging, etc.)
  • Entity extraction (functions, classes, files, technologies)
  • Query expansion with synonyms and related concepts
  • Multi-dimensional relevance scoring

3. Vector Store Abstraction

Unified interface supporting multiple vector databases:
  • ChromaDB: Local or cloud vector storage
  • Upstash Vector: Serverless vector database with Redis fallback
  • Local Filesystem: Zero-configuration fallback option
  • Automatic health monitoring and failover

4. Workspace Context Manager

Intelligent workspace analysis:
  • File filtering with gitignore support
  • Language and framework detection
  • Importance scoring based on file content and location
  • Real-time change detection

Key Features

Intelligent File Filtering

The system automatically filters files to index only relevant code:

Smart Chunking

Code and documentation are intelligently chunked to preserve context: Code Chunking:
  • Keeps functions and classes together
  • Preserves logical block boundaries
  • Smart overlap for context continuity
  • Language-aware splitting
Markdown Chunking:
  • Splits by header hierarchy
  • Maintains document structure
  • Preserves cross-references

Token-Aware Optimization

Results are optimized for AI context windows:

Search Strategies

Semantic similarity using embeddings:
Best for:
  • Conceptual queries
  • Natural language questions
  • Understanding intent
Local file analysis and keyword matching:
Best for:
  • File discovery
  • Quick local searches
  • Zero external dependencies
Statistical keyword matching:
Best for:
  • Exact keyword matching
  • Technical term searches
  • Complementing semantic search
Combines all strategies for optimal results:

Configuration

Environment Variables

Programmatic Configuration

Usage Examples

Project Analysis

Performance Monitoring

Get Statistics

Performance Report

Best Practices

1. Optimize Indexing Costs

2. Use Appropriate Search Strategy

3. Leverage Caching

4. Monitor Performance

Limitations

File Size Limits

Vector Database Quotas

Search Accuracy

Troubleshooting

Vector DB Connection Issues

High Latency

Cache Management

Next Steps

Workspace Indexing

Learn how NikCLI analyzes and indexes your workspace

Semantic Search

Understand advanced semantic search capabilities

Embeddings

Configure embedding providers and models

Cache System

Optimize performance with intelligent caching