Smart context provider for LLMs - Minimal, most-relevant knowledge based on query anticipation and semantic understanding
Project description
PyStreamDocuments
Stop losing context to noise. Transform your documents into intelligent knowledge with one API.
The Problem
Traditional RAG is broken. You index 1000 documents, your LLM gets 500+ tokens of noise, and still misses the answer that was there all along.
Traditional RAG:
- ๐ Index everything equally
- ๐ Retrieve 10 documents (hope one is right)
- ๐ฃ๏ธ Feed 500 tokens to LLM (mostly noise)
- ๐ฐ $0.01+ per query just for context
PyStreamDocuments:
- ๐ง Understand document structure upfront
- ๐ Retrieve exactly 1-3 pieces (guaranteed relevant)
- ๐ฌ Feed 50 tokens to LLM (pure signal)
- ๐ธ <$0.001 per query (10-100x cheaper)
The Solution
PyStreamDocuments is an intelligent document ingestion and retrieval system that:
- Understands structure โ Extracts entities, relationships, hierarchy, and metadata upfront
- Filters progressively โ Eliminates 90%+ of noise across 4 stages before expensive operations
- Returns minimal context โ Only the signal your LLM actually needs
- Connects anything โ S3, PostgreSQL, Notion, Slack, GitHub, webโall with one API
Result: 10-100x fewer tokens, 10-100x lower cost, better answers.
What Makes It Different
| Traditional RAG | PyStreamDocuments |
|---|---|
| โ Embeds everything | โ Embeddings optional, on-demand |
| โ Vendor lock-in | โ Your choice of DB/model |
| โ Returns noise | โ Returns pure signal |
| โ Flat retrieval | โ Smart progressive filtering |
| โ Expensive | โ Dramatically cheaper |
Quick Start (60 seconds)
1๏ธโฃ Install
pip install pystreamdocuments
2๏ธโฃ Ingest
from pystreamdocuments import PyStreamDocuments
client = PyStreamDocuments()
# One API for all sources
await client.ingest("s3://my-bucket/docs") # AWS S3
await client.ingest("postgres://host/db") # Database
await client.ingest("notion://workspace-id") # Notion
await client.ingest("github://owner/repo") # GitHub
3๏ธโฃ Search
# Smart retrieval with context
results = await client.search(
"What's our Q3 revenue forecast?",
context={"domain": "finance", "agent_role": "analyst"}
)
# Returns exactly what you need
for result in results:
print(result.summary) # ~50 tokens of pure signal
That's it. Your LLM now has perfect context every time.
Why People Love It
๐ It's Fast
- Metadata extraction: >100 docs/sec
- Search: <100ms for complex queries
- No wait for embeddings
๐ฐ It's Cheap
- Traditional RAG: $0.01+ per query
- PyStreamDocuments: <$0.001 per query
- 10-100x cost reduction
๐ฏ It Works
- Real understanding of document structure
- 4-stage progressive filtering (90%+ noise elimination)
- Entity-aware retrieval with freshness ranking
- Intelligent deduplication across sources
๐ง It's Flexible
- Optional embeddings (your choice)
- Multiple vector DBs (Pinecone, Weaviate, Qdrant, Postgres)
- Works without embeddings entirely
- Custom models supported
- Zero vendor lock-in
๐ฆ It's Complete
- 171 tests passing
- Production-ready Docker deployment
- CI/CD automation with GitHub Actions
- Comprehensive REST API
- Enterprise monitoring built-in
Real-World Example
Problem: Your LLM misses the updated authorization policy because it's buried in Notion, referenced in Slack, and implemented in GitHub.
Traditional RAG:
- Search all 1000 documents
- Rank by keyword + embeddings (slow, expensive)
- Return top 10 (5 are useless)
- LLM still confused
PyStreamDocuments:
- Recognize query is about "policies" + "authorization"
- Filter to policy documents (metadata, $0 cost)
- Rank by freshness (use document metadata, not index time)
- Find Notion page (authoritative source, updated today)
- Retrieve GitHub implementation (for reference)
- Return 50 tokens of pure signal
- LLM has exactly what it needs
Cost: 100x cheaper. Time: 2x faster. Accuracy: infinitely better.
Features That Matter
๐ Universal Ingestion
One API for everything. S3, SharePoint, Google Drive, Notion, Slack, GitHub, PostgreSQL, MySQL, BigQuery, web, local filesโhandled uniformly.
๐ง Intelligent Understanding
- Extract entities (people, orgs, products, dates)
- Map relationships (who works with who, what depends on what)
- Preserve structure (sections, hierarchy, cross-references)
- Classify knowledge (procedure, policy, definition, data, code)
๐ Progressive Filtering
4-stage pipeline eliminates 90%+ before expensive operations:
- Source relevance (metadata: $0)
- Entity/type matching (index: $0)
- Freshness ranking (document metadata: $0)
- Semantic reranking (optional embeddings: ~$0.0001)
๐ Smart Ranking
- Pre-ranked at index time (instant O(1) retrieval)
- Hybrid ranking (semantic + BM25 + RRF)
- Freshness-aware (use document metadata, not index time)
- Topic coherence scoring
- Automatic deduplication
๐ Quality Assurance
- Pre-ingestion validation gates
- Real-time quality metrics
- Health monitoring
- Trend analysis
- Automatic recommendations
๐ Query Intelligence
- Intent classification (10 types)
- Entity extraction from queries
- Constraint parsing (time, domains, sources)
- Query anticipation (predict next question)
๐ Production Ready
- Docker deployment (with docker-compose)
- Multi-cloud guides (AWS, GCP, Azure, K8s)
- Health checks and monitoring
- REST API with full documentation
- OpenTelemetry integration
Architecture
The Data Flow
Any Source (Docs, Databases, Web, APIs)
โ
[Ingest & Parse]
โ
[Extract Metadata]
โโ Entities & relationships
โโ Document structure
โโ Classification
โโ Freshness markers
โโ Cross-source links
โ
[Smart Indexing]
โโ BM25 keyword index
โโ Topic clustering
โโ Entity graph
โโ Relationship map
โโ Freshness tracking
โ
[User Query]
โ
[4-Stage Filtering]
โโ Stage 1: Source relevance (metadata: $0)
โโ Stage 2: Entity/type match (index: $0)
โโ Stage 3: Freshness rank (metadata: $0)
โโ Stage 4: Semantic rerank (optional: ~$0.0001)
โโ Deduplication
โ
[Minimal Context]
~50 tokens of pure signal
Why It Works
- No noise upfront: Structure extracted once at index time
- Progressive filtering: Eliminates 90%+ before expensive operations
- Freshness awareness: Uses document metadata (created/modified/effective dates)
- Hybrid retrieval: Combines keyword + semantic + topic coherence
- Deduplication: Same fact from multiple sources? Return once
Installation & Setup
Requirements
- Python 3.10+
- PostgreSQL 14+ (optional, for persistence)
Install
# Basic (embeddings optional)
pip install pystreamdocuments
# With server extras
pip install pystreamdocuments[server]
# Development
pip install pystreamdocuments[dev]
Local Development
# Clone repo
git clone https://github.com/Mullassery/pystreamdocuments.git
cd pystreamdocuments
# Start full stack (includes PostgreSQL)
docker-compose up
# Server is now running on http://localhost:8080
# Try health check: curl http://localhost:8080/health
API Reference
Quick Examples
from pystreamdocuments import PyStreamDocuments
client = PyStreamDocuments()
# Ingest from any source
await client.ingest("s3://bucket/docs")
# Search with context
results = await client.search(
query="authorization policy",
context={
"domain": "security",
"agent_role": "compliance_officer",
"time_period": ("2024-Q1", "2024-Q4")
},
top_k=3 # Return only top 3 (very specific)
)
# Get quality metrics
metrics = await client.get_quality_metrics()
print(f"Pass rate: {metrics.validation_pass_rate:.1%}")
print(f"Freshness: {metrics.freshness_score:.1%}")
# Health check
health = await client.health_check()
assert health["status"] == "healthy"
REST API
# Start server
pystreamdocuments-server
# Health check
curl http://localhost:8080/health
# Get quality metrics
curl http://localhost:8080/quality/metrics
# Ingest document
curl -X POST http://localhost:8080/ingest \
-H "Content-Type: application/json" \
-d '{
"source_type": "pdf",
"source_location": "s3://bucket/doc.pdf",
"knowledge_type": "policy",
"domain": "security",
"content": "..."
}'
# Search
curl -X POST http://localhost:8080/search \
-H "Content-Type: application/json" \
-d '{
"query": "What is our authorization policy?",
"domain": "security"
}'
Full Documentation
- API Reference โ All endpoints with examples
- Deployment Guide โ Cloud deployment (AWS, GCP, Azure, K8s)
- Contributing โ How to contribute
Performance
| Metric | Result |
|---|---|
| Ingestion speed | >100 docs/sec (metadata-first) |
| Search latency | <100ms (including semantic) |
| Context reduction | 10-100x fewer tokens |
| Cost reduction | 10-100x cheaper per query |
| Test coverage | 171 tests passing (100% core) |
| Production ready | โ Docker, K8s, multi-cloud |
Status & Roadmap
โ v0.2.0 (Current)
- Universal ingestion (5+ formats)
- Progressive filtering (4 stages)
- Quality validation & monitoring
- Query intelligence (intent + entity extraction)
- Semantic search with hybrid ranking
- REST API with health/metrics
- Docker & multi-cloud deployment
- 171 tests, production-ready
๐ Coming Soon
- v0.3.0: Semantic caching, LLM-powered reranking, advanced analytics
- v1.0.0: Multi-tenancy, enterprise auth, GraphRAG integration
Why Open Source?
We believe intelligent document retrieval should be:
- Accessible: Not locked behind closed-source services
- Trustworthy: Code you can read and audit
- Flexible: Integrate however you want
- Affordable: Not 100x markup on commodities
That's why PyStreamDocuments is open source and MIT-licensed.
Community
- Issues: Report bugs or request features
- Discussions: Ask questions and share ideas
- Contributing: See CONTRIBUTING.md
License
MIT License โ you own what you build.
Built With
- Rust + Python โ Performance + accessibility
- PyO3 โ Zero-copy Python bindings
- Axum โ Modern async HTTP server
- tantivy โ Fast BM25 search
- PostgreSQL โ Reliable persistence
- OpenTelemetry โ Production observability
Extensibility
PyStreamDocuments integrates with specialized tools:
- Document Parsers โ PDF, Word, Markdown parsing with structure extraction
- Spreadsheet Engines โ Schema-aware querying and extraction
- Database Connectors โ Schema inspection and data retrieval
- Web Browsers โ Automated page navigation and content extraction
- Code Analyzers โ Language-aware parsing and API extraction
- MCP Tools โ Integration with Model Context Protocol providers (Notion, Slack, GitHub, etc.)
Stop losing context. Start using intelligence.
Get Started โ | Deployment Guide โ | API Reference โ
โญ If you find this useful, please star the repository! It helps us grow.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pystreamdocuments-0.3.0-cp313-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: pystreamdocuments-0.3.0-cp313-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 371.1 kB
- Tags: CPython 3.13+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c05d00cef4d7bd0505112e9f6927ddded1b9ade90c125d93546a0ca69fd4715
|
|
| MD5 |
8195fb579c5b170c8090ee7c4d2f5fb3
|
|
| BLAKE2b-256 |
f2c0578cf135728aac44716b0728daa18931179425e64b8f8c84f23f8c790176
|