adaptive-intelligence 3.0.1__tar.gz → 4.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adaptive_intelligence-4.0.0/PKG-INFO +309 -0
- adaptive_intelligence-4.0.0/README.md +241 -0
- adaptive_intelligence-4.0.0/adaptive_intelligence/__init__.py +33 -0
- adaptive_intelligence-4.0.0/adaptive_intelligence/agentic/__init__.py +183 -0
- adaptive_intelligence-4.0.0/adaptive_intelligence/context/__init__.py +142 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/core/engine.py +173 -20
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/evaluation/__init__.py +49 -16
- adaptive_intelligence-4.0.0/adaptive_intelligence/mcp/__init__.py +332 -0
- adaptive_intelligence-4.0.0/adaptive_intelligence/memory/persistent.py +201 -0
- adaptive_intelligence-4.0.0/adaptive_intelligence.egg-info/PKG-INFO +309 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence.egg-info/SOURCES.txt +4 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence.egg-info/requires.txt +8 -4
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/pyproject.toml +12 -7
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_core.py +1 -1
- adaptive_intelligence-3.0.1/PKG-INFO +0 -323
- adaptive_intelligence-3.0.1/README.md +0 -259
- adaptive_intelligence-3.0.1/adaptive_intelligence/__init__.py +0 -24
- adaptive_intelligence-3.0.1/adaptive_intelligence.egg-info/PKG-INFO +0 -323
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/LICENSE +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/core/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/core/config.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/core/response.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/graph/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/indexes/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/indexes/base.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/indexes/keyword_index.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/indexes/page_index.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/indexes/vector_index.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/ingestion/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/ingestion/chunker.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/ingestion/engine.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/ingestion/parser.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/llm/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/memory/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/prompts/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/query/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/rl/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/rl/multi_query.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/rl/ppo.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/rl/pretrained.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/rl/reranker.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/security/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence/utils/__init__.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence.egg-info/dependency_links.txt +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/adaptive_intelligence.egg-info/top_level.txt +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/setup.cfg +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_evaluation.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_graph.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_ingestion.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_query.py +0 -0
- {adaptive_intelligence-3.0.1 → adaptive_intelligence-4.0.0}/tests/test_rl.py +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: adaptive-intelligence
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Self-improving retrieval framework with RL routing, context engineering, MCP integration, agentic workflow, and persistent memory.
|
|
5
|
+
Author-email: Venkatkumar Rajan <venkatkumarr.vk99@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/adaptive-intelligence/
|
|
8
|
+
Project-URL: Documentation, https://github.com/VK-Ant/adaptive-intelligence#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/VK-Ant/adaptive-intelligence
|
|
10
|
+
Project-URL: Issues, https://github.com/VK-Ant/adaptive-intelligence/issues
|
|
11
|
+
Project-URL: PyPI, https://pypi.org/project/adaptive-intelligence/
|
|
12
|
+
Project-URL: Portfolio, https://vk-ant.github.io/Venkatkumar/
|
|
13
|
+
Keywords: rag,retrieval,reinforcement-learning,knowledge-graph,document-intelligence,adaptive,self-improving,llm,ai,nlp,evaluation,self-learning,context-engineering,mcp,agentic,memory,tool-use,multi-agent
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Provides-Extra: vector
|
|
29
|
+
Requires-Dist: chromadb>=0.4.0; extra == "vector"
|
|
30
|
+
Provides-Extra: openai
|
|
31
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
32
|
+
Provides-Extra: huggingface
|
|
33
|
+
Requires-Dist: transformers>=4.35.0; extra == "huggingface"
|
|
34
|
+
Requires-Dist: torch>=2.0.0; extra == "huggingface"
|
|
35
|
+
Provides-Extra: pdf
|
|
36
|
+
Requires-Dist: PyMuPDF>=1.23.0; extra == "pdf"
|
|
37
|
+
Provides-Extra: docx
|
|
38
|
+
Requires-Dist: python-docx>=1.0.0; extra == "docx"
|
|
39
|
+
Provides-Extra: xlsx
|
|
40
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "xlsx"
|
|
41
|
+
Provides-Extra: pptx
|
|
42
|
+
Requires-Dist: python-pptx>=0.6.21; extra == "pptx"
|
|
43
|
+
Provides-Extra: sql
|
|
44
|
+
Requires-Dist: sqlalchemy>=2.0.0; extra == "sql"
|
|
45
|
+
Provides-Extra: rerank
|
|
46
|
+
Requires-Dist: sentence-transformers>=2.2.0; extra == "rerank"
|
|
47
|
+
Provides-Extra: ocr
|
|
48
|
+
Requires-Dist: pytesseract>=0.3.10; extra == "ocr"
|
|
49
|
+
Requires-Dist: Pillow>=10.0; extra == "ocr"
|
|
50
|
+
Provides-Extra: all
|
|
51
|
+
Requires-Dist: chromadb>=0.4.0; extra == "all"
|
|
52
|
+
Requires-Dist: openai>=1.0.0; extra == "all"
|
|
53
|
+
Requires-Dist: transformers>=4.35.0; extra == "all"
|
|
54
|
+
Requires-Dist: torch>=2.0.0; extra == "all"
|
|
55
|
+
Requires-Dist: PyMuPDF>=1.23.0; extra == "all"
|
|
56
|
+
Requires-Dist: python-docx>=1.0.0; extra == "all"
|
|
57
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "all"
|
|
58
|
+
Requires-Dist: python-pptx>=0.6.21; extra == "all"
|
|
59
|
+
Requires-Dist: pytesseract>=0.3.10; extra == "all"
|
|
60
|
+
Requires-Dist: Pillow>=10.0; extra == "all"
|
|
61
|
+
Requires-Dist: sentence-transformers>=2.2.0; extra == "all"
|
|
62
|
+
Provides-Extra: dev
|
|
63
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
64
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
65
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
66
|
+
Requires-Dist: mypy>=1.5; extra == "dev"
|
|
67
|
+
Dynamic: license-file
|
|
68
|
+
|
|
69
|
+
# adaptive-intelligence
|
|
70
|
+
|
|
71
|
+
Self-improving retrieval framework that learns, remembers, and connects tools.
|
|
72
|
+
|
|
73
|
+
## What it does
|
|
74
|
+
|
|
75
|
+
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.
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Install
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install adaptive-intelligence # Zero deps (Ollama, no-LLM mode)
|
|
83
|
+
pip install adaptive-intelligence[vector] # + ChromaDB vector search
|
|
84
|
+
pip install adaptive-intelligence[openai] # + Any OpenAI-compatible API (10+ providers)
|
|
85
|
+
pip install adaptive-intelligence[huggingface] # + Local HuggingFace models
|
|
86
|
+
pip install adaptive-intelligence[all] # Everything
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Quick start
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from adaptive_intelligence import AdaptiveAI
|
|
93
|
+
|
|
94
|
+
engine = AdaptiveAI()
|
|
95
|
+
engine.ingest("./documents")
|
|
96
|
+
response = engine.ask("What are the key risks?")
|
|
97
|
+
print(response.answer)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Works without any LLM — returns relevant document excerpts. Add an LLM for synthesized answers.
|
|
101
|
+
|
|
102
|
+
## LLM providers
|
|
103
|
+
|
|
104
|
+
The library works with any LLM. The `[openai]` extras installs the OpenAI SDK which connects to any OpenAI-compatible API.
|
|
105
|
+
|
|
106
|
+
### Free (no credit card needed)
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
# Ollama — local, no extras needed
|
|
110
|
+
engine = AdaptiveAI()
|
|
111
|
+
|
|
112
|
+
# NVIDIA NIM — free cloud tier
|
|
113
|
+
engine = AdaptiveAI(
|
|
114
|
+
api_key="nvapi-...",
|
|
115
|
+
base_url="https://integrate.api.nvidia.com/v1",
|
|
116
|
+
llm_model="meta/llama-3.1-70b-instruct"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# Groq — free cloud tier
|
|
120
|
+
engine = AdaptiveAI(
|
|
121
|
+
api_key="gsk_...",
|
|
122
|
+
base_url="https://api.groq.com/openai/v1",
|
|
123
|
+
llm_model="llama-3.3-70b-versatile"
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Google Gemini — free tier
|
|
127
|
+
engine = AdaptiveAI(
|
|
128
|
+
api_key="...",
|
|
129
|
+
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
|
130
|
+
llm_model="gemini-2.0-flash"
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Together AI — free tier
|
|
134
|
+
engine = AdaptiveAI(
|
|
135
|
+
api_key="...",
|
|
136
|
+
base_url="https://api.together.xyz/v1",
|
|
137
|
+
llm_model="meta-llama/Llama-3-70b-chat-hf"
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Fireworks AI — free tier
|
|
141
|
+
engine = AdaptiveAI(
|
|
142
|
+
api_key="...",
|
|
143
|
+
base_url="https://api.fireworks.ai/inference/v1",
|
|
144
|
+
llm_model="accounts/fireworks/models/llama-v3p1-70b-instruct"
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# HuggingFace local — runs on your GPU, needs [huggingface] extras
|
|
148
|
+
engine = AdaptiveAI(
|
|
149
|
+
llm_backend="huggingface",
|
|
150
|
+
llm_model="Qwen/Qwen2.5-1.5B-Instruct"
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# No LLM — retrieval only, zero dependencies
|
|
154
|
+
engine = AdaptiveAI(llm_backend="none")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Paid
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# OpenAI
|
|
161
|
+
engine = AdaptiveAI(api_key="sk-...", llm_model="gpt-4o")
|
|
162
|
+
|
|
163
|
+
# Grok (xAI)
|
|
164
|
+
engine = AdaptiveAI(api_key="xai-...", base_url="https://api.x.ai/v1")
|
|
165
|
+
|
|
166
|
+
# Azure OpenAI
|
|
167
|
+
engine = AdaptiveAI(azure_endpoint="https://your.openai.azure.com/", api_key="...")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Self-hosted
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
# vLLM local server (free, runs on your GPU)
|
|
174
|
+
engine = AdaptiveAI(base_url="http://localhost:8000/v1")
|
|
175
|
+
|
|
176
|
+
# Any OpenAI-compatible server
|
|
177
|
+
engine = AdaptiveAI(base_url="http://your-server:8000/v1")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Any server that speaks the OpenAI-compatible API works with `[openai]` extras.
|
|
181
|
+
|
|
182
|
+
## Key features
|
|
183
|
+
|
|
184
|
+
### Context Engineering
|
|
185
|
+
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.
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
engine = AdaptiveAI(context_engineering=True)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### MCP Integration
|
|
192
|
+
Connect external tools. Register MCP servers, REST APIs, or Python functions. The RL policy learns which tools to call per query type.
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
# Register tools
|
|
196
|
+
engine.add_tool("financial", server="http://localhost:8081")
|
|
197
|
+
engine.add_tool("calculator", function=my_calc_function)
|
|
198
|
+
engine.add_tool("search", api_endpoint="https://api.example.com/search")
|
|
199
|
+
|
|
200
|
+
# List registered tools
|
|
201
|
+
engine.list_tools()
|
|
202
|
+
|
|
203
|
+
# Remove a tool
|
|
204
|
+
engine.remove_tool("search")
|
|
205
|
+
|
|
206
|
+
# Serve your retrieval as an MCP server
|
|
207
|
+
engine.serve_mcp(port=8080)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Agentic Workflow
|
|
211
|
+
Multi-round retrieval. The system retrieves, evaluates confidence, refines the query, calls tools, and retrieves again until the answer is sufficient.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
response = engine.ask("Analyze supply chain risks and mitigation", mode="agentic")
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Persistent Memory
|
|
218
|
+
Remembers across sessions. Routing patterns, user preferences, and facts persist to disk.
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
engine.remember("focus_area", "supply chain risk")
|
|
222
|
+
engine.recall("focus_area")
|
|
223
|
+
engine.search_memory("supply chain")
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Incremental Learning
|
|
227
|
+
Add new documents anytime. The RL policy, knowledge graph, and memory continue from their current state — no restart needed.
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
engine.ingest("./initial_docs") # Learn from initial set
|
|
231
|
+
engine.ingest("./quarterly_update.pdf") # Add later, system continues
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### RL-Based Retrieval Routing
|
|
235
|
+
Thompson Sampling or PPO learns which retrieval strategy works best per query type.
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
engine = AdaptiveAI(rl_algorithm="ppo")
|
|
239
|
+
engine = AdaptiveAI(pretrained_policy=True, domain="financial")
|
|
240
|
+
engine.export_policy("learned.json") # Transfer to another deployment
|
|
241
|
+
engine.import_policy("learned.json")
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Conditional Graph Activation
|
|
245
|
+
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.
|
|
246
|
+
|
|
247
|
+
### Vectorless Mode
|
|
248
|
+
No ChromaDB, no embeddings, zero dependencies. Uses page-level BM25 with page citations.
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
engine = AdaptiveAI(vectorless=True)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Structured Output
|
|
255
|
+
|
|
256
|
+
```python
|
|
257
|
+
response = engine.ask("Extract metrics", output_format="json")
|
|
258
|
+
response = engine.ask("List items", output_format="csv")
|
|
259
|
+
response = engine.ask("Summarize", output_format="yaml")
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### User Feedback
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
response = engine.ask("What are the risks?")
|
|
266
|
+
engine.feedback(response.query_id, "good") # +0.2 RL reward
|
|
267
|
+
engine.feedback(response.query_id, "bad") # -0.3 RL reward + prompt evolution
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Demos
|
|
271
|
+
|
|
272
|
+
### Colab notebook (no setup needed)
|
|
273
|
+
Run on free T4 GPU with no API key: `notebooks/adaptive_intelligence_v4_demo.ipynb`
|
|
274
|
+
|
|
275
|
+
### Local demos
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
cd demo_mcp_agenticai
|
|
279
|
+
pip install -r requirements.txt
|
|
280
|
+
python demo_basic.py # Basic usage + incremental learning
|
|
281
|
+
python demo_tools.py # Tool registry + cost optimization
|
|
282
|
+
python demo_agentic.py # Agentic multi-round retrieval
|
|
283
|
+
python demo_mcp_server.py # Serve as MCP server (terminal 1)
|
|
284
|
+
python demo_mcp_client.py # Connect to MCP server (terminal 2)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## How it works
|
|
288
|
+
|
|
289
|
+
1. **Understand** — Trigger interpreter classifies query type, complexity, domain, entities (no LLM call)
|
|
290
|
+
2. **Decide** — RL policy selects retrieval route, depth, graph activation, tools to call
|
|
291
|
+
3. **Retrieve** — Executes via vector, BM25, or page index with RRF fusion. Graph activates conditionally.
|
|
292
|
+
4. **Generate** — Cross-encoder reranks chunks. Context engineer assembles full context window. LLM generates.
|
|
293
|
+
5. **Learn** — 6 metrics evaluate response. Composite score = RL reward. Policy updates. Next query is better.
|
|
294
|
+
|
|
295
|
+
## Links
|
|
296
|
+
|
|
297
|
+
- **PyPI:** https://pypi.org/project/adaptive-intelligence/
|
|
298
|
+
- **GitHub:** https://github.com/VK-Ant/adaptive-intelligence
|
|
299
|
+
- **Paper:** https://www.researchgate.net/publication/405076088
|
|
300
|
+
- **Portfolio:** https://vk-ant.github.io/Venkatkumar
|
|
301
|
+
- **Also:** [llmevalkit](https://pypi.org/project/llmevalkit/) — 61 metrics for LLM evaluation
|
|
302
|
+
|
|
303
|
+
## Author
|
|
304
|
+
|
|
305
|
+
Venkatkumar Rajan | [@VK_Venkatkumar](https://linkedin.com/in/venkatkumarvk)
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
Apache License 2.0
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# adaptive-intelligence
|
|
2
|
+
|
|
3
|
+
Self-improving retrieval framework that learns, remembers, and connects tools.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install adaptive-intelligence # Zero deps (Ollama, no-LLM mode)
|
|
15
|
+
pip install adaptive-intelligence[vector] # + ChromaDB vector search
|
|
16
|
+
pip install adaptive-intelligence[openai] # + Any OpenAI-compatible API (10+ providers)
|
|
17
|
+
pip install adaptive-intelligence[huggingface] # + Local HuggingFace models
|
|
18
|
+
pip install adaptive-intelligence[all] # Everything
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick start
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from adaptive_intelligence import AdaptiveAI
|
|
25
|
+
|
|
26
|
+
engine = AdaptiveAI()
|
|
27
|
+
engine.ingest("./documents")
|
|
28
|
+
response = engine.ask("What are the key risks?")
|
|
29
|
+
print(response.answer)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Works without any LLM — returns relevant document excerpts. Add an LLM for synthesized answers.
|
|
33
|
+
|
|
34
|
+
## LLM providers
|
|
35
|
+
|
|
36
|
+
The library works with any LLM. The `[openai]` extras installs the OpenAI SDK which connects to any OpenAI-compatible API.
|
|
37
|
+
|
|
38
|
+
### Free (no credit card needed)
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
# Ollama — local, no extras needed
|
|
42
|
+
engine = AdaptiveAI()
|
|
43
|
+
|
|
44
|
+
# NVIDIA NIM — free cloud tier
|
|
45
|
+
engine = AdaptiveAI(
|
|
46
|
+
api_key="nvapi-...",
|
|
47
|
+
base_url="https://integrate.api.nvidia.com/v1",
|
|
48
|
+
llm_model="meta/llama-3.1-70b-instruct"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Groq — free cloud tier
|
|
52
|
+
engine = AdaptiveAI(
|
|
53
|
+
api_key="gsk_...",
|
|
54
|
+
base_url="https://api.groq.com/openai/v1",
|
|
55
|
+
llm_model="llama-3.3-70b-versatile"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Google Gemini — free tier
|
|
59
|
+
engine = AdaptiveAI(
|
|
60
|
+
api_key="...",
|
|
61
|
+
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
|
|
62
|
+
llm_model="gemini-2.0-flash"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# Together AI — free tier
|
|
66
|
+
engine = AdaptiveAI(
|
|
67
|
+
api_key="...",
|
|
68
|
+
base_url="https://api.together.xyz/v1",
|
|
69
|
+
llm_model="meta-llama/Llama-3-70b-chat-hf"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# Fireworks AI — free tier
|
|
73
|
+
engine = AdaptiveAI(
|
|
74
|
+
api_key="...",
|
|
75
|
+
base_url="https://api.fireworks.ai/inference/v1",
|
|
76
|
+
llm_model="accounts/fireworks/models/llama-v3p1-70b-instruct"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# HuggingFace local — runs on your GPU, needs [huggingface] extras
|
|
80
|
+
engine = AdaptiveAI(
|
|
81
|
+
llm_backend="huggingface",
|
|
82
|
+
llm_model="Qwen/Qwen2.5-1.5B-Instruct"
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# No LLM — retrieval only, zero dependencies
|
|
86
|
+
engine = AdaptiveAI(llm_backend="none")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Paid
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
# OpenAI
|
|
93
|
+
engine = AdaptiveAI(api_key="sk-...", llm_model="gpt-4o")
|
|
94
|
+
|
|
95
|
+
# Grok (xAI)
|
|
96
|
+
engine = AdaptiveAI(api_key="xai-...", base_url="https://api.x.ai/v1")
|
|
97
|
+
|
|
98
|
+
# Azure OpenAI
|
|
99
|
+
engine = AdaptiveAI(azure_endpoint="https://your.openai.azure.com/", api_key="...")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Self-hosted
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# vLLM local server (free, runs on your GPU)
|
|
106
|
+
engine = AdaptiveAI(base_url="http://localhost:8000/v1")
|
|
107
|
+
|
|
108
|
+
# Any OpenAI-compatible server
|
|
109
|
+
engine = AdaptiveAI(base_url="http://your-server:8000/v1")
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Any server that speaks the OpenAI-compatible API works with `[openai]` extras.
|
|
113
|
+
|
|
114
|
+
## Key features
|
|
115
|
+
|
|
116
|
+
### Context Engineering
|
|
117
|
+
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.
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
engine = AdaptiveAI(context_engineering=True)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### MCP Integration
|
|
124
|
+
Connect external tools. Register MCP servers, REST APIs, or Python functions. The RL policy learns which tools to call per query type.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Register tools
|
|
128
|
+
engine.add_tool("financial", server="http://localhost:8081")
|
|
129
|
+
engine.add_tool("calculator", function=my_calc_function)
|
|
130
|
+
engine.add_tool("search", api_endpoint="https://api.example.com/search")
|
|
131
|
+
|
|
132
|
+
# List registered tools
|
|
133
|
+
engine.list_tools()
|
|
134
|
+
|
|
135
|
+
# Remove a tool
|
|
136
|
+
engine.remove_tool("search")
|
|
137
|
+
|
|
138
|
+
# Serve your retrieval as an MCP server
|
|
139
|
+
engine.serve_mcp(port=8080)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Agentic Workflow
|
|
143
|
+
Multi-round retrieval. The system retrieves, evaluates confidence, refines the query, calls tools, and retrieves again until the answer is sufficient.
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
response = engine.ask("Analyze supply chain risks and mitigation", mode="agentic")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Persistent Memory
|
|
150
|
+
Remembers across sessions. Routing patterns, user preferences, and facts persist to disk.
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
engine.remember("focus_area", "supply chain risk")
|
|
154
|
+
engine.recall("focus_area")
|
|
155
|
+
engine.search_memory("supply chain")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Incremental Learning
|
|
159
|
+
Add new documents anytime. The RL policy, knowledge graph, and memory continue from their current state — no restart needed.
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
engine.ingest("./initial_docs") # Learn from initial set
|
|
163
|
+
engine.ingest("./quarterly_update.pdf") # Add later, system continues
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### RL-Based Retrieval Routing
|
|
167
|
+
Thompson Sampling or PPO learns which retrieval strategy works best per query type.
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
engine = AdaptiveAI(rl_algorithm="ppo")
|
|
171
|
+
engine = AdaptiveAI(pretrained_policy=True, domain="financial")
|
|
172
|
+
engine.export_policy("learned.json") # Transfer to another deployment
|
|
173
|
+
engine.import_policy("learned.json")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Conditional Graph Activation
|
|
177
|
+
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.
|
|
178
|
+
|
|
179
|
+
### Vectorless Mode
|
|
180
|
+
No ChromaDB, no embeddings, zero dependencies. Uses page-level BM25 with page citations.
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
engine = AdaptiveAI(vectorless=True)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Structured Output
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
response = engine.ask("Extract metrics", output_format="json")
|
|
190
|
+
response = engine.ask("List items", output_format="csv")
|
|
191
|
+
response = engine.ask("Summarize", output_format="yaml")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### User Feedback
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
response = engine.ask("What are the risks?")
|
|
198
|
+
engine.feedback(response.query_id, "good") # +0.2 RL reward
|
|
199
|
+
engine.feedback(response.query_id, "bad") # -0.3 RL reward + prompt evolution
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Demos
|
|
203
|
+
|
|
204
|
+
### Colab notebook (no setup needed)
|
|
205
|
+
Run on free T4 GPU with no API key: `notebooks/adaptive_intelligence_v4_demo.ipynb`
|
|
206
|
+
|
|
207
|
+
### Local demos
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
cd demo_mcp_agenticai
|
|
211
|
+
pip install -r requirements.txt
|
|
212
|
+
python demo_basic.py # Basic usage + incremental learning
|
|
213
|
+
python demo_tools.py # Tool registry + cost optimization
|
|
214
|
+
python demo_agentic.py # Agentic multi-round retrieval
|
|
215
|
+
python demo_mcp_server.py # Serve as MCP server (terminal 1)
|
|
216
|
+
python demo_mcp_client.py # Connect to MCP server (terminal 2)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## How it works
|
|
220
|
+
|
|
221
|
+
1. **Understand** — Trigger interpreter classifies query type, complexity, domain, entities (no LLM call)
|
|
222
|
+
2. **Decide** — RL policy selects retrieval route, depth, graph activation, tools to call
|
|
223
|
+
3. **Retrieve** — Executes via vector, BM25, or page index with RRF fusion. Graph activates conditionally.
|
|
224
|
+
4. **Generate** — Cross-encoder reranks chunks. Context engineer assembles full context window. LLM generates.
|
|
225
|
+
5. **Learn** — 6 metrics evaluate response. Composite score = RL reward. Policy updates. Next query is better.
|
|
226
|
+
|
|
227
|
+
## Links
|
|
228
|
+
|
|
229
|
+
- **PyPI:** https://pypi.org/project/adaptive-intelligence/
|
|
230
|
+
- **GitHub:** https://github.com/VK-Ant/adaptive-intelligence
|
|
231
|
+
- **Paper:** https://www.researchgate.net/publication/405076088
|
|
232
|
+
- **Portfolio:** https://vk-ant.github.io/Venkatkumar
|
|
233
|
+
- **Also:** [llmevalkit](https://pypi.org/project/llmevalkit/) — 61 metrics for LLM evaluation
|
|
234
|
+
|
|
235
|
+
## Author
|
|
236
|
+
|
|
237
|
+
Venkatkumar Rajan | [@VK_Venkatkumar](https://linkedin.com/in/venkatkumarvk)
|
|
238
|
+
|
|
239
|
+
## License
|
|
240
|
+
|
|
241
|
+
Apache License 2.0
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Adaptive Intelligence v4 — Self-Improving Retrieval Orchestration Framework
|
|
3
|
+
|
|
4
|
+
v4: Context engineering, MCP integration, agentic workflow,
|
|
5
|
+
persistent memory, incremental learning, tool registry.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from adaptive_intelligence import AdaptiveAI
|
|
9
|
+
|
|
10
|
+
engine = AdaptiveAI()
|
|
11
|
+
engine.ingest("./documents")
|
|
12
|
+
response = engine.ask("What are the key risks?")
|
|
13
|
+
|
|
14
|
+
# v4: Add tools
|
|
15
|
+
engine.add_tool("financial", server="http://localhost:8081")
|
|
16
|
+
|
|
17
|
+
# v4: Agentic mode
|
|
18
|
+
response = engine.ask("Deep research on risks", mode="agentic")
|
|
19
|
+
|
|
20
|
+
# v4: Memory persists across sessions
|
|
21
|
+
engine.remember("user_preference", "prefers detailed analysis")
|
|
22
|
+
|
|
23
|
+
# v4: MCP server
|
|
24
|
+
engine.serve_mcp(port=8080)
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
__version__ = "4.0.0"
|
|
28
|
+
__author__ = "Venkatkumar Rajan"
|
|
29
|
+
|
|
30
|
+
from adaptive_intelligence.core.engine import AdaptiveAI
|
|
31
|
+
from adaptive_intelligence.core.response import AdaptiveResponse
|
|
32
|
+
|
|
33
|
+
__all__ = ["AdaptiveAI", "AdaptiveResponse"]
|