🧠 Kalpanā AI — RIF Engine Studio
Unlimited Context via Resonant Interference Fields (RIF) + Any Remote LLM
🚀 Welcome to Kalpanā AI
Kalpanā AI is a high-performance O(1) memory retrieval engine powered by Resonant Interference Fields (RIF).
It absorbs massive documents (100K to 3M+ tokens) into constant-size binary Knowledge Packs (.kp).
When you ask a question, RIF extracts only the exact RIF-retrieved relevant context (~800 tokens) in under 5ms on CPU, sending 125x fewer tokens to remote LLMs. This gives any model unlimited context capability at a fraction of the cost.
📐 System Architecture Diagram
┌────────────────────────────────────────────────────────┐
│ Replace KV Cache & Heavy Vector DB (RAG) │
│ with Kalpanā RIF Engine │
└───────────────────────────┬────────────────────────────┘
│
┌──────────────────────┐ ┌─────────────▼─────────────┐ ┌──────────────────────┐
│ │ Query / │ Kalpanā RIF Engine │ Extracted │ │
│ Agent / User App ├────────────►│ O(1) Holographic ├─────────────►│ Remote LLM │
│ (Prompt & History) │ │ Memory Retrieval │ RIF Context │ (Qwen 2.5 / Llama 3.1│
│ │◄────────────┤ (~800 Tokens, <5ms) │ Context │ Groq / OpenAI / etc.)│
└──────────┬───────────┘ └─────────────▲─────────────┘ └──────────────────────┘
│ │
│ ┌─────────────┴─────────────┐
└────────────────────────►│ Knowledge Packs (.kp) │
1. Compile Document │ Constant-Size RIF State │
(PDF, TXT, Raw Text) └───────────────────────────┘
📌 How to Use this Studio (3 Easy Steps)
Step 1: Compile a Document into a Knowledge Pack
- Go to the
📚 Knowledge Pack Studiotab above. - Paste raw document text OR upload a
.pdf/.txtfile. - Click Compile into .kp and copy the generated
Pack ID(e.g.kp_a1b2c3d4).
- Go to the
Step 2: Chat & Test Context Retrieval
- Go to the
💬 Chat & Inference Testtab above. - Paste your
Pack IDinto the Active Pack ID box. - Select your preferred model (
qwen2.5-72b,llama-3.1-8b, etc.). - Type your query and click 🚀 Send Request to see AI responses with token savings metrics!
- Go to the
Step 3: (Optional) Bring Your Own LLM API Key
- Go to the
🔌 Register Custom LLM Providertab to connect your Groq, OpenAI, Together, or OpenRouter key.
- Go to the
❓ Do I Need to Create a Knowledge Pack (.kp)?
- NO for Standard Chat: If you are having a general multi-turn conversation or building an AI assistant without large files, you do NOT need a
.kppack. Send queries directly to/v1/chat/completions. - YES for Large PDFs / Documents: If you have massive documents, manuals, or legal PDFs (100K to 3M+ tokens), compile them into a
.kppack once. Passingactive_pack_idin your requests compresses the context by 125x and slashes your token bill.
🎬 Real-World Integration Scenarios
Scenario 1: Standard Long Chat Session (No Documents Needed)
import requests
BASE_URL = "https://madurox-kalpana-api-cpu.hf.space"
# Turn 1
history = [{"role": "user", "content": "Hi! How do I handle async tasks in Python?"}]
res1 = requests.post(f"{BASE_URL}/v1/chat/completions", json={"model": "qwen2.5-72b", "messages": history})
reply1 = res1.json()["choices"][0]["message"]["content"]
# Turn 2 (Append assistant reply and send follow-up)
history.append({"role": "assistant", "content": reply1})
history.append({"role": "user", "content": "Can you give a code example using asyncio?"})
res2 = requests.post(f"{BASE_URL}/v1/chat/completions", json={"model": "qwen2.5-72b", "messages": history})
print("AI:", res2.json()["choices"][0]["message"]["content"])
Scenario 2: Chat Session with PDF Document Attached (Middle or Start)
import requests
BASE_URL = "https://madurox-kalpana-api-cpu.hf.space"
# Step 1: User uploads PDF during conversation -> Compile into .kp
files = {"file": ("manual.pdf", open("manual.pdf", "rb"), "application/pdf")}
comp_res = requests.post(f"{BASE_URL}/v1/knowledge_packs/compile_file", files=files)
pack_id = comp_res.json()["pack_id"]
print("Generated Pack ID:", pack_id) # e.g., kp_276ac647
# Step 2: Continue chat session with active_pack_id attached
history = [
{"role": "user", "content": "What is the warranty policy according to the uploaded PDF?"}
]
chat_res = requests.post(
f"{BASE_URL}/v1/chat/completions",
json={
"model": "qwen2.5-72b",
"messages": history,
"active_pack_id": pack_id # <--- Attach PDF Knowledge Pack here!
}
)
print("AI Answer:", chat_res.json()["choices"][0]["message"]["content"])
2️⃣ Ask Question with RIF Context (/v1/chat/completions)
chat_res = requests.post(
"https://madurox-kalpana-api-cpu.hf.space/v1/chat/completions",
json={
"model": "qwen2.5-72b",
"messages": [{"role": "user", "content": "Summarize key points."}],
"active_pack_id": pack_id,
"max_tokens": 512,
"temperature": 0.7
}
)
print("AI Response:", chat_res.json()["choices"][0]["message"]["content"])
print("Token Savings:", chat_res.json()["cost_comparison"]["savings"])
3️⃣ Register Custom API Key (/v1/providers/register)
requests.post(
"https://madurox-kalpana-api-cpu.hf.space/v1/providers/register",
json={
"provider": "groq",
"api_key": "gsk_your_groq_key_here",
"model": "llama-3.1-8b-instant"
}
)
🔗 Resource Links
Test RIF-Enhanced Chat Inference with any LLM
Compile Documents into Portable .kp Knowledge Packs
Option A: Compile Raw Text
Option B: Upload PDF or TXT File
Active Knowledge Packs in Memory
Click Refresh to load active packs.
Bring Your Own API Key (Groq, OpenAI, Together, Cerebras, OpenRouter)
Official Native Model Context Windows vs. Kalpanā RIF Unlimited Context
The table below presents verified native context limits extracted directly from official model specifications and config.json manifests on Hugging Face.
| Model | Provider | Native Context Limit | Verified Official Reference | With Kalpanā RIF | Extension at 3M Tokens |
|---|---|---|---|---|---|
| Qwen 2.5 72B | HuggingFace | 32,768 tokens | max_position_embeddings in config.json |
Unlimited | 91x extension |
| Llama 3.1 8B | Meta / HF | 128,000 tokens | Meta Llama 3.1 Official Specs | Unlimited | 23x extension |
| Mistral 7B v0.3 | Mistral AI | 32,768 tokens | max_position_embeddings in config.json |
Unlimited | 91x extension |
| Qwen 2 0.5B | Qwen | 32,768 tokens | max_position_embeddings in config.json |
Unlimited | 91x extension |
| Phi-3 Mini 4K | Microsoft | 4,096 tokens | max_position_embeddings in config.json |
Unlimited | 732x extension |
Key Takeaway for Enterprise & API Customers
- Without Kalpanā: Querying 500K-1M token documents requires massive, expensive 128K+ LLM instances and incurs enormous token costs.
- With Kalpanā: Documents are absorbed into an O(1) RIF memory state. Every query retrieves only ~800 tokens. Any model — even small 4K/32K models — gets unlimited context capability for a fraction of the cost.