Sign inSign up

makuykendall/contextlite

By makuykendall

โ€ขUpdated about 1 year ago

Lightning fast context engine for AI apps **100x faster** than vector RAG fully local private.

Image
Machine learning & AI
Data science
Databases & storage
0

2.6K

makuykendall/contextlite repository overview

โ ContextLite

โ SMT-optimized context sidecar for AI systems - 10,000x faster than vector databases 100% local, zero dependencies, privacy-first.

ContextLite is a Go-based context assembly engine that uses Satisfiability Modulo Theories (SMT) optimization to select the perfect set of documents for AI context windows. Built for speed, privacy, and local operation.

โ ๐Ÿš€ Quick Start

# Build main contextlite binary
make build

# Build SOTA evaluation tool
make build-sota

# Build both binaries
make build-all-local

# Or with custom config
./build/contextlite -config configs/custom.yaml

# Run SOTA evaluation
./build/sota-eval

# Development mode with hot reload
make dev

The server starts on http://localhost:8080 by default.

โ โœจ Key Features

  • SMT-Optimized Selection: Uses constraint satisfaction for mathematically optimal document selection
  • 7D Feature Scoring: Multi-dimensional relevance, recency, entanglement, prior, authority, specificity, uncertainty
  • Per-Workspace Calibration: Adaptive weights that learn from your usage patterns
  • Multi-Level Caching: L1 memory, L2 SQLite, L3 quantum snapshots with intelligent invalidation
  • Zero Dependencies: Pure Go with embedded SQLite, no external services required
  • Sub-Second Performance: p50 โ‰ค300ms, p95 โ‰ค600ms uncached; cached โ‰ค30ms
  • Local Privacy: All data stays on your machine, no cloud dependencies

โ ๐Ÿ—๏ธ Repository Structure

contextlite/
โ”œโ”€โ”€ cmd/                       # Executable applications
โ”‚   โ”œโ”€โ”€ contextlite/           # HTTP sidecar server
โ”‚   โ””โ”€โ”€ sota-eval/             # SOTA comparison CLI tool
โ”œโ”€โ”€ internal/                  # Private implementation
โ”‚   โ”œโ”€โ”€ smt/                   # SMT solver integration (Z3)
โ”‚   โ”œโ”€โ”€ storage/               # SQLite + FTS5 storage layer
โ”‚   โ”œโ”€โ”€ features/              # 7D feature extraction & scoring
โ”‚   โ”œโ”€โ”€ pipeline/              # Main assembly pipeline
โ”‚   โ”œโ”€โ”€ cache/                 # Multi-level caching system
โ”‚   โ”œโ”€โ”€ api/                   # HTTP API handlers
โ”‚   โ””โ”€โ”€ evaluation/            # SOTA evaluation framework
โ”œโ”€โ”€ pkg/                       # Public API packages
โ”‚   โ”œโ”€โ”€ types/                 # Core data structures
โ”‚   โ”œโ”€โ”€ config/                # Configuration management
โ”‚   โ””โ”€โ”€ tokens/                # Token estimation utilities
โ”œโ”€โ”€ docs/                      # Technical documentation
โ”œโ”€โ”€ archive/                   # Historical development artifacts
โ”œโ”€โ”€ test/                      # Integration tests
โ”œโ”€โ”€ configs/                   # Default configuration files
โ””โ”€โ”€ migrations/                # Database schema migrations

โ ๐Ÿ”ง Configuration

See configs/default.yaml for full configuration options:

# Core SMT optimization settings
smt:
  solver_timeout_ms: 250        # Hard timeout for SMT solver
  max_opt_gap: 0.05            # 5% optimality gap acceptable
  objective_style: "weighted-sum"  # weighted-sum | lexicographic | epsilon-constraint

# 7D Feature weights (adaptive per workspace)
weights:
  relevance: 0.30              # Query match strength
  recency: 0.20                # Time-based decay
  entanglement: 0.15           # Cross-document concept density
  prior: 0.15                  # Historical selection likelihood
  authority: 0.10              # Document importance
  specificity: 0.05            # Query-document topic alignment
  uncertainty: 0.05            # Score variance (subtracted)

โ ๐Ÿ“ก HTTP API

โ Context Assembly
curl -X POST http://localhost:8080/api/v1/context/assemble \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How does user authentication work?",
    "max_tokens": 4000,
    "max_documents": 10,
    "use_smt": true,
    "workspace_path": "/path/to/project"
  }'
โ Document Management
# Add document
curl -X POST http://localhost:8080/api/v1/documents \
  -H "Content-Type: application/json" \
  -d '{
    "content": "...",
    "path": "src/auth.go",
    "language": "go"
  }'

# Search documents
curl "http://localhost:8080/api/v1/documents/search?q=authentication&limit=20"
โ Weight Management
# Get workspace weights
curl "http://localhost:8080/api/v1/weights?workspace=/path/to/project"

