Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3020e31
Merge pull request #122 from rootcodelabs/wip
nuwangeek Feb 20, 2026
6e5c22c
remove unwanted file
nuwangeek Feb 20, 2026
38d0533
updated changes
nuwangeek Feb 20, 2026
72b8ae1
fixed requested changes
nuwangeek Feb 20, 2026
9b7bc7b
fixed issue
nuwangeek Feb 20, 2026
46dd6c4
Merge pull request #123 from rootcodelabs/llm-316
nuwangeek Feb 21, 2026
068f4e0
Merge pull request #124 from buerokratt/wip
Thirunayan22 Feb 21, 2026
a2084e5
service workflow implementation without calling service endpoints
nuwangeek Feb 24, 2026
5216c09
Merge pull request #126 from rootcodelabs/wip
nuwangeek Feb 24, 2026
864ad30
fixed requested changes
nuwangeek Feb 24, 2026
25f9614
fixed issues
nuwangeek Feb 24, 2026
69c1279
protocol related requested changes
nuwangeek Feb 24, 2026
07f2e0f
fixed requested changes
nuwangeek Feb 24, 2026
f63f777
update time tracking
nuwangeek Feb 25, 2026
5429bc0
added time tracking and reloacate input guardrail before toolclassifiier
nuwangeek Feb 25, 2026
721263a
fixed issue
nuwangeek Feb 25, 2026
6ed02d1
Merge pull request #127 from buerokratt/wip
nuwangeek Feb 25, 2026
7238baa
Merge branch 'optimization/llm-304' into wip
nuwangeek Feb 25, 2026
ae7cfa0
Merge pull request #128 from rootcodelabs/wip
nuwangeek Feb 25, 2026
f8a82b6
fixed issue
nuwangeek Feb 25, 2026
3b89fba
added hybrid search for the service detection
nuwangeek Feb 26, 2026
789f062
update tool classifier
nuwangeek Mar 1, 2026
609e6d5
fixing merge conflicts
nuwangeek Mar 1, 2026
a30c52d
Merge pull request #129 from buerokratt/wip
nuwangeek Mar 1, 2026
8dfc155
Merge pull request #130 from rootcodelabs/wip
nuwangeek Mar 1, 2026
3d7fb85
updated intent data enrichment and service classification flow perfor…
nuwangeek Mar 2, 2026
bee9fbf
fixed issue
nuwangeek Mar 2, 2026
4888045
Merge pull request #131 from rootcodelabs/optimization/data-enrichment
nuwangeek Mar 3, 2026
0a0806f
optimize first user query response generation time
nuwangeek Mar 3, 2026
1eb8b47
fixed pr reviewed issues
nuwangeek Mar 3, 2026
94b4f39
Merge pull request #132 from buerokratt/wip
nuwangeek Mar 3, 2026
82b3fe5
Merge branch 'optimization/vector-indexer' into wip
nuwangeek Mar 3, 2026
1b4ada9
Merge pull request #134 from buerokratt/wip
nuwangeek Mar 3, 2026
bb1601f
service integration
nuwangeek Mar 8, 2026
9ce1da2
context based response generation flow
nuwangeek Mar 9, 2026
d647f86
fixed pr review suggested issues
nuwangeek Mar 9, 2026
d67214e
Merge pull request #135 from rootcodelabs/llm-309
nuwangeek Mar 9, 2026
b90ab52
Merge pull request #136 from rootcodelabs/llm-310
nuwangeek Mar 9, 2026
6c46d3c
removed service project layer
nuwangeek Mar 10, 2026
d3e1494
fixed issues
nuwangeek Mar 12, 2026
4add446
Merge pull request #137 from rootcodelabs/llm-310
nuwangeek Mar 12, 2026
c2ef115
delete unnessary files
nuwangeek Mar 13, 2026
97f6f1a
added requested changes
nuwangeek Mar 13, 2026
0be284e
Merge pull request #138 from buerokratt/wip
nuwangeek Mar 17, 2026
a32ca6d
Merge branch 'llm/service-integration' into wip
nuwangeek Mar 17, 2026
4276e7d
Merge pull request #140 from buerokratt/wip
nuwangeek Mar 18, 2026
24259a9
Merge pull request #141 from buerokratt/wip
nuwangeek Mar 20, 2026
8e3da13
fixed ruff check issues in src/contextual_retrieval
nuwangeek Mar 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ ignore = []
fixable = ["ALL"]
unfixable = []

# Per-file ignores for special cases
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
"ANN", # Ignore all missing type annotations (ANN001, ANN201, etc.)
"T201", # Allow print statements
]

"src/models/request_models.py" = ["N815"] # camelCase fields required for API contract
"src/optimization/optimized_module_loader.py" = ["N815"] # Pydantic model fields
"src/optimization/optimizers/generator_optimizer.py" = ["N815"] # Pydantic model fields
"src/response_generator/response_generate.py" = ["N815", "ANN401"] # Pydantic model fields + DSPy streamify Any type

# Library interface patterns - legitimate Any usage
"src/contextual_retrieval/contextual_retrieval_api_client.py" = ["ANN401"] # httpx **kwargs pass-through
"src/guardrails/dspy_nemo_adapter.py" = ["ANN401"] # LangChain LLM interface + DSPy dynamic types
"src/llm_orchestrator_config/context_manager.py" = ["ANN401"] # MockResponse with dynamic attributes
"src/optimization/metrics/*.py" = ["ANN401"] # DSPy optimizer trace parameter (internal type)
"byk-stack-setup/script.py" = ["T201"] # CLI script uses print

[tool.ruff.format]
# Like Black, use double quotes for strings.
Expand Down Expand Up @@ -123,4 +141,4 @@ exclude = [
]

# --- Global strictness ---
typeCheckingMode = "standard" # Standard typechecking mode
typeCheckingMode = "standard" # Standard typechecking mode
11 changes: 7 additions & 4 deletions src/contextual_retrieval/bm25_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
when collection data changes.
"""

from typing import List, Dict, Any, Optional, Set
from typing import List, Dict, Any, Optional, Set, TYPE_CHECKING
from loguru import logger
from rank_bm25 import BM25Okapi
import re
Expand All @@ -20,13 +20,16 @@
)
from contextual_retrieval.config import ConfigLoader, ContextualRetrievalConfig

if TYPE_CHECKING:
from contextual_retrieval.contextual_retrieval_api_client import HTTPClientManager


class SmartBM25Search:
"""In-memory BM25 search with smart refresh capabilities."""

def __init__(
self, qdrant_url: str, config: Optional["ContextualRetrievalConfig"] = None
):
) -> None:
self.qdrant_url = qdrant_url
self._config = config if config is not None else ConfigLoader.load_config()
self._http_client_manager = None
Expand All @@ -40,7 +43,7 @@ def __init__(
# Strong references to background tasks to prevent premature GC
self._background_tasks: Set[asyncio.Task[None]] = set()

async def _get_http_client_manager(self):
async def _get_http_client_manager(self) -> "HTTPClientManager":
"""Get the HTTP client manager instance."""
if self._http_client_manager is None:
self._http_client_manager = await get_http_client_manager()
Expand Down Expand Up @@ -356,7 +359,7 @@ def _tokenize_text(self, text: str) -> List[str]:
tokens = self.tokenizer_pattern.findall(text.lower())
return tokens

async def close(self):
async def close(self) -> None:
"""Close HTTP client."""
if self._http_client_manager:
await self._http_client_manager.close()
2 changes: 1 addition & 1 deletion src/contextual_retrieval/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HttpClientConstants:
DEFAULT_FAILURE_THRESHOLD = 5
DEFAULT_RECOVERY_TIMEOUT = 60.0

# Timeouts (seconds)
# Timeouts in seconds
DEFAULT_READ_TIMEOUT = 30.0
DEFAULT_CONNECT_TIMEOUT = 10.0
DEFAULT_WRITE_TIMEOUT = 10.0
Expand Down
6 changes: 3 additions & 3 deletions src/contextual_retrieval/contextual_retrieval_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class ServiceResilienceManager:
"""Service resilience manager with circuit breaker functionality for HTTP requests."""

def __init__(self, config: Optional["ContextualRetrievalConfig"] = None):
def __init__(self, config: Optional["ContextualRetrievalConfig"] = None) -> None:
# Load configuration if not provided
if config is None:
config = ConfigLoader.load_config()
Expand Down Expand Up @@ -81,7 +81,7 @@ class HTTPClientManager:
_instance: Optional["HTTPClientManager"] = None
_lock = asyncio.Lock()

def __init__(self, config: Optional["ContextualRetrievalConfig"] = None):
def __init__(self, config: Optional["ContextualRetrievalConfig"] = None) -> None:
"""Initialize HTTP client manager."""
# Load configuration if not provided
self._config = config if config is not None else ConfigLoader.load_config()
Expand Down Expand Up @@ -169,7 +169,7 @@ async def get_client(
SecureErrorHandler.sanitize_error_message(
e, "HTTP client initialization"
)
)
) from e

return self._client

Expand Down
12 changes: 7 additions & 5 deletions src/contextual_retrieval/contextual_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
config_path: Optional[str] = None,
llm_service: Optional["LLMOrchestrationService"] = None,
shared_bm25: Optional[SmartBM25Search] = None,
):
) -> None:
"""
Initialize contextual retriever.

Expand Down Expand Up @@ -120,7 +120,7 @@ async def initialize(self) -> bool:
logger.error(f"Failed to initialize Contextual Retriever: {e}")
return False

