-
Notifications
You must be signed in to change notification settings - Fork 94
LCORE-1444: Solr enrichment not working in library mode #1335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,11 @@ | |
| from llama_stack_client import APIConnectionError, AsyncLlamaStackClient # type: ignore | ||
|
|
||
| from configuration import configuration | ||
| from llama_stack_configuration import enrich_byok_rag, YamlDumper | ||
| from llama_stack_configuration import YamlDumper, enrich_byok_rag, enrich_solr | ||
| from log import get_logger | ||
| from models.config import LlamaStackConfiguration | ||
| from models.responses import ServiceUnavailableResponse | ||
| from utils.types import Singleton | ||
| from log import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
@@ -52,14 +52,9 @@ async def _load_library_client(self, config: LlamaStackConfiguration) -> None: | |
| ) | ||
| logger.info("Using Llama stack as library client") | ||
|
|
||
| byok_rag = [b.model_dump() for b in configuration.configuration.byok_rag] | ||
|
|
||
| if byok_rag: # BYOK RAG configured - enrich and store enriched path | ||
| self._config_path = self._enrich_library_config( | ||
| config.library_client_config_path, byok_rag | ||
| ) | ||
| else: # No RAG - store original path | ||
| self._config_path = config.library_client_config_path | ||
| self._config_path = self._enrich_library_config( | ||
| config.library_client_config_path | ||
| ) | ||
|
|
||
| client = AsyncLlamaStackAsLibraryClient(self._config_path) | ||
| await client.initialize() | ||
|
|
@@ -78,21 +73,22 @@ def _load_service_client(self, config: LlamaStackConfiguration) -> None: | |
| base_url=base_url, api_key=api_key, timeout=config.timeout | ||
| ) | ||
|
|
||
| def _enrich_library_config( | ||
| self, input_config_path: str, byok_rag: list[dict] | ||
| ) -> str: | ||
| """Enrich llama-stack config with BYOK RAG settings. | ||
|
|
||
| Only called when BYOK RAG is configured. | ||
| """ | ||
| def _enrich_library_config(self, input_config_path: str) -> str: | ||
| """Enrich llama-stack config with BYOK RAG and OKP Solr settings.""" | ||
| try: | ||
| with open(input_config_path, "r", encoding="utf-8") as f: | ||
| ls_config = yaml.safe_load(f) | ||
| except (OSError, yaml.YAMLError) as e: | ||
| logger.warning("Failed to read llama-stack config: %s", e) | ||
| return input_config_path | ||
|
|
||
| enrich_byok_rag(ls_config, byok_rag) | ||
| config = configuration.configuration | ||
|
|
||
| # Enrichment: BYOK RAG | ||
| enrich_byok_rag(ls_config, [b.model_dump() for b in config.byok_rag]) | ||
|
|
||
| # Enrichment: Solr - enabled when "okp" appears in either inline or tool list | ||
| enrich_solr(ls_config, config.rag.model_dump(), config.okp.model_dump()) | ||
|
Comment on lines
79
to
+91
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: For an empty YAML stream/document (e.g., 🏁 Script executed: # Find enrichment helper functions
fd "\.py$" src/ | xargs grep -l "def enrich_byok_rag\|def enrich_solr"Repository: lightspeed-core/lightspeed-stack Length of output: 108 🏁 Script executed: # Get the content around the enrichment calls to understand context
rg "def enrich_byok_rag|def enrich_solr" -A 15Repository: lightspeed-core/lightspeed-stack Length of output: 2310 🏁 Script executed: # Check if ls_config is ever checked for None elsewhere in the file
rg "ls_config" src/client.py -B 2 -A 2Repository: lightspeed-core/lightspeed-stack Length of output: 924 Guard against non-dict YAML payloads before enrichment.
Proposed fix try:
with open(input_config_path, "r", encoding="utf-8") as f:
ls_config = yaml.safe_load(f)
except (OSError, yaml.YAMLError) as e:
logger.warning("Failed to read llama-stack config: %s", e)
return input_config_path
+ if not isinstance(ls_config, dict):
+ logger.warning(
+ "Invalid llama-stack config format in %s: expected mapping at root",
+ input_config_path,
+ )
+ return input_config_path🤖 Prompt for AI Agents |
||
|
|
||
| enriched_path = os.path.join( | ||
| tempfile.gettempdir(), "llama_stack_enriched_config.yaml" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -377,19 +377,36 @@ def enrich_byok_rag(ls_config: dict[str, Any], byok_rag: list[dict[str, Any]]) - | |||||
| # ============================================================================= | ||||||
|
|
||||||
|
|
||||||
| def enrich_solr(ls_config: dict[str, Any], solr_config: dict[str, Any]) -> None: | ||||||
| def enrich_solr( # pylint: disable=too-many-locals | ||||||
| ls_config: dict[str, Any], | ||||||
| rag_config: dict[str, Any], | ||||||
| okp_config: dict[str, Any], | ||||||
| ) -> None: | ||||||
| """Enrich Llama Stack config with Solr settings. | ||||||
|
|
||||||
| Args: | ||||||
| ls_config: Llama Stack configuration dict (modified in place) | ||||||
| solr_config: Solr configuration dict. Expected keys: | ||||||
| - enabled (bool): whether Solr enrichment should run | ||||||
| rag_config: RAG configuration dict. Used keys: | ||||||
| - inline (list[str]): inline RAG IDs | ||||||
| - tool (list[str]): tool RAG IDs | ||||||
| okp_config: OKP configuration dict. Used keys: | ||||||
| - chunk_filter_query (str): Solr filter query for chunk retrieval | ||||||
| """ | ||||||
| if not solr_config or not solr_config.get("enabled"): | ||||||
| inline_ids = rag_config.get("inline") or [] | ||||||
| tool_ids = rag_config.get("tool") or [] | ||||||
| okp_enabled = constants.OKP_RAG_ID in inline_ids or constants.OKP_RAG_ID in tool_ids | ||||||
|
|
||||||
| if not okp_enabled: | ||||||
| logger.info("OKP is not enabled: skipping") | ||||||
| return | ||||||
|
|
||||||
| user_filter = okp_config.get("chunk_filter_query") | ||||||
| chunk_filter_query = ( | ||||||
| f"{constants.SOLR_CHUNK_FILTER_QUERY} AND {user_filter}" | ||||||
| if user_filter | ||||||
| else constants.SOLR_CHUNK_FILTER_QUERY | ||||||
| ) | ||||||
|
are-ces marked this conversation as resolved.
|
||||||
|
|
||||||
| logger.info("Enriching Llama Stack config with OKP") | ||||||
|
|
||||||
| # Add vector_io provider for Solr | ||||||
|
|
@@ -420,9 +437,6 @@ def enrich_solr(ls_config: dict[str, Any], solr_config: dict[str, Any]) -> None: | |||||
| embedding_dim_env = ( | ||||||
| f"${{env.SOLR_EMBEDDING_DIM:={constants.SOLR_DEFAULT_EMBEDDING_DIMENSION}}}" | ||||||
| ) | ||||||
|
|
||||||
| chunk_filter_query = solr_config.get("chunk_filter_query", "is_chunk:true") | ||||||
|
|
||||||
| ls_config["providers"]["vector_io"].append( | ||||||
| { | ||||||
| "provider_id": constants.SOLR_PROVIDER_ID, | ||||||
|
|
@@ -543,15 +557,7 @@ def generate_configuration( | |||||
| enrich_byok_rag(ls_config, config.get("byok_rag", [])) | ||||||
|
|
||||||
| # Enrichment: Solr - enabled when "okp" appears in either inline or tool list | ||||||
| rag_config = config.get("rag", {}) | ||||||
| inline_ids = rag_config.get("inline") or [] | ||||||
| tool_ids = rag_config.get("tool") or [] | ||||||
| okp_enabled = constants.OKP_RAG_ID in inline_ids or constants.OKP_RAG_ID in tool_ids | ||||||
| okp_config = config.get("okp", {}) | ||||||
| chunk_filter_query = okp_config.get("chunk_filter_query", "is_chunk:true") | ||||||
| enrich_solr( | ||||||
| ls_config, {"enabled": okp_enabled, "chunk_filter_query": chunk_filter_query} | ||||||
| ) | ||||||
| enrich_solr(ls_config, config.get("rag", {}), config.get("okp", {})) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Normalize nullable
Proposed fix- enrich_solr(ls_config, config.get("rag", {}), config.get("okp", {}))
+ enrich_solr(ls_config, config.get("rag") or {}, config.get("okp") or {})📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| logger.info("Writing Llama Stack configuration into file %s", output_file) | ||||||
|
|
||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.