Self-improving retrieval framework with RL routing, context engineering, MCP integration, agentic workflow, and persistent memory.
Project description
adaptive-intelligence
Self-improving retrieval framework that learns, remembers, and connects tools.
What it does
Instead of using the same retrieval strategy for every query, adaptive-intelligence uses reinforcement learning to select the best strategy per query type. The system evaluates every response, uses the score as a reward signal, and improves with every query answered.
Install
pip install adaptive-intelligence # Zero deps (Ollama, no-LLM mode)
pip install adaptive-intelligence[vector] # + ChromaDB vector search
pip install adaptive-intelligence[openai] # + Any OpenAI-compatible API (10+ providers)
pip install adaptive-intelligence[huggingface] # + Local HuggingFace models
pip install adaptive-intelligence[all] # Everything
Quick start
from adaptive_intelligence import AdaptiveAI
engine = AdaptiveAI()
engine.ingest("./documents")
response = engine.ask("What are the key risks?")
print(response.answer)
Works without any LLM — returns relevant document excerpts. Add an LLM for synthesized answers.
LLM providers
The library works with any LLM. The [openai] extras installs the OpenAI SDK which connects to any OpenAI-compatible API.
Free (no credit card needed)
# Ollama — local, no extras needed
engine = AdaptiveAI()
# NVIDIA NIM — free cloud tier
engine = AdaptiveAI(
api_key="nvapi-...",
base_url="https://integrate.api.nvidia.com/v1",
llm_model="meta/llama-3.1-70b-instruct"
)
# Groq — free cloud tier
engine = AdaptiveAI(
api_key="gsk_...",
base_url="https://api.groq.com/openai/v1",
llm_model="llama-3.3-70b-versatile"
)
# Google Gemini — free tier
engine = AdaptiveAI(
api_key="...",
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
llm_model="gemini-2.0-flash"
)
# Together AI — free tier
engine = AdaptiveAI(
api_key="...",
base_url="https://api.together.xyz/v1",
llm_model="meta-llama/Llama-3-70b-chat-hf"
)
# Fireworks AI — free tier
engine = AdaptiveAI(
api_key="...",
base_url="https://api.fireworks.ai/inference/v1",
llm_model="accounts/fireworks/models/llama-v3p1-70b-instruct"
)
# HuggingFace local — runs on your GPU, needs [huggingface] extras
engine = AdaptiveAI(
llm_backend="huggingface",
llm_model="Qwen/Qwen2.5-1.5B-Instruct"
)
# No LLM — retrieval only, zero dependencies
engine = AdaptiveAI(llm_backend="none")
Paid
# OpenAI
engine = AdaptiveAI(api_key="sk-...", llm_model="gpt-4o")
# Grok (xAI)
engine = AdaptiveAI(api_key="xai-...", base_url="https://api.x.ai/v1")
# Azure OpenAI
engine = AdaptiveAI(azure_endpoint="https://your.openai.azure.com/", api_key="...")
Self-hosted
# vLLM local server (free, runs on your GPU)
engine = AdaptiveAI(base_url="http://localhost:8000/v1")
# Any OpenAI-compatible server
engine = AdaptiveAI(base_url="http://your-server:8000/v1")
Any server that speaks the OpenAI-compatible API works with [openai] extras.
Key features
Context Engineering
Optimizes the entire context window — not just which chunks to retrieve, but what memory to include, how much history to keep, which tool results to add, and how to structure the prompt.
engine = AdaptiveAI(context_engineering=True)
MCP Integration
Connect external tools. Register MCP servers, REST APIs, or Python functions. The RL policy learns which tools to call per query type.
# Register tools
engine.add_tool("financial", server="http://localhost:8081")
engine.add_tool("calculator", function=my_calc_function)
engine.add_tool("search", api_endpoint="https://api.example.com/search")
# List registered tools
engine.list_tools()
# Remove a tool
engine.remove_tool("search")
# Serve your retrieval as an MCP server
engine.serve_mcp(port=8080)
Agentic Workflow
Multi-round retrieval. The system retrieves, evaluates confidence, refines the query, calls tools, and retrieves again until the answer is sufficient.
response = engine.ask("Analyze supply chain risks and mitigation", mode="agentic")
Persistent Memory
Remembers across sessions. Routing patterns, user preferences, and facts persist to disk.
engine.remember("focus_area", "supply chain risk")
engine.recall("focus_area")
engine.search_memory("supply chain")
Incremental Learning
Add new documents anytime. The RL policy, knowledge graph, and memory continue from their current state — no restart needed.
engine.ingest("./initial_docs") # Learn from initial set
engine.ingest("./quarterly_update.pdf") # Add later, system continues
RL-Based Retrieval Routing
Thompson Sampling or PPO learns which retrieval strategy works best per query type.
engine = AdaptiveAI(rl_algorithm="ppo")
engine = AdaptiveAI(pretrained_policy=True, domain="financial")
engine.export_policy("learned.json") # Transfer to another deployment
engine.import_policy("learned.json")
Conditional Graph Activation
Knowledge graph auto-built during ingestion. A 5-signal gate activates graph traversal only when the query needs relational reasoning. Saves compute on 70% of queries.
Vectorless Mode
No ChromaDB, no embeddings, zero dependencies. Uses page-level BM25 with page citations.
engine = AdaptiveAI(vectorless=True)
Structured Output
response = engine.ask("Extract metrics", output_format="json")
response = engine.ask("List items", output_format="csv")
response = engine.ask("Summarize", output_format="yaml")
User Feedback
response = engine.ask("What are the risks?")
engine.feedback(response.query_id, "good") # +0.2 RL reward
engine.feedback(response.query_id, "bad") # -0.3 RL reward + prompt evolution
Demos
Colab notebook (no setup needed)
Run on free T4 GPU with no API key: notebooks/adaptive_intelligence_v4_demo.ipynb
Local demos
cd demo_mcp_agenticai
pip install -r requirements.txt
python demo_basic.py # Basic usage + incremental learning
python demo_tools.py # Tool registry + cost optimization
python demo_agentic.py # Agentic multi-round retrieval
python demo_mcp_server.py # Serve as MCP server (terminal 1)
python demo_mcp_client.py # Connect to MCP server (terminal 2)
How it works
- Understand — Trigger interpreter classifies query type, complexity, domain, entities (no LLM call)
- Decide — RL policy selects retrieval route, depth, graph activation, tools to call
- Retrieve — Executes via vector, BM25, or page index with RRF fusion. Graph activates conditionally.
- Generate — Cross-encoder reranks chunks. Context engineer assembles full context window. LLM generates.
- Learn — 6 metrics evaluate response. Composite score = RL reward. Policy updates. Next query is better.
Links
- PyPI: https://pypi.org/project/adaptive-intelligence/
- GitHub: https://github.com/VK-Ant/adaptive-intelligence
- Paper: https://www.researchgate.net/publication/405076088
- Portfolio: https://vk-ant.github.io/Venkatkumar
- Also: llmevalkit — 61 metrics for LLM evaluation
Author
Venkatkumar Rajan | @VK_Venkatkumar
License
Apache License 2.0
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 Distribution
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 adaptive_intelligence-4.0.0.tar.gz.
File metadata
- Download URL: adaptive_intelligence-4.0.0.tar.gz
- Upload date:
- Size: 89.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
533fa90b3dc8a4cfa80061d12c39b4882fc5ecd3889684e0d57c2a02c2e3e4ec
|
|
| MD5 |
dda758879bf2e220d278086ec9385657
|
|
| BLAKE2b-256 |
8f63991cbba1fd099ca595155dc6570696551134adff19856160dca16e3a3e64
|
File details
Details for the file adaptive_intelligence-4.0.0-py3-none-any.whl.
File metadata
- Download URL: adaptive_intelligence-4.0.0-py3-none-any.whl
- Upload date:
- Size: 92.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
089431d5fac96d65e0116519f9a10adbf5e42d618cde70e7c4bae1ef801b8cbe
|
|
| MD5 |
994109b22112117c4cce58f23f9978ea
|
|
| BLAKE2b-256 |
5132e49117b8e07f210729203fd493b9f17f1f42bc41020dad4e250b0caf29b4
|