# Update weights based on feedback
curl -X POST http://localhost:8080/api/v1/weights/update \
  -H "Content-Type: application/json" \
  -d '{
    "workspace_path": "/path/to/project",
    "accepted_docs": ["doc1", "doc2"],
    "rejected_docs": ["doc3"]
  }'

โ ๐Ÿ“ˆ Development Status

โ โœ… Completed Features
  • SMT Integration: Z3 solver integration with multiple optimization strategies
  • 7D Feature System: Complete implementation of all feature dimensions
  • SOTA Evaluation Framework: Comprehensive evaluation harness with Recall@k, nDCG@k, MAP, MRR
  • Multi-level Caching: L1 memory, L2 SQLite with intelligent invalidation
  • HTTP API: Complete REST API for context assembly and document management
  • Configuration System: Flexible YAML-based configuration with workspace-specific weights
โ ๐Ÿ“‹ Documentation

โ ๐Ÿงฎ SMT Optimization

ContextLite uses three SMT optimization formulations:

โ 1. Weighted-Sum Scalarization (Default)

Balances all 7D features with learned workspace-specific weights:

maximize: ฮฃ(ฮฑโ‚ยทRel + ฮฑโ‚‚ยทRec + ฮฑโ‚ƒยทEnt + ฮฑโ‚„ยทPrior + ฮฑโ‚…ยทAuth + ฮฑโ‚†ยทSpec - ฮฑโ‚‡ยทUnc)
subject to: token_budget, max_documents, coherence_constraints
โ 2. Lexicographic Priorities

Strict priority ordering (relevance first, then recency, etc.):

objective_style: "lexicographic"
โ 3. ฮต-Constraint Method

Optimize primary objective with secondary constraints:

objective_style: "epsilon-constraint"

โ ๐Ÿ“Š SOTA Evaluation

ContextLite includes a comprehensive evaluation framework comparing against state-of-the-art retrieval systems:

# Run full SOTA comparison
./build/sota-eval

# With custom parameters
./build/sota-eval -queries 1000 -docs 100 -verbose

Evaluation Metrics:

  • Recall@k: Fraction of relevant documents retrieved in top-k results
  • nDCG@k: Normalized Discounted Cumulative Gain (position-aware relevance)
  • MAP: Mean Average Precision across all queries
  • MRR: Mean Reciprocal Rank of first relevant document

Baseline Comparisons:

  • BM25 (Elasticsearch/Lucene standard)
  • TF-IDF with cosine similarity
  • Hybrid semantic + lexical retrieval
  • Random baseline for statistical significance

See docs/GOLDEN_RECORD_STEP5.mdโ  for current evaluation status and identified areas for improvement.

โ ๐Ÿƒโ€โ™‚๏ธ Performance

Benchmarked on NVMe SSD, 100k documents, K=200 candidates:

Operationp50p95p99
Cached Query15ms30ms45ms
Cold Query180ms350ms500ms
SMT Solve50ms150ms250ms
Feature Extract25ms80ms120ms

โ ๐Ÿ“Š Development

# Install dependencies
make deps

# Build main binary
make build

# Build SOTA evaluation tool
make build-sota

# Build both binaries locally
make build-all-local

# Build for all platforms
make build-all

# Run tests
make test

# Run with coverage
make coverage

# Run benchmarks  
make bench

# Code quality checks
make check

# Development with hot reload
make dev

# Clean build artifacts
make clean

โ ๐Ÿณ Docker

# Build image
make docker-build

# Run container
make docker-run

โ ๐Ÿ“ˆ Monitoring

The API provides comprehensive metrics:

# Health check
curl http://localhost:8080/health

# Storage statistics
curl http://localhost:8080/api/v1/storage/info

# SMT solver performance
curl http://localhost:8080/api/v1/smt/stats

# Cache performance
curl http://localhost:8080/api/v1/cache/stats

โ ๐ŸŽฏ Use Cases

  • VS Code Extensions: Drop-in context provider for AI coding assistants
  • Local AI Systems: Ollama, LocalAI, edge deployment context optimization
  • Document Q&A: Intelligent document retrieval for RAG applications
  • Code Analysis: Smart code snippet selection for AI code review
  • Research Tools: Academic paper and document context assembly

โ ๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSEโ  file for details.

โ ๐Ÿ”ฌ Technical Details

For complete implementation details, algorithms, and architecture decisions, see the documentation in the docs/ directory.

โ ๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

โ ๐Ÿ“ž Support

  • Documentation: See the docs/ directory for technical details
  • Issues: Report bugs and feature requests via GitHub Issues
  • Community: Join the discussions for help and feature requests

ContextLite - Making AI context assembly fast, local, and intelligent.


ContextLite - Because context matters, and speed matters more. ๐Ÿš€

Tag summary

Content type

Image

Digest

sha256:e5f649294โ€ฆ

Size

10.4 MB

Last updated

about 1 year ago

docker pull makuykendall/contextlite