snaprag
Local, CPU-only retrieval for RAG: index() your documents, then retrieve() the relevant chunks.
Parsing uses xberg, embeddings use fastembed and storage uses ChromaDB.
The embedding model (bge-small-en-v1.5, for English) is installed by pip, so nothing is downloaded the first time you run it.
Install
pip install snaprag
Requires Python 3.11 or later. Tested on Windows with Python 3.13.
Install from source
Name both folders in one command, so pip takes the model package from disk:
python -m pip install -e .\model_package -e ".[dev]"
Python 3.11 or later. In a fresh clone, first run python model_package/fetch_model.py to restore the model files.
Quick start
from snaprag import index, retrieve
result = index("handbook.pdf")
print(result.file_ids) # for example ['handbook_483920184756']
for hit in retrieve("How many leave days carry over?"):
print(hit.file_name, hit.page, hit.page_end, hit.text) # page numbers are for PDFs
index()
| Argument | Default | Meaning |
|---|---|---|
file_path |
One file. Pass this or folder_path. |
|
folder_path |
Every file in a folder. | |
file_id |
generated | Your ID for a single file. Not allowed with folder_path. |
metadata |
None |
Added to every chunk, and embedded with its text. |
collection_name |
"default" |
3 to 512 characters: letters, digits, ., _, -. |
recursive |
True |
Include subfolders. |
ocr_images |
False |
Also read the text in pictures inside documents. Much slower. See OCR. |
db_path |
./.snaprag |
Where the database lives. |
It returns an IndexResult with indexed, skipped, failed, file_ids and ok.
Wrong arguments raise an error. A file that cannot be indexed does not raise: check result.failed.
- The generated ID is the first word of the file name plus 12 random digits.
- Indexing a file again skips it if its content, metadata and index settings, including
ocr_images, are unchanged. Otherwise its chunks are replaced and it keeps itsfile_id. - Pass the same
metadataandocr_imageseach time. Leaving them out means no metadata and no image OCR, so the file is indexed again without them. - If re-indexing fails, the previous version stays searchable.
- Files are identified by their full path. A moved or renamed file counts as a new file.
- Deleting a file from disk does not remove it from the index. Use
delete(). - Folder indexing skips hidden files and folders (names starting with
.) and Office lock files (~$). Everything else is attempted, so point it at a document folder, not a whole code project.
Metadata values can be str, int, float, bool, or a non-empty list of one of these types.
None and nested dictionaries are rejected, as are these reserved keys:
file_id, file_name, source_path, chunk_index, chunk_count, fingerprint, heading, page, page_end.
Embedded metadata is limited to 200 tokens.
retrieve()
| Argument | Default | Meaning |
|---|---|---|
query |
The question or search text. | |
file_id |
None |
One ID or a list. None searches everything; an empty list is an error. |
collection_name |
"default" |
Collection to search. |
top_k |
20 |
Number of chunks to return. |
metadata_filter |
None |
All conditions must match. |
mode |
"hybrid" |
"hybrid" searches by meaning and by keyword. "vector" searches by meaning only. |
db_path |
./.snaprag |
Where the database lives. |
retrieve("travel limits", metadata_filter={"team": "hr"}) # equals
retrieve("travel limits", metadata_filter={"year": [2024, 2025]}) # any of
retrieve("travel limits", metadata_filter={"year": {"$gte": 2024}}) # operator
Each result has text, score, similarity, file_id, file_name, source_path, chunk_index,
heading, page, page_end and metadata.
pageandpage_endare the first and last page of the chunk, counting from 1. They are set for PDF files only. When citing a result, show the whole range.scoreis what results are ordered by, higher first. In"hybrid"mode it only ranks results: it is not a measure of confidence, so do not use a fixed cutoff.similarityis how close the chunk's meaning is to the query (cosine similarity). It means the same in both modes.
Hybrid search
Hybrid search combines the best matches by meaning with the best matches by keyword (reciprocal rank fusion). Keyword search helps with names, codes and exact terms. It looks at the chunk text, headings and your metadata, and ignores case and accents. It does not match other forms of a word: "invoices" does not match "invoice".
OCR
- Scanned pages and image files are read with OCR by default.
- Pictures inside a page that also has real text, such as a pasted table or chart, are not read by default.
Use
index(path, ocr_images=True)for them. - Check any figure that came from OCR: it can misread digits.
Managing files and settings
from snaprag import SnapRAG
rag = SnapRAG("data/my-index") # a fixed path, recommended for deployed apps
rag.index(folder_path="docs", metadata={"team": "hr"})
rag.list_files()
rag.delete("handbook_483920184756")
The functions index, retrieve, list_files and delete do the same using db_path.
The default database is .snaprag/ in the current working directory, which is not necessarily your project root.
Importing the package creates nothing, and only index() creates a database.
Only one process should write to a database at a time.
License
MIT. The bundled model files in snaprag-model have their own
MIT license.
Metadata
Release files for snaprag 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snaprag-0.1.0.tar.gz | 29.8 kB | Without provenance | Details for snaprag-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snaprag-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for snaprag-0.1.0-py3-none-any.whl |
Total release size: 54.8 kB
Release files / snaprag-0.1.0.tar.gz
| Download URL | snaprag-0.1.0.tar.gz |
|---|---|
| Size | 29.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f339edb8e79259fb12c097022a940bd1c75fef52b4a08d87e2d647c299d086ce
|
|
BLAKE2b-256 checksum How to use checksums |
9530d3ccd037837a7bed126ca9e879ddfe2b8e69f67eabc940614e4a3e8c57e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / snaprag-0.1.0-py3-none-any.whl
| Download URL | snaprag-0.1.0-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0ac5fee62902777714cb8f62bd976840800899a1ebb87809cc3c6a85fc54621
|
|
BLAKE2b-256 checksum How to use checksums |
01ea686ff4fd132ed21a6150e122904d19772005ac39893bb7ca707a34eecb6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Security for snaprag 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.