nzachapy
Context Filtering for LLMs — Scan your entire dataset and return only the portion relevant to your query.
When working with large datasets and language models, stuffing everything into the context window is noisy and expensive. nzachapy solves this by chunking your data, embedding it semantically, and returning only the chunks most relevant to a given query — so your model sees signal, not noise.
Installation
pip install nzachapy
Quick Start
from nzachapy import Nzacha
# Initialize the module
nz = Nzacha()
# Add your dataset (must be a string or a list of string)
nz.add_by_words(data)
# Query for relevant context
results = nz.search("your query here")
⚠️ Important: Your dataset must be converted to a string before passing it to
add_by_words().
Configuration
When initializing Nzacha, you can customize the following parameters. If left unset, the defaults are used.
| Parameter | Default | Description |
|---|---|---|
chunk_size |
200 |
Number of words per chunk |
overlap |
20 |
Number of overlapping words between consecutive chunks |
openai_api_key |
None |
OpenAI API key for semantic embeddings (optional) |
threshold |
0.6 |
Minimum similarity score for a chunk to be returned |
Example with custom config
nz = Nzacha(
chunk_size=150,
overlap=30,
openai_api_key="sk-...",
threshold=0.75
)
Embedding Backends
nzachapy supports two embedding strategies:
- OpenAI — Provide your
openai_api_keyat initialization to use OpenAI's embedding models for higher-quality semantic search. - Sentence Transformers (default) — If no API key is provided, the module falls back to a local
sentence-transformersmodel. No API key required.
How It Works
-
Chunking —
add_by_words(data)splits your string dataset into overlapping word-based chunks.chunk_sizecontrols how many words each chunk contains;overlapcontrols how many words are shared between adjacent chunks to preserve context across boundaries. -
List —
add_by_words(data)if data is a list, embed each element in the list,chunk_sizeandoverlapare not used here -
Embedding — Each chunk/element is embedded into a vector using either OpenAI or Sentence Transformers.
-
Retrieval — When you run a query, it is embedded the same way and compared against all chunk/element embeddings. Only chunks/elements that meet or exceed the
thresholdsimilarity score are returned.
API Reference
Nzacha(chunk_size, overlap, openai_api_key, threshold)
Initializes the context filter with the given configuration.
nz.add_by_words(data: str | list)
if data: str Chunks the provided string dataset by word count and stores the embeddings internally else just stores the embeddings if each list element internally. Must be called before querying.
data— Your full dataset as a string or list. Convert any other structure to a string or a list first.
Notes
- Always pass data as a plain string or a list. Use
str(),json.dumps(), or.to_string()(for DataFrames) to convert before callingadd_by_words(). - A lower
thresholdreturns more (but less precise) chunks. A higher threshold is stricter. - Chunk
overlaphelps avoid losing context that falls on chunk boundaries — tune it based on your data's structure.
Contributing
Contributions are welcome! If you spot an area for improvement — whether it's a new chunking strategy, a better embedding backend, performance optimizations, or additional retrieval methods — feel free to open an issue or submit a pull request.
Please make sure any changes are well-tested and clearly documented.
License
MIT
Metadata
Release files for nzachapy 0.1.3
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 |
|---|---|---|---|---|
| nzachapy-0.1.3.tar.gz | 10.5 kB | Without provenance | Details for nzachapy-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nzachapy-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for nzachapy-0.1.3-py3-none-any.whl |
Total release size: 16.0 kB
Release files / nzachapy-0.1.3.tar.gz
| Download URL | nzachapy-0.1.3.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bf602c76f9be92469db2e12098dcfa2b0493a85a7f040ee69499a6aec6acbe6
|
|
BLAKE2b-256 checksum How to use checksums |
8eaa1bc8ca3996ed4913e0cb57ff04c5f7f4ef30a0a2714f4286d4b65b1ce9ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / nzachapy-0.1.3-py3-none-any.whl
| Download URL | nzachapy-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9696418c87dbd15565605eb63aa51d342cd7bef282f0eaa92a1bea3dbcf88c8c
|
|
BLAKE2b-256 checksum How to use checksums |
71289838bac83ea9a0fad2b1374f925af6dfa952d97bd405a7deca715560dccc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for nzachapy 0.1.3
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.