Skip to content

Minimal CLI text vault with semantic search using Google Gemini embeddings. Prevents AI agent rot through hierarchical memory management.

License

Notifications You must be signed in to change notification settings

0xmilon/textvolt

Repository files navigation

Text Volt

Minimal CLI text vault with hierarchical memory management to prevent AI agent rot.

License: MIT Python 3.11+

Built by @milonspace

Text Volt is a production-grade command-line tool for storing and searching text using Google Gemini embeddings. It implements a three-tier memory system (working/warm/cold) to prevent memory overload and maintain agent performance over time.

✨ Features

  • πŸ” Semantic Search - Vector-based similarity search using cosine similarity
  • πŸ’Ύ Smart Caching - Automatic embedding cache prevents redundant API calls
  • 🚫 Duplicate Prevention - SHA256 hash-based deduplication ensures unique entries
  • 🧠 Hierarchical Memory - Three-tier memory system (working/warm/cold) prevents agent rot
  • πŸ”„ Auto Consolidation - Automatic tier migration based on access patterns
  • πŸ” Secure Config - Environment-based API key management
  • ⚑ Minimal CLI - Clean, intuitive interface with short aliases (a, s, l, d)
  • πŸ“₯ Stdin Support - Pipe text directly into the vault

πŸš€ Quick Start

Installation

# Install with UV
uv sync

# Or use UVX to run from anywhere
uvx textvolt --help

Configuration

  1. Copy the example environment file:
cp .env.example .env
  1. Add your Gemini API key:
# Edit .env and add your API key
GEMINI_API_KEY=your_api_key_here

Usage

# Add text
textvolt a "Your text here"

# Search semantically
textvolt s "query"

# List entries
textvolt l

# Delete entry
textvolt d 1

πŸ“– Commands

Command Alias Description
add a Add text to vault
search s Semantic search
list l List entries
delete d, rm Delete entry
consolidate - Consolidate memory tiers
validate - Validate memory integrity
reset - Reset vault (with confirmation)

Options

  • -q, --quiet - Quiet mode (minimal output, useful for scripting)
  • -n, --limit <N> - Limit number of results (default: 5 for search, 10 for list)
  • -t, --tier <tier> - Filter by memory tier (working/warm/cold)
  • -m, --meta <json> - Add JSON metadata to entry

πŸ’‘ Examples

Basic Workflow

# Add multiple entries
textvolt a "Project idea: Build a CLI tool"
textvolt a "Meeting notes: Discussed API design"
textvolt a "Code snippet: Fast vector search"

# Search for related content
textvolt s "API"                    # Finds API-related entries
textvolt s "code" -n 3              # Top 3 code-related entries

# List recent entries
textvolt l                          # Last 10 entries
textvolt l -n 20                    # Last 20 entries
textvolt l -t working               # Only working memory

# Clean up
textvolt d 5                        # Delete entry #5
textvolt consolidate                # Optimize memory tiers

Piping Text

# From file
cat notes.txt | textvolt add

# From command output
git log --oneline -5 | textvolt add

# Quiet mode for scripting
echo "text" | textvolt add -q

Using UVX (from anywhere)

uvx textvolt add "Your text here"
uvx textvolt s "query"
uvx textvolt l

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      CLI Interface (Minimal TUI)        β”‚
β”‚  Commands: a/s/l/d + stdin support      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Memory Manager (Hierarchical)      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚ Working  β”‚ β”‚   Warm   β”‚ β”‚  Cold   β”‚ β”‚
β”‚  β”‚ (Recent) β”‚ β”‚ (Active) β”‚ β”‚(Archive)β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Vector Store (SQLite + numpy)        β”‚
β”‚  - Embeddings storage (JSON)            β”‚
β”‚  - Hash-based deduplication            β”‚
β”‚  - Semantic search (cosine)             β”‚
β”‚  - Metadata tracking                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Gemini Embedding Service              β”‚
β”‚   - Text-based caching                  β”‚
β”‚   - Secure API key management           β”‚
β”‚   - Error handling & retries            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ›‘οΈ Preventing AI Agent Rot

Text Volt implements several strategies to prevent agent degradation:

  1. Hierarchical Memory - Three-tier system prevents memory overload
  2. Automatic Consolidation - Moves entries between tiers based on access patterns
  3. Access Tracking - Tracks access counts and timestamps for relevance
  4. Memory Validation - Integrity checks detect corruption
  5. Stateless Operations - Idempotent operations reduce state-related errors
  6. Size Limits - Configurable limits for each memory tier
  7. Duplicate Prevention - Hash-based deduplication prevents redundant entries
  8. Embedding Cache - Reuses embeddings for duplicate text, saving API calls

βš™οΈ Configuration

All configuration is done through environment variables in .env:

Variable Description Default
GEMINI_API_KEY Your Google Gemini API key (required) -
TEXTVOLT_VAULT_PATH Path to SQLite database ~/.textvolt/vault.db
TEXTVOLT_WORKING_SIZE Maximum entries in working memory 100
TEXTVOLT_WARM_SIZE Maximum entries in warm memory 1000
TEXTVOLT_EMBEDDING_MODEL Embedding model name gemini-embedding-exp-03-07

See .env.example for a template.

πŸ“ Project Structure

textvolt/
β”œβ”€β”€ pyproject.toml          # UV project configuration
β”œβ”€β”€ .env.example            # Environment template
β”œβ”€β”€ textvolt/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ config.py          # Settings & configuration
β”‚   β”œβ”€β”€ embedding.py       # Gemini embedding service
β”‚   β”œβ”€β”€ vault.py           # Vector storage & search
β”‚   β”œβ”€β”€ memory.py          # Memory management
β”‚   └── cli.py             # CLI interface
└── README.md              # This file

🎯 Design Decisions

  1. SQLite over PostgreSQL - Minimal dependency, portable, sufficient for CLI tool
  2. JSON storage for embeddings - Simple, no additional vector extensions needed
  3. Cosine similarity - Standard vector similarity metric, implemented in pure NumPy
  4. Hierarchical memory - Three-tier system prevents memory overload and agent rot
  5. Stateless design - Each operation is independent, reducing state-related errors
  6. Hash-based deduplication - SHA256 hashing for fast duplicate detection
  7. Text-based caching - Automatic embedding cache reduces API costs
  8. Minimal CLI - Clean, intuitive interface with short aliases for zero friction
  9. UV/UVX - Fast, modern Python package management and execution

πŸ”’ Security

  • API keys stored in .env file (never committed to git)
  • No hardcoded credentials in source code
  • Environment-based configuration for all sensitive data
  • SHA256 hashing for duplicate detection (no plaintext comparison)

⚑ Performance

  • Caching - Duplicate text uses cached embeddings (no API call)
  • Deduplication - Hash-based lookup is O(1) for duplicate detection
  • Search - Cosine similarity with NumPy (efficient for <10K entries)
  • Memory - Automatic consolidation prevents database bloat

πŸ“„ License

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

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

🎨 Design Principles

This project follows YAGNI, KISS, and DRY principles for maintainable architecture.

About

Minimal CLI text vault with semantic search using Google Gemini embeddings. Prevents AI agent rot through hierarchical memory management.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages