adaptive-intelligence 3.0.0__tar.gz → 3.0.1__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.
Files changed (43) hide show
  1. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/PKG-INFO +2 -2
  2. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/README.md +1 -1
  3. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/__init__.py +1 -1
  4. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/core/engine.py +28 -15
  5. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/llm/__init__.py +71 -9
  6. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence.egg-info/PKG-INFO +2 -2
  7. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/pyproject.toml +1 -1
  8. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_core.py +1 -1
  9. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/LICENSE +0 -0
  10. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/core/__init__.py +0 -0
  11. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/core/config.py +0 -0
  12. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/core/response.py +0 -0
  13. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/evaluation/__init__.py +0 -0
  14. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/graph/__init__.py +0 -0
  15. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/indexes/__init__.py +0 -0
  16. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/indexes/base.py +0 -0
  17. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/indexes/keyword_index.py +0 -0
  18. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/indexes/page_index.py +0 -0
  19. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/indexes/vector_index.py +0 -0
  20. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/ingestion/__init__.py +0 -0
  21. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/ingestion/chunker.py +0 -0
  22. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/ingestion/engine.py +0 -0
  23. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/ingestion/parser.py +0 -0
  24. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/memory/__init__.py +0 -0
  25. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/prompts/__init__.py +0 -0
  26. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/query/__init__.py +0 -0
  27. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/rl/__init__.py +0 -0
  28. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/rl/multi_query.py +0 -0
  29. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/rl/ppo.py +0 -0
  30. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/rl/pretrained.py +0 -0
  31. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/rl/reranker.py +0 -0
  32. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/security/__init__.py +0 -0
  33. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence/utils/__init__.py +0 -0
  34. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence.egg-info/SOURCES.txt +0 -0
  35. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence.egg-info/dependency_links.txt +0 -0
  36. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence.egg-info/requires.txt +0 -0
  37. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/adaptive_intelligence.egg-info/top_level.txt +0 -0
  38. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/setup.cfg +0 -0
  39. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_evaluation.py +0 -0
  40. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_graph.py +0 -0
  41. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_ingestion.py +0 -0
  42. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_query.py +0 -0
  43. {adaptive_intelligence-3.0.0 → adaptive_intelligence-3.0.1}/tests/test_rl.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adaptive-intelligence
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Self-improving retrieval orchestration framework with RL-based routing, conditional graph activation, and evaluation-driven learning.
5
5
  Author-email: Venkatkumar Rajan <venkatkumarr.vk99@gmail.com>
6
6
  License: Apache-2.0
@@ -66,7 +66,7 @@ Dynamic: license-file
66
66
 
67
67
  Self-improving retrieval orchestration framework. Drop documents, ask questions, the system learns how to retrieve better over time.
68
68
 
69
- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v3_demo.ipynb)
69
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v2_three_way.ipynb)
70
70
 
71
71
  ## Install
72
72
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Self-improving retrieval orchestration framework. Drop documents, ask questions, the system learns how to retrieve better over time.
4
4
 
5
- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v3_demo.ipynb)
5
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v2_three_way.ipynb)
6
6
 
7
7
  ## Install
8
8
 
@@ -15,7 +15,7 @@ Usage:
15
15
  engine = AdaptiveAI(rl_algorithm="ppo", reranking=True, pretrained_policy=True)