def _get_session_llm_service(self):
def _get_session_llm_service(self) -> "LLMOrchestrationService":
"""
Get cached LLM service for current retrieval session.
Uses injected service if available, creates new instance as fallback.
Expand All @@ -140,7 +140,7 @@ def _get_session_llm_service(self):

return self._session_llm_service

def _clear_session_cache(self):
def _clear_session_cache(self) -> None:
"""Clear cached connections at end of retrieval session."""
if self._session_llm_service is not None:
logger.debug("Clearing session LLM service cache")
Expand Down Expand Up @@ -374,7 +374,9 @@ async def _execute_batch_query_searches(
self._search_single_query_with_embedding(
query, i, embedding, collections, limit
)
for i, (query, embedding) in enumerate(zip(queries, batch_embeddings))
for i, (query, embedding) in enumerate(
zip(queries, batch_embeddings, strict=True)
)
]

# Execute all searches in parallel
Expand Down Expand Up @@ -621,7 +623,7 @@ async def health_check(self) -> Dict[str, Any]:

return health_status

async def close(self):
async def close(self) -> None:
"""Clean up resources."""
try:
await self.provider_detection.close()
Expand Down
11 changes: 7 additions & 4 deletions src/contextual_retrieval/provider_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- No hardcoded weights or preferences
"""

from typing import List, Optional, Dict, Any
from typing import List, Optional, Dict, Any, TYPE_CHECKING
from loguru import logger
from contextual_retrieval.contextual_retrieval_api_client import get_http_client_manager
from contextual_retrieval.error_handler import SecureErrorHandler
Expand All @@ -18,18 +18,21 @@
)
from contextual_retrieval.config import ConfigLoader, ContextualRetrievalConfig

if TYPE_CHECKING:
from contextual_retrieval.contextual_retrieval_api_client import HTTPClientManager


class DynamicProviderDetection:
"""Dynamic collection selection without hardcoded preferences."""

def __init__(
self, qdrant_url: str, config: Optional["ContextualRetrievalConfig"] = None
):
) -> None:
self.qdrant_url = qdrant_url
self._config = config if config is not None else ConfigLoader.load_config()
self._http_client_manager = None

async def _get_http_client_manager(self):
async def _get_http_client_manager(self) -> "HTTPClientManager":
"""Get the HTTP client manager instance."""
if self._http_client_manager is None:
self._http_client_manager = await get_http_client_manager()
Expand Down Expand Up @@ -212,7 +215,7 @@ async def get_collection_stats(self) -> Dict[str, Any]:

return stats

async def close(self):
async def close(self) -> None:
"""Close HTTP client."""
if self._http_client_manager:
await self._http_client_manager.close()
11 changes: 7 additions & 4 deletions src/contextual_retrieval/qdrant_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
existing contextual embeddings created by the vector indexer.
"""

from typing import List, Dict, Any, Optional, Protocol
from typing import List, Dict, Any, Optional, Protocol, TYPE_CHECKING
from loguru import logger
import asyncio
from contextual_retrieval.contextual_retrieval_api_client import get_http_client_manager
Expand All @@ -17,6 +17,9 @@
)
from contextual_retrieval.config import ConfigLoader, ContextualRetrievalConfig

if TYPE_CHECKING:
from contextual_retrieval.contextual_retrieval_api_client import HTTPClientManager


class LLMServiceProtocol(Protocol):
"""Protocol defining the interface required from LLM service for embedding operations."""
Expand Down Expand Up @@ -47,12 +50,12 @@ class QdrantContextualSearch:

def __init__(
self, qdrant_url: str, config: Optional["ContextualRetrievalConfig"] = None
):
) -> None:
self.qdrant_url = qdrant_url
self._config = config if config is not None else ConfigLoader.load_config()
self._http_client_manager = None

async def _get_http_client_manager(self):
async def _get_http_client_manager(self) -> "HTTPClientManager":
"""Get the HTTP client manager instance."""
if self._http_client_manager is None:
self._http_client_manager = await get_http_client_manager()
Expand Down Expand Up @@ -345,7 +348,7 @@ def get_embeddings_for_queries_batch(
logger.error(f"Failed to get batch embeddings: {e}")
return None

async def close(self):
async def close(self) -> None:
"""Close HTTP client."""
if self._http_client_manager:
await self._http_client_manager.close()
Expand Down
4 changes: 2 additions & 2 deletions src/contextual_retrieval/rank_fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class DynamicRankFusion:
"""Dynamic score fusion without hardcoded collection weights."""

def __init__(self, config: Optional["ContextualRetrievalConfig"] = None):
def __init__(self, config: Optional["ContextualRetrievalConfig"] = None) -> None:
"""
Initialize rank fusion with configuration.

Expand Down Expand Up @@ -184,7 +184,7 @@ def _reciprocal_rank_fusion(

# Calculate final fused scores
fused_results: List[Dict[str, Any]] = []
for chunk_id, data in chunk_scores.items():
for data in chunk_scores.values():
chunk = data["chunk"].copy()

# Calculate fused RRF score
Expand Down
Loading