Skip to main content

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.

Python 3.10+ PyPI version Tests License GitHub stars

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:

  1. Understands structure โ€” Extracts entities, relationships, hierarchy, and metadata upfront
  2. Filters progressively โ€” Eliminates 90%+ of noise across 4 stages before expensive operations
  3. Returns minimal context โ€” Only the signal your LLM actually needs
  4. 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:

  1. Search all 1000 documents
  2. Rank by keyword + embeddings (slow, expensive)
  3. Return top 10 (5 are useless)
  4. LLM still confused

PyStreamDocuments:

  1. Recognize query is about "policies" + "authorization"
  2. Filter to policy documents (metadata, $0 cost)
  3. Rank by freshness (use document metadata, not index time)
  4. Find Notion page (authoritative source, updated today)
  5. Retrieve GitHub implementation (for reference)
  6. Return 50 tokens of pure signal
  7. 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:

  1. Source relevance (metadata: $0)
  2. Entity/type matching (index: $0)
  3. Freshness ranking (document metadata: $0)
  4. 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

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystreamdocuments-0.3.0-cp313-abi3-macosx_11_0_arm64.whl (371.1 kB view details)

Uploaded CPython 3.13+macOS 11.0+ ARM64

File details

Details for the file pystreamdocuments-0.3.0-cp313-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pystreamdocuments-0.3.0-cp313-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c05d00cef4d7bd0505112e9f6927ddded1b9ade90c125d93546a0ca69fd4715
MD5 8195fb579c5b170c8090ee7c4d2f5fb3
BLAKE2b-256 f2c0578cf135728aac44716b0728daa18931179425e64b8f8c84f23f8c790176

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page