16
16
  """
17
17
 
18
- __version__ = "3.0.0"
18
+ __version__ = "3.0.1"
19
19
  __author__ = "Venkatkumar Rajan"
20
20
 
21
21
  from adaptive_intelligence.core.engine import AdaptiveAI
@@ -74,7 +74,7 @@ class AdaptiveAI:
74
74
 
75
75
  # Setup
76
76
  setup_logging(config.log_level, config.log_file)
77
- logger.info(f"Initializing Adaptive Intelligence v3.0.0")
77
+ logger.info(f"Initializing Adaptive Intelligence v3.0.1")
78
78
 
79
79
  self._storage_dir = Path(config.storage_dir)
80
80
  self._storage_dir.mkdir(parents=True, exist_ok=True)
@@ -224,8 +224,12 @@ class AdaptiveAI:
224
224
  azure_endpoint=self.config.azure_endpoint,
225
225
  deployment_name=self.config.deployment_name,
226
226
  )
227
+ # Quick availability check for Ollama
228
+ if self.config.llm_backend.value == "ollama" and not self._llm.is_available():
229
+ logger.info("Ollama not running. Using retrieval-only mode.")
230
+ self._llm = None
227
231
  except Exception as e:
228
- logger.warning(f"LLM init failed: {e}. Fallback mode active.")
232
+ logger.info(f"LLM not available ({e}). Using retrieval-only mode.")
229
233
  self._llm = None
230
234
 
231
235
  # ─── INGESTION ─────────────────────────────────────────
@@ -675,20 +679,29 @@ class AdaptiveAI:
675
679
 
676
680
  def _fallback_answer(self, query: str, chunks: List[Chunk]) -> str:
677
681
  if not chunks:
678
- return "I could not find relevant information to answer this query."
682
+ return "No relevant information found in the ingested documents for this query."
679
683
 
680
- parts = ["Based on the available documents:\n"]
684
+ # Build a clean, readable answer from retrieved chunks
685
+ parts = []
681
686
  for i, chunk in enumerate(chunks[:5]):
682
- source = chunk.source_document or "Unknown"
683
- page = f", Page {chunk.page_number}" if chunk.page_number else ""
684
- preview = chunk.content[:300].strip()
685
- parts.append(f"[{i+1}] From {source}{page}:\n{preview}\n")
686
-
687
- parts.append(
688
- "\nNote: Direct excerpt from sources. "
689
- "Connect an LLM provider for synthesized answers."
690
- )
691
- return "\n".join(parts)
687
+ source = chunk.source_document or "document"
688
+ page = f" (page {chunk.page_number})" if chunk.page_number else ""
689
+ content = chunk.content.strip()
690
+
691
+ # Clean up content - take meaningful portion
692
+ if len(content) > 400:
693
+ # Cut at sentence boundary
694
+ cut = content[:400]
695
+ last_period = cut.rfind(".")
696
+ if last_period > 100:
697
+ content = cut[:last_period + 1]
698
+ else:
699
+ content = cut + "..."
700
+
701
+ parts.append(f"From {source}{page}:\n{content}")
702
+
703
+ answer = "\n\n".join(parts)
704
+ return answer
692
705
 
693
706
  def _extract_citations(self, answer: str, chunks: List[Chunk]) -> List[Citation]:
694
707
  citations = []
@@ -817,7 +830,7 @@ class AdaptiveAI:
817
830
 
818
831
  def status(self) -> Dict[str, Any]:
819
832
  return {
820
- "version": "3.0.0",
833
+ "version": "3.0.1",
821
834
  "vectorless": self._vectorless,
822
835
  "documents_indexed": self.page_index.count() if self._vectorless else (self.vector_index.count() if self.vector_index else 0),
823
836
  "total_queries": self._total_queries,
@@ -285,11 +285,20 @@ class HuggingFaceProvider(BaseLLMProvider):
285
285
 
286
286
  start = time.time()
287
287
 
288
- full_prompt = ""
289
- if system_prompt:
290
- full_prompt = f"System: {system_prompt}\n\nUser: {prompt}\n\nAssistant:"
291
- else:
292
- full_prompt = f"User: {prompt}\n\nAssistant:"
288
+ # Use chat template if available, else simple format
289
+ try:
290
+ messages = []
291
+ if system_prompt:
292
+ messages.append({"role": "system", "content": system_prompt})
293
+ messages.append({"role": "user", "content": prompt})
294
+ full_prompt = self._tokenizer.apply_chat_template(
295
+ messages, tokenize=False, add_generation_prompt=True
296
+ )
297
+ except Exception:
298
+ if system_prompt:
299
+ full_prompt = f"System: {system_prompt}\n\nUser: {prompt}\n\nAssistant:"
300
+ else:
301
+ full_prompt = f"User: {prompt}\n\nAssistant:"
293
302
 
294
303
  inputs = self._tokenizer(full_prompt, return_tensors="pt", truncation=True, max_length=4096)
295
304
  inputs = {k: v.to(self._model.device) for k, v in inputs.items()}
@@ -298,18 +307,24 @@ class HuggingFaceProvider(BaseLLMProvider):
298
307
  with torch.no_grad():
299
308
  outputs = self._model.generate(
300
309
  **inputs,
301
- max_new_tokens=max_tokens,
310
+ max_new_tokens=min(max_tokens, 1024),
302
311
  temperature=max(temperature, 0.01),
303
312
  do_sample=temperature > 0,
304
- pad_token_id=self._tokenizer.pad_token_id,
313
+ pad_token_id=self._tokenizer.pad_token_id or self._tokenizer.eos_token_id,
314
+ repetition_penalty=1.3,
315
+ no_repeat_ngram_size=4,
305
316
  )
306
317
 
307
318
  generated = outputs[0][input_len:]
308
- text = self._tokenizer.decode(generated, skip_special_tokens=True)
319
+ text = self._tokenizer.decode(generated, skip_special_tokens=True).strip()
320
+
321
+ # Clean garbled output
322
+ text = self._clean_output(text)
323
+
309
324
  latency = time.time() - start
310
325
 
311
326
  return LLMResponse(
312
- text=text.strip(),
327
+ text=text,
313
328
  model=self.model_name,
314
329
  provider="huggingface",
315
330
  input_tokens=input_len,
@@ -317,6 +332,53 @@ class HuggingFaceProvider(BaseLLMProvider):
317
332
  latency_seconds=latency,
318
333
  )
319
334
 
335
+ @staticmethod
336
+ def _clean_output(text: str) -> str:
337
+ """Remove garbled/repetitive content from model output."""
338
+ if not text:
339
+ return text
340
+
341
+ lines = text.split("\n")
342
+ clean_lines = []
343
+ seen = set()
344
+
345
+ for line in lines:
346
+ stripped = line.strip()
347
+ # Skip empty or very short repeated lines
348
+ if not stripped:
349
+ if clean_lines and clean_lines[-1] != "":
350
+ clean_lines.append("")
351
+ continue
352
+
353
+ # Skip if line is mostly non-alphabetic (garbled)
354
+ alpha_ratio = sum(c.isalpha() or c.isspace() for c in stripped) / max(len(stripped), 1)
355
+ if alpha_ratio < 0.5 and len(stripped) > 20:
356
+ break # Stop at first garbled line
357
+
358
+ # Skip repeated lines
359
+ key = stripped.lower()[:80]
360
+ if key in seen and len(key) > 10:
361
+ continue
362
+ seen.add(key)
363
+
364
+ # Stop if line is just repeated characters
365
+ if len(set(stripped)) < 3 and len(stripped) > 5:
366
+ break
367
+
368
+ clean_lines.append(line)
369
+
370
+ result = "\n".join(clean_lines).strip()
371
+
372
+ # If result is too short after cleaning, return what we have
373
+ if len(result) < 10 and len(text) > 10:
374
+ # Take first 500 chars of original, cut at last sentence
375
+ result = text[:500]
376
+ last_period = result.rfind(".")
377
+ if last_period > 50:
378
+ result = result[:last_period + 1]
379
+
380
+ return result
381
+
320
382
 
321
383
  class LLMManager:
322
384
  """Factory and manager for LLM providers."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: adaptive-intelligence
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Self-improving retrieval orchestration framework with RL-based routing, conditional graph activation, and evaluation-driven learning.
5
5
  Author-email: Venkatkumar Rajan <venkatkumarr.vk99@gmail.com>
