Quantum Knowledge Weaver (QKW) is an open-source, hybrid quantum-classical multi-source knowledge orchestration brain. It comprehends complex user inquiries, optimizes API selection via the Quantum Approximate Optimization Algorithm (QAOA with XY-Mixer & Dicke States) mapped to a QUBO Hamiltonian with Quantum Covariance Synergies, concurrently fetches ground truth from 8 heterogeneous public repositories (Wikipedia, arXiv, The Holy Quran, Hadith Traditions, PubMed, NASA Open Science, OpenAlex Academic Graph, and PubChem), cross-references disparate claims for corroboration and contradictions via Natural Language Inference (NLI), and synthesizes citation-backed answers using local, open-source LLMs (Ollama).
flowchart TD
User([User / Client]) -->|1. Natural Language Query| UI[Streamlit UI / FastAPI Backend]
UI -->|2. Check Semantic Memory| Qdrant[(Qdrant Vector DB)]
Qdrant -.->|Cache Hit < 20ms| UI
Qdrant -->|Cache Miss| Orchestrator[Classical Orchestrator]
subgraph Quantum_Router [⚛️ Quantum Routing Layer - 8 Qubits]
Orchestrator --> Formulator[QUBO & Ising Hamiltonian + Covariance Synergies J_ij]
Formulator --> QAOA[QAOA XY-Mixer Optimizer / Dicke State |D_N^K>]
QAOA --> Winner[Optimal API Selection Vector x_i in {0,1}^8]
end
subgraph External_APIs [🌐 Asynchronous Distributed Data Sources]
Winner -->|Async Parallel| Wiki[Wikipedia Action API]
Winner -->|Async Parallel| Arxiv[arXiv Atom Feed]
Winner -->|Async Parallel| Quran[Quranic Corpus API]
Winner -->|Async Parallel| Hadith[Hadith Traditions Index]
Winner -->|Async Parallel| PubMed[PubMed NCBI E-Utilities]
Winner -->|Async Parallel| NASA[NASA Astrophysics API]
Winner -->|Async Parallel| OpenAlex[OpenAlex Academic Graph]
Winner -->|Async Parallel| PubChem[PubChem Chemical DB]
end
Wiki & Arxiv & Quran & Hadith & PubMed & NASA & OpenAlex & PubChem --> Aggregator[Result & Citation Collector]
subgraph Synthesis_and_Memory [🧠 Cross-Reference & Synthesis Engine]
Aggregator --> CrossRef[Semantic Cross-Reference & Contradiction Layer]
CrossRef --> LLM[Local Ollama LLM Synthesizer]
LLM --> Neo4j[(Neo4j Entity-Relation Graph)]
LLM --> Qdrant
end
LLM -->|3. Grounded Answer with Citations & Telemetry| UI
The API routing problem is formulated as a Quadratic Unconstrained Binary Optimization (QUBO) problem.
Given
-
$x_i = 1$ : Query API$i$ -
$x_i = 0$ : Exclude API$i$
Where:
-
$R_i \in [0, 1]$ is the semantic domain relevance of API$i$ to query keywords. -
$L_i \in [0, 1]$ is normalized historical API latency. -
$K$ is the target API budget constraint (e.g.,$K=3$ ). -
$P$ is the quadratic penalty factor enforcing cardinality.
Mapping binary variables
Starting from an equal superposition state
d:/AI/
├── backend/
│ ├── apis/ # Isolated clients for external knowledge sources
│ │ ├── base.py # Base abstract client with latency tracking
│ │ ├── wikipedia.py # Wikipedia Action & REST summary client
│ │ ├── arxiv.py # arXiv Atom XML preprint parser
│ │ ├── quran.py # Quranic verses & translations (Al-Quran / Quran.com)
│ │ ├── hadith.py # Prophetic traditions (Bukhari, Muslim, Tirmidhi)
│ │ ├── pubmed.py # NCBI Entrez E-utilities (esearch + esummary)
│ │ └── registry.py # Central API registry & metadata
│ ├── quantum/ # Quantum computing algorithms & simulators
│ │ ├── qubo_formulator.py # Mathematical QUBO Hamiltonian builder
│ │ ├── router.py # QAOA variational optimizer & statevector engine
│ │ ├── grover_search.py # Grover's algorithm simulator for graph searching
│ │ └── vqe_simulator.py # Variational Quantum Eigensolver for H2 chemistry
│ ├── orchestrator/ # Concurrency engine & Pydantic models
│ │ ├── engine.py # Master asynchronous pipeline
│ │ └── models.py # Request/response contracts & telemetry schemas
│ ├── cross_reference/ # Semantic comparison & contradiction detection
│ │ └── comparator.py # Cross-referencer & similarity matrix
│ ├── synthesis/ # Anti-hallucination synthesis
│ │ └── synthesizer.py # Local Ollama (llama3.1 / qwen2.5) grounding
│ ├── memory/ # Persistent & in-memory databases
│ │ ├── qdrant_store.py # Qdrant semantic vector cache
│ │ └── neo4j_store.py # Neo4j entity-relation knowledge graph
│ ├── config.py # Environment configuration & defaults
│ └── main.py # FastAPI endpoints (/query, /health, /apis, /quantum/route)
├── frontend/
│ └── streamlit_app.py # Interactive Streamlit UI with quantum telemetry
├── tests/ # Comprehensive test suite (pytest)
│ ├── test_apis.py # API client tests
│ ├── test_quantum_router.py # QAOA, QUBO, Grover, and VQE tests
│ ├── test_cross_reference.py# Semantic similarity & contradiction tests
│ └── test_orchestrator.py # End-to-end integration & cache tests
├── docker-compose.yml # Containerized services (Qdrant, Neo4j, backend, UI)
├── requirements.txt # Python dependencies
├── pytest.ini # Pytest configuration
└── README.md # Project documentation
- Python 3.11, 3.12, or 3.13
- (Optional) Ollama for local LLM synthesis:
ollama run llama3.1 # or ollama run qwen2.5
# Clone the repository
git clone https://github.com/your-username/quantum-knowledge-weaver.git
cd quantum-knowledge-weaver
# Create and activate virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Linux/macOS:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt# Terminal 1: Launch FastAPI Backend
uvicorn backend.main:app --host 0.0.0.0 --port 8000 --reload
# Terminal 2: Launch Streamlit Frontend
streamlit run frontend/streamlit_app.pydocker-compose up --build- FastAPI Docs:
http://localhost:8000/docs - Streamlit UI:
http://localhost:8501 - Neo4j Browser:
http://localhost:7474 - Qdrant Dashboard:
http://localhost:6333/dashboard
Run the test suite with:
pytest tests/ -vAll 9 test suites validate:
- ✅ Wikipedia, arXiv, and Hadith API fetching and error containment
- ✅ QUBO matrix formulation and eigenvalue costs
- ✅ QAOA quantum statevector routing convergence
- ✅ Grover quadratic search on graph structures
- ✅ VQE molecular ground state calculation for
$H_2$ - ✅ Cross-referencing similarity and contradiction detection
- ✅ End-to-end asynchronous pipeline with Qdrant vector caching
| Method | Endpoint | Description |
|---|---|---|
POST |
/query |
Full hybrid pipeline: QAOA routing |
GET |
/health |
System health, quantum engine status, and database connectivity |
GET |
/apis |
List of registered APIs, latency profiles, and domain tags |
POST |
/quantum/route |
Standalone QAOA routing inspection (qubits, energy, probabilities) |
POST |
/quantum/vqe |
Standalone VQE simulation for molecular ground states |
GET |
/memory/graph |
Entity-relation knowledge graph nodes and edges |
- Phase 1: Core Hybrid MVP (5 APIs, QAOA statevector router, cross-reference comparator, Ollama grounding).
- Phase 2: Memory & Graph Architecture (Qdrant semantic caching, Neo4j knowledge triples, Grover search demo, VQE simulator).
- Phase 3: Hardware Verification on IBM Quantum (Running QAOA circuits on 127-qubit IBM Eagle/Heron QPUs via
qiskit-ibm-runtime). - Phase 4: Open Source Release & arXiv Preprint ("Hybrid Quantum-Classical Multi-Domain API Orchestration via Variational Hamiltonian Optimization").
Distributed under the MIT License. See LICENSE for details.