Metadata-Version: 2.4
Name: prismrag-patch
Version: 0.2.1
Summary: Free OSS RAG library — ingest, graph RAG search, communities, bridges, append (API parity)
Author-email: Insight IT Solutions <prismrag@insightits.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://prismrag.insightits.com
Project-URL: Documentation, https://prismrag.insightits.com/prismrag-lib.html
Project-URL: Repository, https://github.com/aminparva84/InsightPrismRAG
Project-URL: Bug Tracker, https://prismrag.insightits.com/support
Project-URL: PyPI, https://pypi.org/project/prismrag-patch/
Project-URL: Whitepaper, https://prismrag.insightits.com/whitepaper.html
Keywords: rag,vector-database,graph-rag,pgvector,chromadb,pinecone,weaviate,llm,open-source
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Provides-Extra: graph
Requires-Dist: networkx>=3.0; extra == "graph"
Requires-Dist: python-louvain>=0.16; extra == "graph"
Provides-Extra: torch
Requires-Dist: torch>=2.0; extra == "torch"
Provides-Extra: pgvector
Requires-Dist: psycopg2-binary>=2.9; extra == "pgvector"
Requires-Dist: pgvector>=0.2; extra == "pgvector"
Provides-Extra: chroma
Requires-Dist: chromadb>=0.4; extra == "chroma"
Provides-Extra: pinecone
Requires-Dist: pinecone-client>=3.0; extra == "pinecone"
Provides-Extra: weaviate
Requires-Dist: weaviate-client>=4.0; extra == "weaviate"
Provides-Extra: all
Requires-Dist: networkx>=3.0; extra == "all"
Requires-Dist: python-louvain>=0.16; extra == "all"
Requires-Dist: torch>=2.0; extra == "all"
Requires-Dist: psycopg2-binary>=2.9; extra == "all"
Requires-Dist: pgvector>=0.2; extra == "all"
Requires-Dist: chromadb>=0.4; extra == "all"
Requires-Dist: pinecone-client>=3.0; extra == "all"
Requires-Dist: weaviate-client>=4.0; extra == "all"
Dynamic: license-file

# prismrag-patch

**Free OSS RAG library with full API core parity — ingest, graph RAG search, communities, bridges, append.**

Official site: **[prismrag.insightits.com/prismrag-lib.html](https://prismrag.insightits.com/prismrag-lib.html)** ·
Product overview: **[INFO.md](../INFO.md)** ·
PyPI: **[pypi.org/project/prismrag-patch](https://pypi.org/project/prismrag-patch/)**

## What's in 0.2.1

- **No license key** — Apache-2.0, pip-only, fully offline
- **`PrismRAG` client** — mirrors SaaS core endpoints locally
- **Graph RAG** — word graph, Louvain communities, BFS retrieval
- **Dual vectors** — 768-d semantic + 256-d personal (RulesStrategy projection)
- **Append + quality scoring** — extend mappings without full retrain
- **Step-by-step tests** — `tests/test_lib_step*.py` + evaluation harness

## Quick start — full RAG pipeline (no DB required)

```python
from prismrag_patch import PrismRAG

mapping = {
    "categories": [
        {"slug": "medication", "label": "Medication"},
        {"slug": "lab_results", "label": "Lab Results"},
    ],
    "rules": [
        {"word": "metformin", "category_slug": "medication"},
        {"word": "troponin",  "category_slug": "lab_results"},
    ],
}

rag = PrismRAG(mapping=mapping, tenant_id="demo")
job = rag.ingest(records=[
    {"word": "metformin", "text": "metformin for diabetes"},
    {"word": "troponin",  "text": "troponin heart attack marker"},
])
print(job["status"], job["community_count"])

results = rag.search("What medications for diabetes?", top_k=5)
for hit in results["results"]:
    print(hit["category_slug"], hit["chunk_ref"])

comms = rag.list_communities()
bridge = rag.create_bridge(comms[0]["community_id"], comms[1]["community_id"])
quality = rag.chunk_quality()
```

## Vector DB adapters (Tier-1 remap)

Works with pgvector, ChromaDB, Pinecone, or Weaviate — bring your own embeddings:

```python
from prismrag_patch import PrismRAGPatch
from prismrag_patch.adapters.pgvector import PgvectorAdapter
import psycopg2

patch = PrismRAGPatch(mapping=mapping)  # no license_key
conn = psycopg2.connect("postgresql://user:pass@localhost/mydb")
adapter = PgvectorAdapter(patch, conn)
adapter.insert("metformin therapy", your_embed_fn("metformin therapy"))
```

## PostgreSQL store (SaaS schema parity)

Use the same ``prismrag.*`` tables as production — no HTTP API required:

```python
import os
from prismrag_patch import PrismRAG, PostgresStore

dsn = os.environ["PRISMRAG_DB_DSN"]  # postgresql://user:pass@host:5432/prismrag
tenant_id = "10000000-0000-0000-0000-000000000001"

# Option A: factory
rag = PrismRAG.from_postgres(dsn=dsn, mapping=mapping, tenant_id=tenant_id)

# Option B: explicit store
store = PostgresStore(dsn=dsn)
store.ensure_tenant(tenant_id)
rag = PrismRAG(mapping=mapping, tenant_id=tenant_id, store=store)

rag.ingest(records=[...])
print(rag.search("credit risk", top_k=5))
```

Requires ``prismrag/schema.sql`` applied to your database and ``pip install "prismrag-patch[graph,pgvector]"``.

Integration tests: ``PRISMRAG_DB_DSN=... pytest tests/test_lib_postgres_store.py -v``

## Installation

```bash
pip install prismrag-patch                      # core (mapping, ingest, search in-memory)
pip install "prismrag-patch[graph]"             # + networkx + python-louvain (communities)
pip install "prismrag-patch[pgvector]"          # + PostgreSQL adapter
pip install "prismrag-patch[all]"               # everything
```

## Running parity tests

```bash
cd prismrag_patch && pip install -e ".[graph]"
cd .. && pytest tests/test_lib_step01_mapping.py -v   # step 1: mapping
pytest tests/test_lib_step02_ingest.py -v              # step 2: ingest
pytest tests/test_lib_step03_graph.py -v               # step 3: graph/communities
pytest tests/test_lib_step04_search.py -v              # step 4: search
pytest tests/test_lib_step05_bridge_append.py -v     # step 5: bridge/append/quality
pytest tests/test_lib_step06_evaluation.py -v -s     # step 6: evaluation report
```

## API parity matrix

| SaaS endpoint | Library method |
|---------------|----------------|
| `POST /jobs` (inline ingest) | `rag.ingest(...)` |
| `GET /jobs/{id}` | `rag.get_job(job_id)` |
| `POST /search` | `rag.search(query, top_k=, category_filter=)` |
| `GET /communities` | `rag.list_communities()` |
| `POST /bridges` | `rag.create_bridge(a, b, bridge_label=)` |
| `POST /append` | `rag.append_chunks(...)` |
| `GET /chunks/quality` | `rag.chunk_quality()` |
| Chunk export | `rag.export_chunks()` |

## License

Apache-2.0 — free for commercial and personal use.

© 2026 Insight IT Solutions
