Capsa
A compact, lightweight library for embedding-based document storage and retrieval.
Capsa is a Rust library that implements the retrieval component of RAG (Retrieval-Augmented Generation) systems. It provides a simple API for ingesting documents, generating embeddings, storing them in a vector database, and performing semantic search through natural language queries.
The repository also includes a fully-functional CLI tool for document indexing and semantic search.
How It Works
Capsa uses a standard vector database approach:
- Document Chunking - Documents are split into 128-token chunks with overlap to preserve context
- Embedding Generation - Each chunk is converted to a vector representation using an embedding model (via OpenAI-compatible API)
- Vector Storage - Embeddings are stored in libSQL (Turso's fork of SQLite with vector indexing) for fast similarity search
- Semantic Query - Queries are embedded and matched against stored vectors using cosine similarity
This allows finding relevant content based on semantic meaning rather than exact keyword matches.
Library Usage
Add Capsa to your Cargo.toml:
[]
= "0.1"
Example
use ;
use json;
use SecretString;
async
CLI Tool
Installation
# Optionally install to ~/.cargo/bin
Prerequisites
Capsa requires an embedding service with an OpenAI-compatible API. You have several options:
Option 1: llama.cpp
Option 2: text-embeddings-inference
For GPU/CUDA support:
For CPU only support:
Option 3: Any OpenAI-compatible API (remote or local)
Basic Usage
Index documents:
Query:
Examples
Indexing Documents
Add a PDF document:
================================================================================
================================================================================
================================================================================
================================================================================
Add a YouTube video transcript:
================================================================================
================================================================================
) ()
================================================================================
================================================================================
Semantic Search
Simple query:
$ capsa ask -d -k 1 "What is the transformer architecture?"
================================================================================
DOCUMENT RETRIEVAL SYSTEM
================================================================================
QUERY.....: What is the transformer architecture?
TOP-K.....: 1
INITIALIZING DATABASE CONNECTION... DONE
================================================================================
RECORD 001 DOCID=000001 SIMILARITY= 76.70%
================================================================================
TITLE..: Attention is All you Need
AUTHOR.: Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, �ukasz Kaiser, Illia Polosukhin
SUBJECT: Neural Information Processing Systems http://nips.cc/
FILE...: attention-is-all-you-need.pdf
OFFSET.: 4080-4478 (398 BYTES)
--------------------------------------------------------------------------------
CONTENT:
--------------------------------------------------------------------------------
In this work we propose the Transformer, a model architecture eschewing recurrence and instead
relying entirely on an attention mechanism to draw global dependencies between input and output.
The Transformer allows for significantly more parallelization and can reach a new state of the art in
translation quality after being trained for as little as twelve hours on eight P100 GPUs.
2 Background
--------------------------------------------------------------------------------
$
Another query, on the same database:
$ capsa ask -d -k 1 "Will you disappoint me?"
================================================================================
DOCUMENT RETRIEVAL SYSTEM
================================================================================
QUERY.....: Will you disappoint me?
TOP-K.....: 1
INITIALIZING DATABASE CONNECTION... DONE
================================================================================
RECORD 001 DOCID=000002 SIMILARITY= 54.33%
================================================================================
TITLE..: Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)
AUTHOR.: Rick Astley
OFFSET.: 511-974 (463 BYTES)
--------------------------------------------------------------------------------
CONTENT:
--------------------------------------------------------------------------------
for so long ♪ ♪ Your heart's been aching
but you're too shy to say it ♪ ♪ Inside we both know
what's been going ♪ ♪ We know the game
and we're gonna play it ♪ ♪ And if you ask me
how I'm feeling ♪ ♪ Don't tell me
you're too blind to see ♪ ♪ Never gonna give you up ♪ ♪ Never gonna let you down ♪ ♪ Never gonna run around
and desert you ♪ ♪ Never gonna make you cry ♪ ♪ Never gonna say goodbye ♪ ♪ Never gonna tell a lie
--------------------------------------------------------------------------------
$
Output with -d shows cosine similarity percentages, helping you gauge result relevance.
Configuration
Global Options
Available for all commands:
--base-url <url>- Embedding service URL (default:http://localhost:9000/v1)--model <name>- Model name (default:nomic-ai/nomic-embed-text-v1.5)--db-path <path>- Database path (default:./documents.db)
Environment Variables
CAPSA_API_KEY- API key for embedding service (optional)
Command Reference
pdf - Index PDF Documents
Extracts PDF metadata and text, generates embeddings, and stores them in the vector database.
yt - Index YouTube Transcripts
Downloads YouTube transcript with metadata and indexes it for semantic search.
Options:
--lang <code>- Language code (default:en)
Accepts: Video ID or full YouTube URL
ask - Semantic Search
Query your document database using natural language.
Options:
-d- Show similarity percentages for each result-k <num>- Number of results to return (default:5)
License
MIT