🧠 Kalpanā AI — RIF Engine Studio

Unlimited Context via Resonant Interference Fields (RIF) + Any Remote LLM

📖 OpenAPI Swagger Docs | ❤️ HuggingFace Space

🚀 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)

  1. Step 1: Compile a Document into a Knowledge Pack

    • Go to the 📚 Knowledge Pack Studio tab above.
    • Paste raw document text OR upload a .pdf / .txt file.
    • Click Compile into .kp and copy the generated Pack ID (e.g. kp_a1b2c3d4).
  2. Step 2: Chat & Test Context Retrieval

    • Go to the 💬 Chat & Inference Test tab above.
    • Paste your Pack ID into 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!
  3. Step 3: (Optional) Bring Your Own LLM API Key

    • Go to the 🔌 Register Custom LLM Provider tab to connect your Groq, OpenAI, Together, or OpenRouter key.


❓ 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 .kp pack. 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 .kp pack once. Passing active_pack_id in 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