vector-poison-score
Score (query, document) pairs for vector/RAG poisoning signals. Detects vector-text mismatch, zero/NaN/suspiciously-round vectors, instruction-like payloads, link farms, oversized chunks. Pure Python, zero runtime dependencies.
Python port of @mukundakatta/vector-poison-score. The JS sibling has the original heuristics; this port adds vector-aware signals on top.
Install
pip install vector-poison-score
# Optional: faster cosine via numpy
pip install "vector-poison-score[numpy]"
Usage
from vector_poison_score import score, filter_poisoned
q_vec = [0.1, 0.2, 0.3, 0.4]
d_vec = [0.1, 0.2, 0.3, 0.41] # very close to q_vec
q_text = "Who is the CEO of Anthropic?"
d_text = "Buy cheap watches at example.com" # totally unrelated
s = score(q_vec, d_vec, d_text, q_text)
s.score # 0.25 (one signal)
s.signals # ["vector_text_mismatch"]
s.severity # "low"
# Bulk-filter retrieved chunks
records = [
{"id": "a", "embedding": q_vec, "text": "About Anthropic..."},
{"id": "b", "embedding": d_vec, "text": d_text},
]
filter_poisoned(
records,
max_score=0.2,
query_vec=q_vec,
query_text=q_text,
) # -> drops record 'b'
Signals
| Signal | Trigger |
|---|---|
vector_text_mismatch |
Cosine(query, doc) >= 0.7 but Jaccard(query terms, doc terms) <= 0.1. The classic poisoned-embedding signature. |
zero_vector |
Doc vector is all zeros. |
nan_vector |
Doc vector contains NaN or +/-inf. |
suspiciously_round |
>= 70% of doc-vector entries are within 1e-3 of an integer (likely hand-crafted). |
instruction_like_payload |
Doc text matches the prompt-injection regex (mirrors JS sibling). |
link_farm |
Doc text has > 5 URLs (mirrors JS sibling). |
oversized_chunk |
Doc text > 20000 chars (mirrors JS sibling). |
score = min(1.0, len(signals) / 4). Severity: >= 0.66 -> high, >= 0.33 -> medium, else low.
API differences from the JS sibling
- JS:
scoreVectorPoison({ text }), text-only. Python:score(query_vec, doc_vec, doc_text, query_text)-- adds vector-aware signals (mismatch, zero, NaN, round) on top of the text checks. - JS:
filterPoisoned(docs, { maxScore }). Python:filter_poisoned(records, max_score=, text_key=, vector_key=, query_vec=, query_text=)-- record-shape configurable, query inputs optional. PoisonScoreis a frozen dataclass; severity is a typed string literal.
See the JS sibling for the original heuristics and broader design notes.
Metadata
Release files for vector-poison-score 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 |
|---|---|---|---|---|
| vector_poison_score-0.1.0.tar.gz | 6.9 kB | Without provenance | Details for vector_poison_score-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vector_poison_score-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for vector_poison_score-0.1.0-py3-none-any.whl |
Total release size: 13.8 kB
Release files / vector_poison_score-0.1.0.tar.gz
| Download URL | vector_poison_score-0.1.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
882d2d7de8774cf1ef467efe6c24c673388d6889faf0288b23b4fa3dd997ee79
|
|
BLAKE2b-256 checksum How to use checksums |
d3b85ef17b81ecda9b575e08fd445f66fc9e563a65bd15f881f36efc0823b860
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / vector_poison_score-0.1.0-py3-none-any.whl
| Download URL | vector_poison_score-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
560b556a8e1dd8584b2b826e93f124a7aa4a60f21b9c80f6ced43ec0d98af558
|
|
BLAKE2b-256 checksum How to use checksums |
5a393052549c8541f02f665c673000897d700944332ff8fded66959d81a1c9b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for vector-poison-score 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.