6
6
  License: Apache-2.0
@@ -66,7 +66,7 @@ Dynamic: license-file
66
66
 
67
67
  Self-improving retrieval orchestration framework. Drop documents, ask questions, the system learns how to retrieve better over time.
68
68
 
69
- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v3_demo.ipynb)
69
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VK-Ant/adaptive-intelligence/blob/main/notebooks/adaptive_intelligence_v2_three_way.ipynb)
70
70
 
71
71
  ## Install
72
72
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "adaptive-intelligence"
7
- version = "3.0.0"
7
+ version = "3.0.1"
8
8
  description = "Self-improving retrieval orchestration framework with RL-based routing, conditional graph activation, and evaluation-driven learning."
9
9
  readme = "README.md"
10
10
  license = {text = "Apache-2.0"}
@@ -118,7 +118,7 @@ class TestAdaptiveAIInit:
118
118
  engine = AdaptiveAI(storage_dir=d, log_level="WARNING")
119
119
  assert engine.config.llm_backend == LLMBackend.OLLAMA
120
120
  status = engine.status()
121
- assert status["version"] == "3.0.0"
121
+ assert status["version"] == "3.0.1"
122
122
 
123
123
  def test_kwargs_init(self):
124
124
  with tempfile.TemporaryDirectory() as d: