lfx-nightly 0.2.0.dev25__py3-none-any.whl

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.

Potentially problematic release.


This version of lfx-nightly might be problematic. Click here for more details.

Files changed (769) hide show
  1. lfx/__init__.py +0 -0
  2. lfx/__main__.py +25 -0
  3. lfx/_assets/component_index.json +1 -0
  4. lfx/base/__init__.py +0 -0
  5. lfx/base/agents/__init__.py +0 -0
  6. lfx/base/agents/agent.py +375 -0
  7. lfx/base/agents/altk_base_agent.py +380 -0
  8. lfx/base/agents/altk_tool_wrappers.py +565 -0
  9. lfx/base/agents/callback.py +130 -0
  10. lfx/base/agents/context.py +109 -0
  11. lfx/base/agents/crewai/__init__.py +0 -0
  12. lfx/base/agents/crewai/crew.py +231 -0
  13. lfx/base/agents/crewai/tasks.py +12 -0
  14. lfx/base/agents/default_prompts.py +23 -0
  15. lfx/base/agents/errors.py +15 -0
  16. lfx/base/agents/events.py +430 -0
  17. lfx/base/agents/utils.py +237 -0
  18. lfx/base/astra_assistants/__init__.py +0 -0
  19. lfx/base/astra_assistants/util.py +171 -0
  20. lfx/base/chains/__init__.py +0 -0
  21. lfx/base/chains/model.py +19 -0
  22. lfx/base/composio/__init__.py +0 -0
  23. lfx/base/composio/composio_base.py +2584 -0
  24. lfx/base/compressors/__init__.py +0 -0
  25. lfx/base/compressors/model.py +60 -0
  26. lfx/base/constants.py +46 -0
  27. lfx/base/curl/__init__.py +0 -0
  28. lfx/base/curl/parse.py +188 -0
  29. lfx/base/data/__init__.py +5 -0
  30. lfx/base/data/base_file.py +810 -0
  31. lfx/base/data/docling_utils.py +338 -0
  32. lfx/base/data/storage_utils.py +192 -0
  33. lfx/base/data/utils.py +362 -0
  34. lfx/base/datastax/__init__.py +5 -0
  35. lfx/base/datastax/astradb_base.py +896 -0
  36. lfx/base/document_transformers/__init__.py +0 -0
  37. lfx/base/document_transformers/model.py +43 -0
  38. lfx/base/embeddings/__init__.py +0 -0
  39. lfx/base/embeddings/aiml_embeddings.py +62 -0
  40. lfx/base/embeddings/embeddings_class.py +113 -0
  41. lfx/base/embeddings/model.py +26 -0
  42. lfx/base/flow_processing/__init__.py +0 -0
  43. lfx/base/flow_processing/utils.py +86 -0
  44. lfx/base/huggingface/__init__.py +0 -0
  45. lfx/base/huggingface/model_bridge.py +133 -0
  46. lfx/base/io/__init__.py +0 -0
  47. lfx/base/io/chat.py +21 -0
  48. lfx/base/io/text.py +22 -0
  49. lfx/base/knowledge_bases/__init__.py +3 -0
  50. lfx/base/knowledge_bases/knowledge_base_utils.py +137 -0
  51. lfx/base/langchain_utilities/__init__.py +0 -0
  52. lfx/base/langchain_utilities/model.py +35 -0
  53. lfx/base/langchain_utilities/spider_constants.py +1 -0
  54. lfx/base/langwatch/__init__.py +0 -0
  55. lfx/base/langwatch/utils.py +18 -0
  56. lfx/base/mcp/__init__.py +0 -0
  57. lfx/base/mcp/constants.py +2 -0
  58. lfx/base/mcp/util.py +1659 -0
  59. lfx/base/memory/__init__.py +0 -0
  60. lfx/base/memory/memory.py +49 -0
  61. lfx/base/memory/model.py +38 -0
  62. lfx/base/models/__init__.py +3 -0
  63. lfx/base/models/aiml_constants.py +51 -0
  64. lfx/base/models/anthropic_constants.py +51 -0
  65. lfx/base/models/aws_constants.py +151 -0
  66. lfx/base/models/chat_result.py +76 -0
  67. lfx/base/models/cometapi_constants.py +54 -0
  68. lfx/base/models/google_generative_ai_constants.py +70 -0
  69. lfx/base/models/google_generative_ai_model.py +38 -0
  70. lfx/base/models/groq_constants.py +150 -0
  71. lfx/base/models/groq_model_discovery.py +265 -0
  72. lfx/base/models/model.py +375 -0
  73. lfx/base/models/model_input_constants.py +378 -0
  74. lfx/base/models/model_metadata.py +41 -0
  75. lfx/base/models/model_utils.py +108 -0
  76. lfx/base/models/novita_constants.py +35 -0
  77. lfx/base/models/ollama_constants.py +52 -0
  78. lfx/base/models/openai_constants.py +129 -0
  79. lfx/base/models/sambanova_constants.py +18 -0
  80. lfx/base/models/watsonx_constants.py +36 -0
  81. lfx/base/processing/__init__.py +0 -0
  82. lfx/base/prompts/__init__.py +0 -0
  83. lfx/base/prompts/api_utils.py +224 -0
  84. lfx/base/prompts/utils.py +61 -0
  85. lfx/base/textsplitters/__init__.py +0 -0
  86. lfx/base/textsplitters/model.py +28 -0
  87. lfx/base/tools/__init__.py +0 -0
  88. lfx/base/tools/base.py +26 -0
  89. lfx/base/tools/component_tool.py +325 -0
  90. lfx/base/tools/constants.py +49 -0
  91. lfx/base/tools/flow_tool.py +132 -0
  92. lfx/base/tools/run_flow.py +698 -0
  93. lfx/base/vectorstores/__init__.py +0 -0
  94. lfx/base/vectorstores/model.py +193 -0
  95. lfx/base/vectorstores/utils.py +22 -0
  96. lfx/base/vectorstores/vector_store_connection_decorator.py +52 -0
  97. lfx/cli/__init__.py +5 -0
  98. lfx/cli/commands.py +327 -0
  99. lfx/cli/common.py +650 -0
  100. lfx/cli/run.py +506 -0
  101. lfx/cli/script_loader.py +289 -0
  102. lfx/cli/serve_app.py +546 -0
  103. lfx/cli/validation.py +69 -0
  104. lfx/components/FAISS/__init__.py +34 -0
  105. lfx/components/FAISS/faiss.py +111 -0
  106. lfx/components/Notion/__init__.py +19 -0
  107. lfx/components/Notion/add_content_to_page.py +269 -0
  108. lfx/components/Notion/create_page.py +94 -0
  109. lfx/components/Notion/list_database_properties.py +68 -0
  110. lfx/components/Notion/list_pages.py +122 -0
  111. lfx/components/Notion/list_users.py +77 -0
  112. lfx/components/Notion/page_content_viewer.py +93 -0
  113. lfx/components/Notion/search.py +111 -0
  114. lfx/components/Notion/update_page_property.py +114 -0
  115. lfx/components/__init__.py +428 -0
  116. lfx/components/_importing.py +42 -0
  117. lfx/components/agentql/__init__.py +3 -0
  118. lfx/components/agentql/agentql_api.py +151 -0
  119. lfx/components/aiml/__init__.py +37 -0
  120. lfx/components/aiml/aiml.py +115 -0
  121. lfx/components/aiml/aiml_embeddings.py +37 -0
  122. lfx/components/altk/__init__.py +34 -0
  123. lfx/components/altk/altk_agent.py +193 -0
  124. lfx/components/amazon/__init__.py +36 -0
  125. lfx/components/amazon/amazon_bedrock_converse.py +195 -0
  126. lfx/components/amazon/amazon_bedrock_embedding.py +109 -0
  127. lfx/components/amazon/amazon_bedrock_model.py +130 -0
  128. lfx/components/amazon/s3_bucket_uploader.py +211 -0
  129. lfx/components/anthropic/__init__.py +34 -0
  130. lfx/components/anthropic/anthropic.py +187 -0
  131. lfx/components/apify/__init__.py +5 -0
  132. lfx/components/apify/apify_actor.py +325 -0
  133. lfx/components/arxiv/__init__.py +3 -0
  134. lfx/components/arxiv/arxiv.py +169 -0
  135. lfx/components/assemblyai/__init__.py +46 -0
  136. lfx/components/assemblyai/assemblyai_get_subtitles.py +83 -0
  137. lfx/components/assemblyai/assemblyai_lemur.py +183 -0
  138. lfx/components/assemblyai/assemblyai_list_transcripts.py +95 -0
  139. lfx/components/assemblyai/assemblyai_poll_transcript.py +72 -0
  140. lfx/components/assemblyai/assemblyai_start_transcript.py +188 -0
  141. lfx/components/azure/__init__.py +37 -0
  142. lfx/components/azure/azure_openai.py +95 -0
  143. lfx/components/azure/azure_openai_embeddings.py +83 -0
  144. lfx/components/baidu/__init__.py +32 -0
  145. lfx/components/baidu/baidu_qianfan_chat.py +113 -0
  146. lfx/components/bing/__init__.py +3 -0
  147. lfx/components/bing/bing_search_api.py +61 -0
  148. lfx/components/cassandra/__init__.py +40 -0
  149. lfx/components/cassandra/cassandra.py +264 -0
  150. lfx/components/cassandra/cassandra_chat.py +92 -0
  151. lfx/components/cassandra/cassandra_graph.py +238 -0
  152. lfx/components/chains/__init__.py +3 -0
  153. lfx/components/chroma/__init__.py +34 -0
  154. lfx/components/chroma/chroma.py +169 -0
  155. lfx/components/cleanlab/__init__.py +40 -0
  156. lfx/components/cleanlab/cleanlab_evaluator.py +155 -0
  157. lfx/components/cleanlab/cleanlab_rag_evaluator.py +254 -0
  158. lfx/components/cleanlab/cleanlab_remediator.py +131 -0
  159. lfx/components/clickhouse/__init__.py +34 -0
  160. lfx/components/clickhouse/clickhouse.py +135 -0
  161. lfx/components/cloudflare/__init__.py +32 -0
  162. lfx/components/cloudflare/cloudflare.py +81 -0
  163. lfx/components/cohere/__init__.py +40 -0
  164. lfx/components/cohere/cohere_embeddings.py +81 -0
  165. lfx/components/cohere/cohere_models.py +46 -0
  166. lfx/components/cohere/cohere_rerank.py +51 -0
  167. lfx/components/cometapi/__init__.py +32 -0
  168. lfx/components/cometapi/cometapi.py +166 -0
  169. lfx/components/composio/__init__.py +222 -0
  170. lfx/components/composio/agentql_composio.py +11 -0
  171. lfx/components/composio/agiled_composio.py +11 -0
  172. lfx/components/composio/airtable_composio.py +11 -0
  173. lfx/components/composio/apollo_composio.py +11 -0
  174. lfx/components/composio/asana_composio.py +11 -0
  175. lfx/components/composio/attio_composio.py +11 -0
  176. lfx/components/composio/bitbucket_composio.py +11 -0
  177. lfx/components/composio/bolna_composio.py +11 -0
  178. lfx/components/composio/brightdata_composio.py +11 -0
  179. lfx/components/composio/calendly_composio.py +11 -0
  180. lfx/components/composio/canva_composio.py +11 -0
  181. lfx/components/composio/canvas_composio.py +11 -0
  182. lfx/components/composio/coda_composio.py +11 -0
  183. lfx/components/composio/composio_api.py +278 -0
  184. lfx/components/composio/contentful_composio.py +11 -0
  185. lfx/components/composio/digicert_composio.py +11 -0
  186. lfx/components/composio/discord_composio.py +11 -0
  187. lfx/components/composio/dropbox_compnent.py +11 -0
  188. lfx/components/composio/elevenlabs_composio.py +11 -0
  189. lfx/components/composio/exa_composio.py +11 -0
  190. lfx/components/composio/figma_composio.py +11 -0
  191. lfx/components/composio/finage_composio.py +11 -0
  192. lfx/components/composio/firecrawl_composio.py +11 -0
  193. lfx/components/composio/fireflies_composio.py +11 -0
  194. lfx/components/composio/fixer_composio.py +11 -0
  195. lfx/components/composio/flexisign_composio.py +11 -0
  196. lfx/components/composio/freshdesk_composio.py +11 -0
  197. lfx/components/composio/github_composio.py +11 -0
  198. lfx/components/composio/gmail_composio.py +38 -0
  199. lfx/components/composio/googlebigquery_composio.py +11 -0
  200. lfx/components/composio/googlecalendar_composio.py +11 -0
  201. lfx/components/composio/googleclassroom_composio.py +11 -0
  202. lfx/components/composio/googledocs_composio.py +11 -0
  203. lfx/components/composio/googlemeet_composio.py +11 -0
  204. lfx/components/composio/googlesheets_composio.py +11 -0
  205. lfx/components/composio/googletasks_composio.py +8 -0
  206. lfx/components/composio/heygen_composio.py +11 -0
  207. lfx/components/composio/instagram_composio.py +11 -0
  208. lfx/components/composio/jira_composio.py +11 -0
  209. lfx/components/composio/jotform_composio.py +11 -0
  210. lfx/components/composio/klaviyo_composio.py +11 -0
  211. lfx/components/composio/linear_composio.py +11 -0
  212. lfx/components/composio/listennotes_composio.py +11 -0
  213. lfx/components/composio/mem0_composio.py +11 -0
  214. lfx/components/composio/miro_composio.py +11 -0
  215. lfx/components/composio/missive_composio.py +11 -0
  216. lfx/components/composio/notion_composio.py +11 -0
  217. lfx/components/composio/onedrive_composio.py +11 -0
  218. lfx/components/composio/outlook_composio.py +11 -0
  219. lfx/components/composio/pandadoc_composio.py +11 -0
  220. lfx/components/composio/peopledatalabs_composio.py +11 -0
  221. lfx/components/composio/perplexityai_composio.py +11 -0
  222. lfx/components/composio/reddit_composio.py +11 -0
  223. lfx/components/composio/serpapi_composio.py +11 -0
  224. lfx/components/composio/slack_composio.py +11 -0
  225. lfx/components/composio/slackbot_composio.py +11 -0
  226. lfx/components/composio/snowflake_composio.py +11 -0
  227. lfx/components/composio/supabase_composio.py +11 -0
  228. lfx/components/composio/tavily_composio.py +11 -0
  229. lfx/components/composio/timelinesai_composio.py +11 -0
  230. lfx/components/composio/todoist_composio.py +11 -0
  231. lfx/components/composio/wrike_composio.py +11 -0
  232. lfx/components/composio/youtube_composio.py +11 -0
  233. lfx/components/confluence/__init__.py +3 -0
  234. lfx/components/confluence/confluence.py +84 -0
  235. lfx/components/couchbase/__init__.py +34 -0
  236. lfx/components/couchbase/couchbase.py +102 -0
  237. lfx/components/crewai/__init__.py +49 -0
  238. lfx/components/crewai/crewai.py +108 -0
  239. lfx/components/crewai/hierarchical_crew.py +47 -0
  240. lfx/components/crewai/hierarchical_task.py +45 -0
  241. lfx/components/crewai/sequential_crew.py +53 -0
  242. lfx/components/crewai/sequential_task.py +74 -0
  243. lfx/components/crewai/sequential_task_agent.py +144 -0
  244. lfx/components/cuga/__init__.py +34 -0
  245. lfx/components/cuga/cuga_agent.py +730 -0
  246. lfx/components/custom_component/__init__.py +34 -0
  247. lfx/components/custom_component/custom_component.py +31 -0
  248. lfx/components/data/__init__.py +114 -0
  249. lfx/components/data_source/__init__.py +58 -0
  250. lfx/components/data_source/api_request.py +577 -0
  251. lfx/components/data_source/csv_to_data.py +101 -0
  252. lfx/components/data_source/json_to_data.py +106 -0
  253. lfx/components/data_source/mock_data.py +398 -0
  254. lfx/components/data_source/news_search.py +166 -0
  255. lfx/components/data_source/rss.py +71 -0
  256. lfx/components/data_source/sql_executor.py +101 -0
  257. lfx/components/data_source/url.py +311 -0
  258. lfx/components/data_source/web_search.py +326 -0
  259. lfx/components/datastax/__init__.py +76 -0
  260. lfx/components/datastax/astradb_assistant_manager.py +307 -0
  261. lfx/components/datastax/astradb_chatmemory.py +40 -0
  262. lfx/components/datastax/astradb_cql.py +288 -0
  263. lfx/components/datastax/astradb_graph.py +217 -0
  264. lfx/components/datastax/astradb_tool.py +378 -0
  265. lfx/components/datastax/astradb_vectorize.py +122 -0
  266. lfx/components/datastax/astradb_vectorstore.py +449 -0
  267. lfx/components/datastax/create_assistant.py +59 -0
  268. lfx/components/datastax/create_thread.py +33 -0
  269. lfx/components/datastax/dotenv.py +36 -0
  270. lfx/components/datastax/get_assistant.py +38 -0
  271. lfx/components/datastax/getenvvar.py +31 -0
  272. lfx/components/datastax/graph_rag.py +141 -0
  273. lfx/components/datastax/hcd.py +315 -0
  274. lfx/components/datastax/list_assistants.py +26 -0
  275. lfx/components/datastax/run.py +90 -0
  276. lfx/components/deactivated/__init__.py +15 -0
  277. lfx/components/deactivated/amazon_kendra.py +66 -0
  278. lfx/components/deactivated/chat_litellm_model.py +158 -0
  279. lfx/components/deactivated/code_block_extractor.py +26 -0
  280. lfx/components/deactivated/documents_to_data.py +22 -0
  281. lfx/components/deactivated/embed.py +16 -0
  282. lfx/components/deactivated/extract_key_from_data.py +46 -0
  283. lfx/components/deactivated/json_document_builder.py +57 -0
  284. lfx/components/deactivated/list_flows.py +20 -0
  285. lfx/components/deactivated/mcp_sse.py +61 -0
  286. lfx/components/deactivated/mcp_stdio.py +62 -0
  287. lfx/components/deactivated/merge_data.py +93 -0
  288. lfx/components/deactivated/message.py +37 -0
  289. lfx/components/deactivated/metal.py +54 -0
  290. lfx/components/deactivated/multi_query.py +59 -0
  291. lfx/components/deactivated/retriever.py +43 -0
  292. lfx/components/deactivated/selective_passthrough.py +77 -0
  293. lfx/components/deactivated/should_run_next.py +40 -0
  294. lfx/components/deactivated/split_text.py +63 -0
  295. lfx/components/deactivated/store_message.py +24 -0
  296. lfx/components/deactivated/sub_flow.py +124 -0
  297. lfx/components/deactivated/vectara_self_query.py +76 -0
  298. lfx/components/deactivated/vector_store.py +24 -0
  299. lfx/components/deepseek/__init__.py +34 -0
  300. lfx/components/deepseek/deepseek.py +136 -0
  301. lfx/components/docling/__init__.py +43 -0
  302. lfx/components/docling/chunk_docling_document.py +186 -0
  303. lfx/components/docling/docling_inline.py +238 -0
  304. lfx/components/docling/docling_remote.py +195 -0
  305. lfx/components/docling/export_docling_document.py +117 -0
  306. lfx/components/documentloaders/__init__.py +3 -0
  307. lfx/components/duckduckgo/__init__.py +3 -0
  308. lfx/components/duckduckgo/duck_duck_go_search_run.py +92 -0
  309. lfx/components/elastic/__init__.py +37 -0
  310. lfx/components/elastic/elasticsearch.py +267 -0
  311. lfx/components/elastic/opensearch.py +789 -0
  312. lfx/components/elastic/opensearch_multimodal.py +1575 -0
  313. lfx/components/embeddings/__init__.py +37 -0
  314. lfx/components/embeddings/similarity.py +77 -0
  315. lfx/components/embeddings/text_embedder.py +65 -0
  316. lfx/components/exa/__init__.py +3 -0
  317. lfx/components/exa/exa_search.py +68 -0
  318. lfx/components/files_and_knowledge/__init__.py +47 -0
  319. lfx/components/files_and_knowledge/directory.py +113 -0
  320. lfx/components/files_and_knowledge/file.py +841 -0
  321. lfx/components/files_and_knowledge/ingestion.py +694 -0
  322. lfx/components/files_and_knowledge/retrieval.py +264 -0
  323. lfx/components/files_and_knowledge/save_file.py +746 -0
  324. lfx/components/firecrawl/__init__.py +43 -0
  325. lfx/components/firecrawl/firecrawl_crawl_api.py +88 -0
  326. lfx/components/firecrawl/firecrawl_extract_api.py +136 -0
  327. lfx/components/firecrawl/firecrawl_map_api.py +89 -0
  328. lfx/components/firecrawl/firecrawl_scrape_api.py +73 -0
  329. lfx/components/flow_controls/__init__.py +58 -0
  330. lfx/components/flow_controls/conditional_router.py +208 -0
  331. lfx/components/flow_controls/data_conditional_router.py +126 -0
  332. lfx/components/flow_controls/flow_tool.py +111 -0
  333. lfx/components/flow_controls/listen.py +29 -0
  334. lfx/components/flow_controls/loop.py +163 -0
  335. lfx/components/flow_controls/notify.py +88 -0
  336. lfx/components/flow_controls/pass_message.py +36 -0
  337. lfx/components/flow_controls/run_flow.py +108 -0
  338. lfx/components/flow_controls/sub_flow.py +115 -0
  339. lfx/components/git/__init__.py +4 -0
  340. lfx/components/git/git.py +262 -0
  341. lfx/components/git/gitextractor.py +196 -0
  342. lfx/components/glean/__init__.py +3 -0
  343. lfx/components/glean/glean_search_api.py +173 -0
  344. lfx/components/google/__init__.py +17 -0
  345. lfx/components/google/gmail.py +193 -0
  346. lfx/components/google/google_bq_sql_executor.py +157 -0
  347. lfx/components/google/google_drive.py +92 -0
  348. lfx/components/google/google_drive_search.py +152 -0
  349. lfx/components/google/google_generative_ai.py +144 -0
  350. lfx/components/google/google_generative_ai_embeddings.py +141 -0
  351. lfx/components/google/google_oauth_token.py +89 -0
  352. lfx/components/google/google_search_api_core.py +68 -0
  353. lfx/components/google/google_serper_api_core.py +74 -0
  354. lfx/components/groq/__init__.py +34 -0
  355. lfx/components/groq/groq.py +143 -0
  356. lfx/components/helpers/__init__.py +154 -0
  357. lfx/components/homeassistant/__init__.py +7 -0
  358. lfx/components/homeassistant/home_assistant_control.py +152 -0
  359. lfx/components/homeassistant/list_home_assistant_states.py +137 -0
  360. lfx/components/huggingface/__init__.py +37 -0
  361. lfx/components/huggingface/huggingface.py +199 -0
  362. lfx/components/huggingface/huggingface_inference_api.py +106 -0
  363. lfx/components/ibm/__init__.py +34 -0
  364. lfx/components/ibm/watsonx.py +207 -0
  365. lfx/components/ibm/watsonx_embeddings.py +135 -0
  366. lfx/components/icosacomputing/__init__.py +5 -0
  367. lfx/components/icosacomputing/combinatorial_reasoner.py +84 -0
  368. lfx/components/input_output/__init__.py +40 -0
  369. lfx/components/input_output/chat.py +109 -0
  370. lfx/components/input_output/chat_output.py +184 -0
  371. lfx/components/input_output/text.py +27 -0
  372. lfx/components/input_output/text_output.py +29 -0
  373. lfx/components/input_output/webhook.py +56 -0
  374. lfx/components/jigsawstack/__init__.py +23 -0
  375. lfx/components/jigsawstack/ai_scrape.py +126 -0
  376. lfx/components/jigsawstack/ai_web_search.py +136 -0
  377. lfx/components/jigsawstack/file_read.py +115 -0
  378. lfx/components/jigsawstack/file_upload.py +94 -0
  379. lfx/components/jigsawstack/image_generation.py +205 -0
  380. lfx/components/jigsawstack/nsfw.py +60 -0
  381. lfx/components/jigsawstack/object_detection.py +124 -0
  382. lfx/components/jigsawstack/sentiment.py +112 -0
  383. lfx/components/jigsawstack/text_to_sql.py +90 -0
  384. lfx/components/jigsawstack/text_translate.py +77 -0
  385. lfx/components/jigsawstack/vocr.py +107 -0
  386. lfx/components/knowledge_bases/__init__.py +89 -0
  387. lfx/components/langchain_utilities/__init__.py +109 -0
  388. lfx/components/langchain_utilities/character.py +53 -0
  389. lfx/components/langchain_utilities/conversation.py +59 -0
  390. lfx/components/langchain_utilities/csv_agent.py +175 -0
  391. lfx/components/langchain_utilities/fake_embeddings.py +26 -0
  392. lfx/components/langchain_utilities/html_link_extractor.py +35 -0
  393. lfx/components/langchain_utilities/json_agent.py +100 -0
  394. lfx/components/langchain_utilities/langchain_hub.py +126 -0
  395. lfx/components/langchain_utilities/language_recursive.py +49 -0
  396. lfx/components/langchain_utilities/language_semantic.py +138 -0
  397. lfx/components/langchain_utilities/llm_checker.py +39 -0
  398. lfx/components/langchain_utilities/llm_math.py +42 -0
  399. lfx/components/langchain_utilities/natural_language.py +61 -0
  400. lfx/components/langchain_utilities/openai_tools.py +53 -0
  401. lfx/components/langchain_utilities/openapi.py +48 -0
  402. lfx/components/langchain_utilities/recursive_character.py +60 -0
  403. lfx/components/langchain_utilities/retrieval_qa.py +83 -0
  404. lfx/components/langchain_utilities/runnable_executor.py +137 -0
  405. lfx/components/langchain_utilities/self_query.py +80 -0
  406. lfx/components/langchain_utilities/spider.py +142 -0
  407. lfx/components/langchain_utilities/sql.py +40 -0
  408. lfx/components/langchain_utilities/sql_database.py +35 -0
  409. lfx/components/langchain_utilities/sql_generator.py +78 -0
  410. lfx/components/langchain_utilities/tool_calling.py +59 -0
  411. lfx/components/langchain_utilities/vector_store_info.py +49 -0
  412. lfx/components/langchain_utilities/vector_store_router.py +33 -0
  413. lfx/components/langchain_utilities/xml_agent.py +71 -0
  414. lfx/components/langwatch/__init__.py +3 -0
  415. lfx/components/langwatch/langwatch.py +278 -0
  416. lfx/components/link_extractors/__init__.py +3 -0
  417. lfx/components/llm_operations/__init__.py +46 -0
  418. lfx/components/llm_operations/batch_run.py +205 -0
  419. lfx/components/llm_operations/lambda_filter.py +218 -0
  420. lfx/components/llm_operations/llm_conditional_router.py +421 -0
  421. lfx/components/llm_operations/llm_selector.py +499 -0
  422. lfx/components/llm_operations/structured_output.py +244 -0
  423. lfx/components/lmstudio/__init__.py +34 -0
  424. lfx/components/lmstudio/lmstudioembeddings.py +89 -0
  425. lfx/components/lmstudio/lmstudiomodel.py +133 -0
  426. lfx/components/logic/__init__.py +181 -0
  427. lfx/components/maritalk/__init__.py +32 -0
  428. lfx/components/maritalk/maritalk.py +52 -0
  429. lfx/components/mem0/__init__.py +3 -0
  430. lfx/components/mem0/mem0_chat_memory.py +147 -0
  431. lfx/components/milvus/__init__.py +34 -0
  432. lfx/components/milvus/milvus.py +115 -0
  433. lfx/components/mistral/__init__.py +37 -0
  434. lfx/components/mistral/mistral.py +114 -0
  435. lfx/components/mistral/mistral_embeddings.py +58 -0
  436. lfx/components/models/__init__.py +89 -0
  437. lfx/components/models_and_agents/__init__.py +49 -0
  438. lfx/components/models_and_agents/agent.py +644 -0
  439. lfx/components/models_and_agents/embedding_model.py +423 -0
  440. lfx/components/models_and_agents/language_model.py +398 -0
  441. lfx/components/models_and_agents/mcp_component.py +594 -0
  442. lfx/components/models_and_agents/memory.py +268 -0
  443. lfx/components/models_and_agents/prompt.py +67 -0
  444. lfx/components/mongodb/__init__.py +34 -0
  445. lfx/components/mongodb/mongodb_atlas.py +213 -0
  446. lfx/components/needle/__init__.py +3 -0
  447. lfx/components/needle/needle.py +104 -0
  448. lfx/components/notdiamond/__init__.py +34 -0
  449. lfx/components/notdiamond/notdiamond.py +228 -0
  450. lfx/components/novita/__init__.py +32 -0
  451. lfx/components/novita/novita.py +130 -0
  452. lfx/components/nvidia/__init__.py +57 -0
  453. lfx/components/nvidia/nvidia.py +151 -0
  454. lfx/components/nvidia/nvidia_embedding.py +77 -0
  455. lfx/components/nvidia/nvidia_ingest.py +317 -0
  456. lfx/components/nvidia/nvidia_rerank.py +63 -0
  457. lfx/components/nvidia/system_assist.py +65 -0
  458. lfx/components/olivya/__init__.py +3 -0
  459. lfx/components/olivya/olivya.py +116 -0
  460. lfx/components/ollama/__init__.py +37 -0
  461. lfx/components/ollama/ollama.py +548 -0
  462. lfx/components/ollama/ollama_embeddings.py +103 -0
  463. lfx/components/openai/__init__.py +37 -0
  464. lfx/components/openai/openai.py +100 -0
  465. lfx/components/openai/openai_chat_model.py +176 -0
  466. lfx/components/openrouter/__init__.py +32 -0
  467. lfx/components/openrouter/openrouter.py +104 -0
  468. lfx/components/output_parsers/__init__.py +3 -0
  469. lfx/components/perplexity/__init__.py +34 -0
  470. lfx/components/perplexity/perplexity.py +75 -0
  471. lfx/components/pgvector/__init__.py +34 -0
  472. lfx/components/pgvector/pgvector.py +72 -0
  473. lfx/components/pinecone/__init__.py +34 -0
  474. lfx/components/pinecone/pinecone.py +134 -0
  475. lfx/components/processing/__init__.py +72 -0
  476. lfx/components/processing/alter_metadata.py +109 -0
  477. lfx/components/processing/combine_text.py +40 -0
  478. lfx/components/processing/converter.py +248 -0
  479. lfx/components/processing/create_data.py +111 -0
  480. lfx/components/processing/create_list.py +40 -0
  481. lfx/components/processing/data_operations.py +528 -0
  482. lfx/components/processing/data_to_dataframe.py +71 -0
  483. lfx/components/processing/dataframe_operations.py +313 -0
  484. lfx/components/processing/dataframe_to_toolset.py +259 -0
  485. lfx/components/processing/dynamic_create_data.py +357 -0
  486. lfx/components/processing/extract_key.py +54 -0
  487. lfx/components/processing/filter_data.py +43 -0
  488. lfx/components/processing/filter_data_values.py +89 -0
  489. lfx/components/processing/json_cleaner.py +104 -0
  490. lfx/components/processing/merge_data.py +91 -0
  491. lfx/components/processing/message_to_data.py +37 -0
  492. lfx/components/processing/output_parser.py +46 -0
  493. lfx/components/processing/parse_data.py +71 -0
  494. lfx/components/processing/parse_dataframe.py +69 -0
  495. lfx/components/processing/parse_json_data.py +91 -0
  496. lfx/components/processing/parser.py +148 -0
  497. lfx/components/processing/regex.py +83 -0
  498. lfx/components/processing/select_data.py +49 -0
  499. lfx/components/processing/split_text.py +141 -0
  500. lfx/components/processing/store_message.py +91 -0
  501. lfx/components/processing/update_data.py +161 -0
  502. lfx/components/prototypes/__init__.py +35 -0
  503. lfx/components/prototypes/python_function.py +73 -0
  504. lfx/components/qdrant/__init__.py +34 -0
  505. lfx/components/qdrant/qdrant.py +109 -0
  506. lfx/components/redis/__init__.py +37 -0
  507. lfx/components/redis/redis.py +89 -0
  508. lfx/components/redis/redis_chat.py +43 -0
  509. lfx/components/sambanova/__init__.py +32 -0
  510. lfx/components/sambanova/sambanova.py +84 -0
  511. lfx/components/scrapegraph/__init__.py +40 -0
  512. lfx/components/scrapegraph/scrapegraph_markdownify_api.py +64 -0
  513. lfx/components/scrapegraph/scrapegraph_search_api.py +64 -0
  514. lfx/components/scrapegraph/scrapegraph_smart_scraper_api.py +71 -0
  515. lfx/components/searchapi/__init__.py +34 -0
  516. lfx/components/searchapi/search.py +79 -0
  517. lfx/components/serpapi/__init__.py +3 -0
  518. lfx/components/serpapi/serp.py +115 -0
  519. lfx/components/supabase/__init__.py +34 -0
  520. lfx/components/supabase/supabase.py +76 -0
  521. lfx/components/tavily/__init__.py +4 -0
  522. lfx/components/tavily/tavily_extract.py +117 -0
  523. lfx/components/tavily/tavily_search.py +212 -0
  524. lfx/components/textsplitters/__init__.py +3 -0
  525. lfx/components/toolkits/__init__.py +3 -0
  526. lfx/components/tools/__init__.py +66 -0
  527. lfx/components/tools/calculator.py +109 -0
  528. lfx/components/tools/google_search_api.py +45 -0
  529. lfx/components/tools/google_serper_api.py +115 -0
  530. lfx/components/tools/python_code_structured_tool.py +328 -0
  531. lfx/components/tools/python_repl.py +98 -0
  532. lfx/components/tools/search_api.py +88 -0
  533. lfx/components/tools/searxng.py +145 -0
  534. lfx/components/tools/serp_api.py +120 -0
  535. lfx/components/tools/tavily_search_tool.py +345 -0
  536. lfx/components/tools/wikidata_api.py +103 -0
  537. lfx/components/tools/wikipedia_api.py +50 -0
  538. lfx/components/tools/yahoo_finance.py +130 -0
  539. lfx/components/twelvelabs/__init__.py +52 -0
  540. lfx/components/twelvelabs/convert_astra_results.py +84 -0
  541. lfx/components/twelvelabs/pegasus_index.py +311 -0
  542. lfx/components/twelvelabs/split_video.py +301 -0
  543. lfx/components/twelvelabs/text_embeddings.py +57 -0
  544. lfx/components/twelvelabs/twelvelabs_pegasus.py +408 -0
  545. lfx/components/twelvelabs/video_embeddings.py +100 -0
  546. lfx/components/twelvelabs/video_file.py +191 -0
  547. lfx/components/unstructured/__init__.py +3 -0
  548. lfx/components/unstructured/unstructured.py +121 -0
  549. lfx/components/upstash/__init__.py +34 -0
  550. lfx/components/upstash/upstash.py +124 -0
  551. lfx/components/utilities/__init__.py +43 -0
  552. lfx/components/utilities/calculator_core.py +89 -0
  553. lfx/components/utilities/current_date.py +42 -0
  554. lfx/components/utilities/id_generator.py +42 -0
  555. lfx/components/utilities/python_repl_core.py +98 -0
  556. lfx/components/vectara/__init__.py +37 -0
  557. lfx/components/vectara/vectara.py +97 -0
  558. lfx/components/vectara/vectara_rag.py +164 -0
  559. lfx/components/vectorstores/__init__.py +34 -0
  560. lfx/components/vectorstores/local_db.py +270 -0
  561. lfx/components/vertexai/__init__.py +37 -0
  562. lfx/components/vertexai/vertexai.py +71 -0
  563. lfx/components/vertexai/vertexai_embeddings.py +67 -0
  564. lfx/components/vlmrun/__init__.py +34 -0
  565. lfx/components/vlmrun/vlmrun_transcription.py +224 -0
  566. lfx/components/weaviate/__init__.py +34 -0
  567. lfx/components/weaviate/weaviate.py +89 -0
  568. lfx/components/wikipedia/__init__.py +4 -0
  569. lfx/components/wikipedia/wikidata.py +86 -0
  570. lfx/components/wikipedia/wikipedia.py +53 -0
  571. lfx/components/wolframalpha/__init__.py +3 -0
  572. lfx/components/wolframalpha/wolfram_alpha_api.py +54 -0
  573. lfx/components/xai/__init__.py +32 -0
  574. lfx/components/xai/xai.py +167 -0
  575. lfx/components/yahoosearch/__init__.py +3 -0
  576. lfx/components/yahoosearch/yahoo.py +137 -0
  577. lfx/components/youtube/__init__.py +52 -0
  578. lfx/components/youtube/channel.py +227 -0
  579. lfx/components/youtube/comments.py +231 -0
  580. lfx/components/youtube/playlist.py +33 -0
  581. lfx/components/youtube/search.py +120 -0
  582. lfx/components/youtube/trending.py +285 -0
  583. lfx/components/youtube/video_details.py +263 -0
  584. lfx/components/youtube/youtube_transcripts.py +206 -0
  585. lfx/components/zep/__init__.py +3 -0
  586. lfx/components/zep/zep.py +45 -0
  587. lfx/constants.py +6 -0
  588. lfx/custom/__init__.py +7 -0
  589. lfx/custom/attributes.py +87 -0
  590. lfx/custom/code_parser/__init__.py +3 -0
  591. lfx/custom/code_parser/code_parser.py +361 -0
  592. lfx/custom/custom_component/__init__.py +0 -0
  593. lfx/custom/custom_component/base_component.py +128 -0
  594. lfx/custom/custom_component/component.py +1890 -0
  595. lfx/custom/custom_component/component_with_cache.py +8 -0
  596. lfx/custom/custom_component/custom_component.py +650 -0
  597. lfx/custom/dependency_analyzer.py +165 -0
  598. lfx/custom/directory_reader/__init__.py +3 -0
  599. lfx/custom/directory_reader/directory_reader.py +359 -0
  600. lfx/custom/directory_reader/utils.py +171 -0
  601. lfx/custom/eval.py +12 -0
  602. lfx/custom/schema.py +32 -0
  603. lfx/custom/tree_visitor.py +21 -0
  604. lfx/custom/utils.py +877 -0
  605. lfx/custom/validate.py +523 -0
  606. lfx/events/__init__.py +1 -0
  607. lfx/events/event_manager.py +110 -0
  608. lfx/exceptions/__init__.py +0 -0
  609. lfx/exceptions/component.py +15 -0
  610. lfx/field_typing/__init__.py +91 -0
  611. lfx/field_typing/constants.py +216 -0
  612. lfx/field_typing/range_spec.py +35 -0
  613. lfx/graph/__init__.py +6 -0
  614. lfx/graph/edge/__init__.py +0 -0
  615. lfx/graph/edge/base.py +300 -0
  616. lfx/graph/edge/schema.py +119 -0
  617. lfx/graph/edge/utils.py +0 -0
  618. lfx/graph/graph/__init__.py +0 -0
  619. lfx/graph/graph/ascii.py +202 -0
  620. lfx/graph/graph/base.py +2298 -0
  621. lfx/graph/graph/constants.py +63 -0
  622. lfx/graph/graph/runnable_vertices_manager.py +133 -0
  623. lfx/graph/graph/schema.py +53 -0
  624. lfx/graph/graph/state_model.py +66 -0
  625. lfx/graph/graph/utils.py +1024 -0
  626. lfx/graph/schema.py +75 -0
  627. lfx/graph/state/__init__.py +0 -0
  628. lfx/graph/state/model.py +250 -0
  629. lfx/graph/utils.py +206 -0
  630. lfx/graph/vertex/__init__.py +0 -0
  631. lfx/graph/vertex/base.py +826 -0
  632. lfx/graph/vertex/constants.py +0 -0
  633. lfx/graph/vertex/exceptions.py +4 -0
  634. lfx/graph/vertex/param_handler.py +316 -0
  635. lfx/graph/vertex/schema.py +26 -0
  636. lfx/graph/vertex/utils.py +19 -0
  637. lfx/graph/vertex/vertex_types.py +489 -0
  638. lfx/helpers/__init__.py +141 -0
  639. lfx/helpers/base_model.py +71 -0
  640. lfx/helpers/custom.py +13 -0
  641. lfx/helpers/data.py +167 -0
  642. lfx/helpers/flow.py +308 -0
  643. lfx/inputs/__init__.py +68 -0
  644. lfx/inputs/constants.py +2 -0
  645. lfx/inputs/input_mixin.py +352 -0
  646. lfx/inputs/inputs.py +718 -0
  647. lfx/inputs/validators.py +19 -0
  648. lfx/interface/__init__.py +6 -0
  649. lfx/interface/components.py +897 -0
  650. lfx/interface/importing/__init__.py +5 -0
  651. lfx/interface/importing/utils.py +39 -0
  652. lfx/interface/initialize/__init__.py +3 -0
  653. lfx/interface/initialize/loading.py +317 -0
  654. lfx/interface/listing.py +26 -0
  655. lfx/interface/run.py +16 -0
  656. lfx/interface/utils.py +111 -0
  657. lfx/io/__init__.py +63 -0
  658. lfx/io/schema.py +295 -0
  659. lfx/load/__init__.py +8 -0
  660. lfx/load/load.py +256 -0
  661. lfx/load/utils.py +99 -0
  662. lfx/log/__init__.py +5 -0
  663. lfx/log/logger.py +411 -0
  664. lfx/logging/__init__.py +11 -0
  665. lfx/logging/logger.py +24 -0
  666. lfx/memory/__init__.py +70 -0
  667. lfx/memory/stubs.py +302 -0
  668. lfx/processing/__init__.py +1 -0
  669. lfx/processing/process.py +238 -0
  670. lfx/processing/utils.py +25 -0
  671. lfx/py.typed +0 -0
  672. lfx/schema/__init__.py +66 -0
  673. lfx/schema/artifact.py +83 -0
  674. lfx/schema/content_block.py +62 -0
  675. lfx/schema/content_types.py +91 -0
  676. lfx/schema/cross_module.py +80 -0
  677. lfx/schema/data.py +309 -0
  678. lfx/schema/dataframe.py +210 -0
  679. lfx/schema/dotdict.py +74 -0
  680. lfx/schema/encoders.py +13 -0
  681. lfx/schema/graph.py +47 -0
  682. lfx/schema/image.py +184 -0
  683. lfx/schema/json_schema.py +186 -0
  684. lfx/schema/log.py +62 -0
  685. lfx/schema/message.py +493 -0
  686. lfx/schema/openai_responses_schemas.py +74 -0
  687. lfx/schema/properties.py +41 -0
  688. lfx/schema/schema.py +180 -0
  689. lfx/schema/serialize.py +13 -0
  690. lfx/schema/table.py +142 -0
  691. lfx/schema/validators.py +114 -0
  692. lfx/serialization/__init__.py +5 -0
  693. lfx/serialization/constants.py +2 -0
  694. lfx/serialization/serialization.py +314 -0
  695. lfx/services/__init__.py +26 -0
  696. lfx/services/base.py +28 -0
  697. lfx/services/cache/__init__.py +6 -0
  698. lfx/services/cache/base.py +183 -0
  699. lfx/services/cache/service.py +166 -0
  700. lfx/services/cache/utils.py +169 -0
  701. lfx/services/chat/__init__.py +1 -0
  702. lfx/services/chat/config.py +2 -0
  703. lfx/services/chat/schema.py +10 -0
  704. lfx/services/database/__init__.py +5 -0
  705. lfx/services/database/service.py +25 -0
  706. lfx/services/deps.py +194 -0
  707. lfx/services/factory.py +19 -0
  708. lfx/services/initialize.py +19 -0
  709. lfx/services/interfaces.py +103 -0
  710. lfx/services/manager.py +185 -0
  711. lfx/services/mcp_composer/__init__.py +6 -0
  712. lfx/services/mcp_composer/factory.py +16 -0
  713. lfx/services/mcp_composer/service.py +1441 -0
  714. lfx/services/schema.py +21 -0
  715. lfx/services/session.py +87 -0
  716. lfx/services/settings/__init__.py +3 -0
  717. lfx/services/settings/auth.py +133 -0
  718. lfx/services/settings/base.py +668 -0
  719. lfx/services/settings/constants.py +43 -0
  720. lfx/services/settings/factory.py +23 -0
  721. lfx/services/settings/feature_flags.py +11 -0
  722. lfx/services/settings/service.py +35 -0
  723. lfx/services/settings/utils.py +40 -0
  724. lfx/services/shared_component_cache/__init__.py +1 -0
  725. lfx/services/shared_component_cache/factory.py +30 -0
  726. lfx/services/shared_component_cache/service.py +9 -0
  727. lfx/services/storage/__init__.py +5 -0
  728. lfx/services/storage/local.py +185 -0
  729. lfx/services/storage/service.py +177 -0
  730. lfx/services/tracing/__init__.py +1 -0
  731. lfx/services/tracing/service.py +21 -0
  732. lfx/settings.py +6 -0
  733. lfx/template/__init__.py +6 -0
  734. lfx/template/field/__init__.py +0 -0
  735. lfx/template/field/base.py +260 -0
  736. lfx/template/field/prompt.py +15 -0
  737. lfx/template/frontend_node/__init__.py +6 -0
  738. lfx/template/frontend_node/base.py +214 -0
  739. lfx/template/frontend_node/constants.py +65 -0
  740. lfx/template/frontend_node/custom_components.py +79 -0
  741. lfx/template/template/__init__.py +0 -0
  742. lfx/template/template/base.py +100 -0
  743. lfx/template/utils.py +217 -0
  744. lfx/type_extraction/__init__.py +19 -0
  745. lfx/type_extraction/type_extraction.py +75 -0
  746. lfx/type_extraction.py +80 -0
  747. lfx/utils/__init__.py +1 -0
  748. lfx/utils/async_helpers.py +42 -0
  749. lfx/utils/component_utils.py +154 -0
  750. lfx/utils/concurrency.py +60 -0
  751. lfx/utils/connection_string_parser.py +11 -0
  752. lfx/utils/constants.py +233 -0
  753. lfx/utils/data_structure.py +212 -0
  754. lfx/utils/exceptions.py +22 -0
  755. lfx/utils/helpers.py +34 -0
  756. lfx/utils/image.py +79 -0
  757. lfx/utils/langflow_utils.py +52 -0
  758. lfx/utils/lazy_load.py +15 -0
  759. lfx/utils/request_utils.py +18 -0
  760. lfx/utils/schemas.py +139 -0
  761. lfx/utils/ssrf_protection.py +384 -0
  762. lfx/utils/util.py +626 -0
  763. lfx/utils/util_strings.py +56 -0
  764. lfx/utils/validate_cloud.py +26 -0
  765. lfx/utils/version.py +24 -0
  766. lfx_nightly-0.2.0.dev25.dist-info/METADATA +312 -0
  767. lfx_nightly-0.2.0.dev25.dist-info/RECORD +769 -0
  768. lfx_nightly-0.2.0.dev25.dist-info/WHEEL +4 -0
  769. lfx_nightly-0.2.0.dev25.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,1575 @@
1
+ from __future__ import annotations
2
+
3
+ import copy
4
+ import json
5
+ import time
6
+ import uuid
7
+ from concurrent.futures import ThreadPoolExecutor, as_completed
8
+ from typing import Any
9
+
10
+ from opensearchpy import OpenSearch, helpers
11
+ from opensearchpy.exceptions import OpenSearchException, RequestError
12
+
13
+ from lfx.base.vectorstores.model import LCVectorStoreComponent, check_cached_vector_store
14
+ from lfx.base.vectorstores.vector_store_connection_decorator import vector_store_connection
15
+ from lfx.io import BoolInput, DropdownInput, HandleInput, IntInput, MultilineInput, SecretStrInput, StrInput, TableInput
16
+ from lfx.log import logger
17
+ from lfx.schema.data import Data
18
+
19
+
20
+ def normalize_model_name(model_name: str) -> str:
21
+ """Normalize embedding model name for use as field suffix.
22
+
23
+ Converts model names to valid OpenSearch field names by replacing
24
+ special characters and ensuring alphanumeric format.
25
+
26
+ Args:
27
+ model_name: Original embedding model name (e.g., "text-embedding-3-small")
28
+
29
+ Returns:
30
+ Normalized field suffix (e.g., "text_embedding_3_small")
31
+ """
32
+ normalized = model_name.lower()
33
+ # Replace common separators with underscores
34
+ normalized = normalized.replace("-", "_").replace(":", "_").replace("/", "_").replace(".", "_")
35
+ # Remove any non-alphanumeric characters except underscores
36
+ normalized = "".join(c if c.isalnum() or c == "_" else "_" for c in normalized)
37
+ # Remove duplicate underscores
38
+ while "__" in normalized:
39
+ normalized = normalized.replace("__", "_")
40
+ return normalized.strip("_")
41
+
42
+
43
+ def get_embedding_field_name(model_name: str) -> str:
44
+ """Get the dynamic embedding field name for a model.
45
+
46
+ Args:
47
+ model_name: Embedding model name
48
+
49
+ Returns:
50
+ Field name in format: chunk_embedding_{normalized_model_name}
51
+ """
52
+ logger.info(f"chunk_embedding_{normalize_model_name(model_name)}")
53
+ return f"chunk_embedding_{normalize_model_name(model_name)}"
54
+
55
+
56
+ @vector_store_connection
57
+ class OpenSearchVectorStoreComponentMultimodalMultiEmbedding(LCVectorStoreComponent):
58
+ """OpenSearch Vector Store Component with Multi-Model Hybrid Search Capabilities.
59
+
60
+ This component provides vector storage and retrieval using OpenSearch, combining semantic
61
+ similarity search (KNN) with keyword-based search for optimal results. It supports:
62
+ - Multiple embedding models per index with dynamic field names
63
+ - Automatic detection and querying of all available embedding models
64
+ - Parallel embedding generation for multi-model search
65
+ - Document ingestion with model tracking
66
+ - Advanced filtering and aggregations
67
+ - Flexible authentication options
68
+
69
+ Features:
70
+ - Multi-model vector storage with dynamic fields (chunk_embedding_{model_name})
71
+ - Hybrid search combining multiple KNN queries (dis_max) + keyword matching
72
+ - Auto-detection of available models in the index
73
+ - Parallel query embedding generation for all detected models
74
+ - Vector storage with configurable engines (jvector, nmslib, faiss, lucene)
75
+ - Flexible authentication (Basic auth, JWT tokens)
76
+
77
+ Model Name Resolution:
78
+ - Priority: deployment > model > model_name attributes
79
+ - This ensures correct matching between embedding objects and index fields
80
+ - When multiple embeddings are provided, specify embedding_model_name to select which one to use
81
+ - During search, each detected model in the index is matched to its corresponding embedding object
82
+ """
83
+
84
+ display_name: str = "OpenSearch (Multi-Model Multi-Embedding)"
85
+ icon: str = "OpenSearch"
86
+ description: str = (
87
+ "Store and search documents using OpenSearch with multi-model hybrid semantic and keyword search."
88
+ )
89
+
90
+ # Keys we consider baseline
91
+ default_keys: list[str] = [
92
+ "opensearch_url",
93
+ "index_name",
94
+ *[i.name for i in LCVectorStoreComponent.inputs], # search_query, add_documents, etc.
95
+ "embedding",
96
+ "embedding_model_name",
97
+ "vector_field",
98
+ "number_of_results",
99
+ "auth_mode",
100
+ "username",
101
+ "password",
102
+ "jwt_token",
103
+ "jwt_header",
104
+ "bearer_prefix",
105
+ "use_ssl",
106
+ "verify_certs",
107
+ "filter_expression",
108
+ "engine",
109
+ "space_type",
110
+ "ef_construction",
111
+ "m",
112
+ "num_candidates",
113
+ "docs_metadata",
114
+ ]
115
+
116
+ inputs = [
117
+ TableInput(
118
+ name="docs_metadata",
119
+ display_name="Document Metadata",
120
+ info=(
121
+ "Additional metadata key-value pairs to be added to all ingested documents. "
122
+ "Useful for tagging documents with source information, categories, or other custom attributes."
123
+ ),
124
+ table_schema=[
125
+ {
126
+ "name": "key",
127
+ "display_name": "Key",
128
+ "type": "str",
129
+ "description": "Key name",
130
+ },
131
+ {
132
+ "name": "value",
133
+ "display_name": "Value",
134
+ "type": "str",
135
+ "description": "Value of the metadata",
136
+ },
137
+ ],
138
+ value=[],
139
+ input_types=["Data"],
140
+ ),
141
+ StrInput(
142
+ name="opensearch_url",
143
+ display_name="OpenSearch URL",
144
+ value="http://localhost:9200",
145
+ info=(
146
+ "The connection URL for your OpenSearch cluster "
147
+ "(e.g., http://localhost:9200 for local development or your cloud endpoint)."
148
+ ),
149
+ ),
150
+ StrInput(
151
+ name="index_name",
152
+ display_name="Index Name",
153
+ value="langflow",
154
+ info=(
155
+ "The OpenSearch index name where documents will be stored and searched. "
156
+ "Will be created automatically if it doesn't exist."
157
+ ),
158
+ ),
159
+ DropdownInput(
160
+ name="engine",
161
+ display_name="Vector Engine",
162
+ options=["jvector", "nmslib", "faiss", "lucene"],
163
+ value="jvector",
164
+ info=(
165
+ "Vector search engine for similarity calculations. 'jvector' is recommended for most use cases. "
166
+ "Note: Amazon OpenSearch Serverless only supports 'nmslib' or 'faiss'."
167
+ ),
168
+ advanced=True,
169
+ ),
170
+ DropdownInput(
171
+ name="space_type",
172
+ display_name="Distance Metric",
173
+ options=["l2", "l1", "cosinesimil", "linf", "innerproduct"],
174
+ value="l2",
175
+ info=(
176
+ "Distance metric for calculating vector similarity. 'l2' (Euclidean) is most common, "
177
+ "'cosinesimil' for cosine similarity, 'innerproduct' for dot product."
178
+ ),
179
+ advanced=True,
180
+ ),
181
+ IntInput(
182
+ name="ef_construction",
183
+ display_name="EF Construction",
184
+ value=512,
185
+ info=(
186
+ "Size of the dynamic candidate list during index construction. "
187
+ "Higher values improve recall but increase indexing time and memory usage."
188
+ ),
189
+ advanced=True,
190
+ ),
191
+ IntInput(
192
+ name="m",
193
+ display_name="M Parameter",
194
+ value=16,
195
+ info=(
196
+ "Number of bidirectional connections for each vector in the HNSW graph. "
197
+ "Higher values improve search quality but increase memory usage and indexing time."
198
+ ),
199
+ advanced=True,
200
+ ),
201
+ IntInput(
202
+ name="num_candidates",
203
+ display_name="Candidate Pool Size",
204
+ value=1000,
205
+ info=(
206
+ "Number of approximate neighbors to consider for each KNN query. "
207
+ "Some OpenSearch deployments do not support this parameter; set to 0 to disable."
208
+ ),
209
+ advanced=True,
210
+ ),
211
+ *LCVectorStoreComponent.inputs, # includes search_query, add_documents, etc.
212
+ HandleInput(name="embedding", display_name="Embedding", input_types=["Embeddings"], is_list=True),
213
+ StrInput(
214
+ name="embedding_model_name",
215
+ display_name="Embedding Model Name",
216
+ value="",
217
+ info=(
218
+ "Name of the embedding model to use for ingestion. This selects which embedding from the list "
219
+ "will be used to embed documents. Matches on deployment, model, model_id, or model_name. "
220
+ "For duplicate deployments, use combined format: 'deployment:model' "
221
+ "(e.g., 'text-embedding-ada-002:text-embedding-3-large'). "
222
+ "Leave empty to use the first embedding. Error message will show all available identifiers."
223
+ ),
224
+ advanced=False,
225
+ ),
226
+ StrInput(
227
+ name="vector_field",
228
+ display_name="Legacy Vector Field Name",
229
+ value="chunk_embedding",
230
+ advanced=True,
231
+ info=(
232
+ "Legacy field name for backward compatibility. New documents use dynamic fields "
233
+ "(chunk_embedding_{model_name}) based on the embedding_model_name."
234
+ ),
235
+ ),
236
+ IntInput(
237
+ name="number_of_results",
238
+ display_name="Default Result Limit",
239
+ value=10,
240
+ advanced=True,
241
+ info=(
242
+ "Default maximum number of search results to return when no limit is "
243
+ "specified in the filter expression."
244
+ ),
245
+ ),
246
+ MultilineInput(
247
+ name="filter_expression",
248
+ display_name="Search Filters (JSON)",
249
+ value="",
250
+ info=(
251
+ "Optional JSON configuration for search filtering, result limits, and score thresholds.\n\n"
252
+ "Format 1 - Explicit filters:\n"
253
+ '{"filter": [{"term": {"filename":"doc.pdf"}}, '
254
+ '{"terms":{"owner":["user1","user2"]}}], "limit": 10, "score_threshold": 1.6}\n\n'
255
+ "Format 2 - Context-style mapping:\n"
256
+ '{"data_sources":["file.pdf"], "document_types":["application/pdf"], "owners":["user123"]}\n\n'
257
+ "Use __IMPOSSIBLE_VALUE__ as placeholder to ignore specific filters."
258
+ ),
259
+ ),
260
+ # ----- Auth controls (dynamic) -----
261
+ DropdownInput(
262
+ name="auth_mode",
263
+ display_name="Authentication Mode",
264
+ value="basic",
265
+ options=["basic", "jwt"],
266
+ info=(
267
+ "Authentication method: 'basic' for username/password authentication, "
268
+ "or 'jwt' for JSON Web Token (Bearer) authentication."
269
+ ),
270
+ real_time_refresh=True,
271
+ advanced=False,
272
+ ),
273
+ StrInput(
274
+ name="username",
275
+ display_name="Username",
276
+ value="admin",
277
+ show=True,
278
+ ),
279
+ SecretStrInput(
280
+ name="password",
281
+ display_name="OpenSearch Password",
282
+ value="admin",
283
+ show=True,
284
+ ),
285
+ SecretStrInput(
286
+ name="jwt_token",
287
+ display_name="JWT Token",
288
+ value="JWT",
289
+ load_from_db=False,
290
+ show=False,
291
+ info=(
292
+ "Valid JSON Web Token for authentication. "
293
+ "Will be sent in the Authorization header (with optional 'Bearer ' prefix)."
294
+ ),
295
+ ),
296
+ StrInput(
297
+ name="jwt_header",
298
+ display_name="JWT Header Name",
299
+ value="Authorization",
300
+ show=False,
301
+ advanced=True,
302
+ ),
303
+ BoolInput(
304
+ name="bearer_prefix",
305
+ display_name="Prefix 'Bearer '",
306
+ value=True,
307
+ show=False,
308
+ advanced=True,
309
+ ),
310
+ # ----- TLS -----
311
+ BoolInput(
312
+ name="use_ssl",
313
+ display_name="Use SSL/TLS",
314
+ value=True,
315
+ advanced=True,
316
+ info="Enable SSL/TLS encryption for secure connections to OpenSearch.",
317
+ ),
318
+ BoolInput(
319
+ name="verify_certs",
320
+ display_name="Verify SSL Certificates",
321
+ value=False,
322
+ advanced=True,
323
+ info=(
324
+ "Verify SSL certificates when connecting. "
325
+ "Disable for self-signed certificates in development environments."
326
+ ),
327
+ ),
328
+ ]
329
+
330
+ def _get_embedding_model_name(self, embedding_obj=None) -> str:
331
+ """Get the embedding model name from component config or embedding object.
332
+
333
+ Priority: deployment > model > model_id > model_name
334
+ This ensures we use the actual model being deployed, not just the configured model.
335
+ Supports multiple embedding providers (OpenAI, Watsonx, Cohere, etc.)
336
+
337
+ Args:
338
+ embedding_obj: Specific embedding object to get name from (optional)
339
+
340
+ Returns:
341
+ Embedding model name
342
+
343
+ Raises:
344
+ ValueError: If embedding model name cannot be determined
345
+ """
346
+ # First try explicit embedding_model_name input
347
+ if hasattr(self, "embedding_model_name") and self.embedding_model_name:
348
+ return self.embedding_model_name.strip()
349
+
350
+ # Try to get from provided embedding object
351
+ if embedding_obj:
352
+ # Priority: deployment > model > model_id > model_name
353
+ if hasattr(embedding_obj, "deployment") and embedding_obj.deployment:
354
+ return str(embedding_obj.deployment)
355
+ if hasattr(embedding_obj, "model") and embedding_obj.model:
356
+ return str(embedding_obj.model)
357
+ if hasattr(embedding_obj, "model_id") and embedding_obj.model_id:
358
+ return str(embedding_obj.model_id)
359
+ if hasattr(embedding_obj, "model_name") and embedding_obj.model_name:
360
+ return str(embedding_obj.model_name)
361
+
362
+ # Try to get from embedding component (legacy single embedding)
363
+ if hasattr(self, "embedding") and self.embedding:
364
+ # Handle list of embeddings
365
+ if isinstance(self.embedding, list) and len(self.embedding) > 0:
366
+ first_emb = self.embedding[0]
367
+ if hasattr(first_emb, "deployment") and first_emb.deployment:
368
+ return str(first_emb.deployment)
369
+ if hasattr(first_emb, "model") and first_emb.model:
370
+ return str(first_emb.model)
371
+ if hasattr(first_emb, "model_id") and first_emb.model_id:
372
+ return str(first_emb.model_id)
373
+ if hasattr(first_emb, "model_name") and first_emb.model_name:
374
+ return str(first_emb.model_name)
375
+ # Handle single embedding
376
+ elif not isinstance(self.embedding, list):
377
+ if hasattr(self.embedding, "deployment") and self.embedding.deployment:
378
+ return str(self.embedding.deployment)
379
+ if hasattr(self.embedding, "model") and self.embedding.model:
380
+ return str(self.embedding.model)
381
+ if hasattr(self.embedding, "model_id") and self.embedding.model_id:
382
+ return str(self.embedding.model_id)
383
+ if hasattr(self.embedding, "model_name") and self.embedding.model_name:
384
+ return str(self.embedding.model_name)
385
+
386
+ msg = (
387
+ "Could not determine embedding model name. "
388
+ "Please set the 'embedding_model_name' field or ensure the embedding component "
389
+ "has a 'deployment', 'model', 'model_id', or 'model_name' attribute."
390
+ )
391
+ raise ValueError(msg)
392
+
393
+ # ---------- helper functions for index management ----------
394
+ def _default_text_mapping(
395
+ self,
396
+ dim: int,
397
+ engine: str = "jvector",
398
+ space_type: str = "l2",
399
+ ef_search: int = 512,
400
+ ef_construction: int = 100,
401
+ m: int = 16,
402
+ vector_field: str = "vector_field",
403
+ ) -> dict[str, Any]:
404
+ """Create the default OpenSearch index mapping for vector search.
405
+
406
+ This method generates the index configuration with k-NN settings optimized
407
+ for approximate nearest neighbor search using the specified vector engine.
408
+ Includes the embedding_model keyword field for tracking which model was used.
409
+
410
+ Args:
411
+ dim: Dimensionality of the vector embeddings
412
+ engine: Vector search engine (jvector, nmslib, faiss, lucene)
413
+ space_type: Distance metric for similarity calculation
414
+ ef_search: Size of dynamic list used during search
415
+ ef_construction: Size of dynamic list used during index construction
416
+ m: Number of bidirectional links for each vector
417
+ vector_field: Name of the field storing vector embeddings
418
+
419
+ Returns:
420
+ Dictionary containing OpenSearch index mapping configuration
421
+ """
422
+ return {
423
+ "settings": {"index": {"knn": True, "knn.algo_param.ef_search": ef_search}},
424
+ "mappings": {
425
+ "properties": {
426
+ vector_field: {
427
+ "type": "knn_vector",
428
+ "dimension": dim,
429
+ "method": {
430
+ "name": "disk_ann",
431
+ "space_type": space_type,
432
+ "engine": engine,
433
+ "parameters": {"ef_construction": ef_construction, "m": m},
434
+ },
435
+ },
436
+ "embedding_model": {"type": "keyword"}, # Track which model was used
437
+ "embedding_dimensions": {"type": "integer"},
438
+ }
439
+ },
440
+ }
441
+
442
+ def _ensure_embedding_field_mapping(
443
+ self,
444
+ client: OpenSearch,
445
+ index_name: str,
446
+ field_name: str,
447
+ dim: int,
448
+ engine: str,
449
+ space_type: str,
450
+ ef_construction: int,
451
+ m: int,
452
+ ) -> None:
453
+ """Lazily add a dynamic embedding field to the index if it doesn't exist.
454
+
455
+ This allows adding new embedding models without recreating the entire index.
456
+ Also ensures the embedding_model tracking field exists.
457
+
458
+ Args:
459
+ client: OpenSearch client instance
460
+ index_name: Target index name
461
+ field_name: Dynamic field name for this embedding model
462
+ dim: Vector dimensionality
463
+ engine: Vector search engine
464
+ space_type: Distance metric
465
+ ef_construction: Construction parameter
466
+ m: HNSW parameter
467
+ """
468
+ try:
469
+ mapping = {
470
+ "properties": {
471
+ field_name: {
472
+ "type": "knn_vector",
473
+ "dimension": dim,
474
+ "method": {
475
+ "name": "disk_ann",
476
+ "space_type": space_type,
477
+ "engine": engine,
478
+ "parameters": {"ef_construction": ef_construction, "m": m},
479
+ },
480
+ },
481
+ # Also ensure the embedding_model tracking field exists as keyword
482
+ "embedding_model": {"type": "keyword"},
483
+ "embedding_dimensions": {"type": "integer"},
484
+ }
485
+ }
486
+ client.indices.put_mapping(index=index_name, body=mapping)
487
+ logger.info(f"Added/updated embedding field mapping: {field_name}")
488
+ except Exception as e:
489
+ logger.warning(f"Could not add embedding field mapping for {field_name}: {e}")
490
+ raise
491
+
492
+ properties = self._get_index_properties(client)
493
+ if not self._is_knn_vector_field(properties, field_name):
494
+ msg = f"Field '{field_name}' is not mapped as knn_vector. Current mapping: {properties.get(field_name)}"
495
+ logger.aerror(msg)
496
+ raise ValueError(msg)
497
+
498
+ def _validate_aoss_with_engines(self, *, is_aoss: bool, engine: str) -> None:
499
+ """Validate engine compatibility with Amazon OpenSearch Serverless (AOSS).
500
+
501
+ Amazon OpenSearch Serverless has restrictions on which vector engines
502
+ can be used. This method ensures the selected engine is compatible.
503
+
504
+ Args:
505
+ is_aoss: Whether the connection is to Amazon OpenSearch Serverless
506
+ engine: The selected vector search engine
507
+
508
+ Raises:
509
+ ValueError: If AOSS is used with an incompatible engine
510
+ """
511
+ if is_aoss and engine not in {"nmslib", "faiss"}:
512
+ msg = "Amazon OpenSearch Service Serverless only supports `nmslib` or `faiss` engines"
513
+ raise ValueError(msg)
514
+
515
+ def _is_aoss_enabled(self, http_auth: Any) -> bool:
516
+ """Determine if Amazon OpenSearch Serverless (AOSS) is being used.
517
+
518
+ Args:
519
+ http_auth: The HTTP authentication object
520
+
521
+ Returns:
522
+ True if AOSS is enabled, False otherwise
523
+ """
524
+ return http_auth is not None and hasattr(http_auth, "service") and http_auth.service == "aoss"
525
+
526
+ def _bulk_ingest_embeddings(
527
+ self,
528
+ client: OpenSearch,
529
+ index_name: str,
530
+ embeddings: list[list[float]],
531
+ texts: list[str],
532
+ metadatas: list[dict] | None = None,
533
+ ids: list[str] | None = None,
534
+ vector_field: str = "vector_field",
535
+ text_field: str = "text",
536
+ embedding_model: str = "unknown",
537
+ mapping: dict | None = None,
538
+ max_chunk_bytes: int | None = 1 * 1024 * 1024,
539
+ *,
540
+ is_aoss: bool = False,
541
+ ) -> list[str]:
542
+ """Efficiently ingest multiple documents with embeddings into OpenSearch.
543
+
544
+ This method uses bulk operations to insert documents with their vector
545
+ embeddings and metadata into the specified OpenSearch index. Each document
546
+ is tagged with the embedding_model name for tracking.
547
+
548
+ Args:
549
+ client: OpenSearch client instance
550
+ index_name: Target index for document storage
551
+ embeddings: List of vector embeddings for each document
552
+ texts: List of document texts
553
+ metadatas: Optional metadata dictionaries for each document
554
+ ids: Optional document IDs (UUIDs generated if not provided)
555
+ vector_field: Field name for storing vector embeddings
556
+ text_field: Field name for storing document text
557
+ embedding_model: Name of the embedding model used
558
+ mapping: Optional index mapping configuration
559
+ max_chunk_bytes: Maximum size per bulk request chunk
560
+ is_aoss: Whether using Amazon OpenSearch Serverless
561
+
562
+ Returns:
563
+ List of document IDs that were successfully ingested
564
+ """
565
+ if not mapping:
566
+ mapping = {}
567
+
568
+ requests = []
569
+ return_ids = []
570
+ vector_dimensions = len(embeddings[0]) if embeddings else None
571
+
572
+ for i, text in enumerate(texts):
573
+ metadata = metadatas[i] if metadatas else {}
574
+ if vector_dimensions is not None and "embedding_dimensions" not in metadata:
575
+ metadata = {**metadata, "embedding_dimensions": vector_dimensions}
576
+ _id = ids[i] if ids else str(uuid.uuid4())
577
+ request = {
578
+ "_op_type": "index",
579
+ "_index": index_name,
580
+ vector_field: embeddings[i],
581
+ text_field: text,
582
+ "embedding_model": embedding_model, # Track which model was used
583
+ **metadata,
584
+ }
585
+ if is_aoss:
586
+ request["id"] = _id
587
+ else:
588
+ request["_id"] = _id
589
+ requests.append(request)
590
+ return_ids.append(_id)
591
+ if metadatas:
592
+ self.log(f"Sample metadata: {metadatas[0] if metadatas else {}}")
593
+ helpers.bulk(client, requests, max_chunk_bytes=max_chunk_bytes)
594
+ return return_ids
595
+
596
+ # ---------- auth / client ----------
597
+ def _build_auth_kwargs(self) -> dict[str, Any]:
598
+ """Build authentication configuration for OpenSearch client.
599
+
600
+ Constructs the appropriate authentication parameters based on the
601
+ selected auth mode (basic username/password or JWT token).
602
+
603
+ Returns:
604
+ Dictionary containing authentication configuration
605
+
606
+ Raises:
607
+ ValueError: If required authentication parameters are missing
608
+ """
609
+ mode = (self.auth_mode or "basic").strip().lower()
610
+ if mode == "jwt":
611
+ token = (self.jwt_token or "").strip()
612
+ if not token:
613
+ msg = "Auth Mode is 'jwt' but no jwt_token was provided."
614
+ raise ValueError(msg)
615
+ header_name = (self.jwt_header or "Authorization").strip()
616
+ header_value = f"Bearer {token}" if self.bearer_prefix else token
617
+ return {"headers": {header_name: header_value}}
618
+ user = (self.username or "").strip()
619
+ pwd = (self.password or "").strip()
620
+ if not user or not pwd:
621
+ msg = "Auth Mode is 'basic' but username/password are missing."
622
+ raise ValueError(msg)
623
+ return {"http_auth": (user, pwd)}
624
+
625
+ def build_client(self) -> OpenSearch:
626
+ """Create and configure an OpenSearch client instance.
627
+
628
+ Returns:
629
+ Configured OpenSearch client ready for operations
630
+ """
631
+ auth_kwargs = self._build_auth_kwargs()
632
+ return OpenSearch(
633
+ hosts=[self.opensearch_url],
634
+ use_ssl=self.use_ssl,
635
+ verify_certs=self.verify_certs,
636
+ ssl_assert_hostname=False,
637
+ ssl_show_warn=False,
638
+ **auth_kwargs,
639
+ )
640
+
641
+ @check_cached_vector_store
642
+ def build_vector_store(self) -> OpenSearch:
643
+ # Return raw OpenSearch client as our "vector store."
644
+ self.log(self.ingest_data)
645
+ client = self.build_client()
646
+ logger.warning(f"Embedding: {self.embedding}")
647
+ self._add_documents_to_vector_store(client=client)
648
+ return client
649
+
650
+ # ---------- ingest ----------
651
+ def _add_documents_to_vector_store(self, client: OpenSearch) -> None:
652
+ """Process and ingest documents into the OpenSearch vector store.
653
+
654
+ This method handles the complete document ingestion pipeline:
655
+ - Prepares document data and metadata
656
+ - Generates vector embeddings using the selected model
657
+ - Creates appropriate index mappings with dynamic field names
658
+ - Bulk inserts documents with vectors and model tracking
659
+
660
+ Args:
661
+ client: OpenSearch client for performing operations
662
+ """
663
+ # Convert DataFrame to Data if needed using parent's method
664
+ self.ingest_data = self._prepare_ingest_data()
665
+
666
+ docs = self.ingest_data or []
667
+ if not docs:
668
+ self.log("No documents to ingest.")
669
+ return
670
+
671
+ if not self.embedding:
672
+ msg = "Embedding handle is required to embed documents."
673
+ raise ValueError(msg)
674
+
675
+ # Normalize embedding to list
676
+ embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]
677
+
678
+ if not embeddings_list:
679
+ msg = "At least one embedding is required to embed documents."
680
+ raise ValueError(msg)
681
+
682
+ self.log(f"Available embedding models: {len(embeddings_list)}")
683
+
684
+ # Select the embedding to use for ingestion
685
+ selected_embedding = None
686
+ embedding_model = None
687
+
688
+ # If embedding_model_name is specified, find matching embedding
689
+ if hasattr(self, "embedding_model_name") and self.embedding_model_name and self.embedding_model_name.strip():
690
+ target_model_name = self.embedding_model_name.strip()
691
+ self.log(f"Looking for embedding model: {target_model_name}")
692
+
693
+ for emb_obj in embeddings_list:
694
+ # Check all possible model identifiers (deployment, model, model_id, model_name)
695
+ # Also check available_models list from EmbeddingsWithModels
696
+ possible_names = []
697
+ deployment = getattr(emb_obj, "deployment", None)
698
+ model = getattr(emb_obj, "model", None)
699
+ model_id = getattr(emb_obj, "model_id", None)
700
+ model_name = getattr(emb_obj, "model_name", None)
701
+ available_models_attr = getattr(emb_obj, "available_models", None)
702
+
703
+ if deployment:
704
+ possible_names.append(str(deployment))
705
+ if model:
706
+ possible_names.append(str(model))
707
+ if model_id:
708
+ possible_names.append(str(model_id))
709
+ if model_name:
710
+ possible_names.append(str(model_name))
711
+
712
+ # Also add combined identifier
713
+ if deployment and model and deployment != model:
714
+ possible_names.append(f"{deployment}:{model}")
715
+
716
+ # Add all models from available_models dict
717
+ if available_models_attr and isinstance(available_models_attr, dict):
718
+ possible_names.extend(
719
+ str(model_key).strip()
720
+ for model_key in available_models_attr
721
+ if model_key and str(model_key).strip()
722
+ )
723
+
724
+ # Match if target matches any of the possible names
725
+ if target_model_name in possible_names:
726
+ # Check if target is in available_models dict - use dedicated instance
727
+ if (
728
+ available_models_attr
729
+ and isinstance(available_models_attr, dict)
730
+ and target_model_name in available_models_attr
731
+ ):
732
+ # Use the dedicated embedding instance from the dict
733
+ selected_embedding = available_models_attr[target_model_name]
734
+ embedding_model = target_model_name
735
+ self.log(f"Found dedicated embedding instance for '{embedding_model}' in available_models dict")
736
+ else:
737
+ # Traditional identifier match
738
+ selected_embedding = emb_obj
739
+ embedding_model = self._get_embedding_model_name(emb_obj)
740
+ self.log(f"Found matching embedding model: {embedding_model} (matched on: {target_model_name})")
741
+ break
742
+
743
+ if not selected_embedding:
744
+ # Build detailed list of available embeddings with all their identifiers
745
+ available_info = []
746
+ for idx, emb in enumerate(embeddings_list):
747
+ emb_type = type(emb).__name__
748
+ identifiers = []
749
+ deployment = getattr(emb, "deployment", None)
750
+ model = getattr(emb, "model", None)
751
+ model_id = getattr(emb, "model_id", None)
752
+ model_name = getattr(emb, "model_name", None)
753
+ available_models_attr = getattr(emb, "available_models", None)
754
+
755
+ if deployment:
756
+ identifiers.append(f"deployment='{deployment}'")
757
+ if model:
758
+ identifiers.append(f"model='{model}'")
759
+ if model_id:
760
+ identifiers.append(f"model_id='{model_id}'")
761
+ if model_name:
762
+ identifiers.append(f"model_name='{model_name}'")
763
+
764
+ # Add combined identifier as an option
765
+ if deployment and model and deployment != model:
766
+ identifiers.append(f"combined='{deployment}:{model}'")
767
+
768
+ # Add available_models dict if present
769
+ if available_models_attr and isinstance(available_models_attr, dict):
770
+ identifiers.append(f"available_models={list(available_models_attr.keys())}")
771
+
772
+ available_info.append(
773
+ f" [{idx}] {emb_type}: {', '.join(identifiers) if identifiers else 'No identifiers'}"
774
+ )
775
+
776
+ msg = (
777
+ f"Embedding model '{target_model_name}' not found in available embeddings.\n\n"
778
+ f"Available embeddings:\n" + "\n".join(available_info) + "\n\n"
779
+ "Please set 'embedding_model_name' to one of the identifier values shown above "
780
+ "(use the value after the '=' sign, without quotes).\n"
781
+ "For duplicate deployments, use the 'combined' format.\n"
782
+ "Or leave it empty to use the first embedding."
783
+ )
784
+ raise ValueError(msg)
785
+ else:
786
+ # Use first embedding if no model name specified
787
+ selected_embedding = embeddings_list[0]
788
+ embedding_model = self._get_embedding_model_name(selected_embedding)
789
+ self.log(f"No embedding_model_name specified, using first embedding: {embedding_model}")
790
+
791
+ dynamic_field_name = get_embedding_field_name(embedding_model)
792
+
793
+ self.log(f"Using embedding model for ingestion: {embedding_model}")
794
+ self.log(f"Dynamic vector field: {dynamic_field_name}")
795
+
796
+ # Log embedding details for debugging
797
+ if hasattr(selected_embedding, "deployment"):
798
+ logger.info(f"Embedding deployment: {selected_embedding.deployment}")
799
+ if hasattr(selected_embedding, "model"):
800
+ logger.info(f"Embedding model: {selected_embedding.model}")
801
+ if hasattr(selected_embedding, "model_id"):
802
+ logger.info(f"Embedding model_id: {selected_embedding.model_id}")
803
+ if hasattr(selected_embedding, "dimensions"):
804
+ logger.info(f"Embedding dimensions: {selected_embedding.dimensions}")
805
+ if hasattr(selected_embedding, "available_models"):
806
+ logger.info(f"Embedding available_models: {selected_embedding.available_models}")
807
+
808
+ # No model switching needed - each model in available_models has its own dedicated instance
809
+ # The selected_embedding is already configured correctly for the target model
810
+ logger.info(f"Using embedding instance for '{embedding_model}' - pre-configured and ready to use")
811
+
812
+ # Extract texts and metadata from documents
813
+ texts = []
814
+ metadatas = []
815
+ # Process docs_metadata table input into a dict
816
+ additional_metadata = {}
817
+ if hasattr(self, "docs_metadata") and self.docs_metadata:
818
+ logger.info(f"[LF] Docs metadata {self.docs_metadata}")
819
+ if isinstance(self.docs_metadata[-1], Data):
820
+ logger.info(f"[LF] Docs metadata is a Data object {self.docs_metadata}")
821
+ self.docs_metadata = self.docs_metadata[-1].data
822
+ logger.info(f"[LF] Docs metadata is a Data object {self.docs_metadata}")
823
+ additional_metadata.update(self.docs_metadata)
824
+ else:
825
+ for item in self.docs_metadata:
826
+ if isinstance(item, dict) and "key" in item and "value" in item:
827
+ additional_metadata[item["key"]] = item["value"]
828
+ # Replace string "None" values with actual None
829
+ for key, value in additional_metadata.items():
830
+ if value == "None":
831
+ additional_metadata[key] = None
832
+ logger.info(f"[LF] Additional metadata {additional_metadata}")
833
+ for doc_obj in docs:
834
+ data_copy = json.loads(doc_obj.model_dump_json())
835
+ text = data_copy.pop(doc_obj.text_key, doc_obj.default_value)
836
+ texts.append(text)
837
+
838
+ # Merge additional metadata from table input
839
+ data_copy.update(additional_metadata)
840
+
841
+ metadatas.append(data_copy)
842
+ self.log(metadatas)
843
+
844
+ # Generate embeddings (threaded for concurrency) with retries
845
+ def embed_chunk(chunk_text: str) -> list[float]:
846
+ return selected_embedding.embed_documents([chunk_text])[0]
847
+
848
+ vectors: list[list[float]] | None = None
849
+ last_exception: Exception | None = None
850
+ delay = 1.0
851
+ attempts = 0
852
+ max_attempts = 3
853
+
854
+ while attempts < max_attempts:
855
+ attempts += 1
856
+ try:
857
+ max_workers = min(max(len(texts), 1), 8)
858
+ with ThreadPoolExecutor(max_workers=max_workers) as executor:
859
+ futures = {executor.submit(embed_chunk, chunk): idx for idx, chunk in enumerate(texts)}
860
+ vectors = [None] * len(texts)
861
+ for future in as_completed(futures):
862
+ idx = futures[future]
863
+ vectors[idx] = future.result()
864
+ break
865
+ except Exception as exc:
866
+ last_exception = exc
867
+ if attempts >= max_attempts:
868
+ logger.error(
869
+ f"Embedding generation failed for model {embedding_model} after retries",
870
+ error=str(exc),
871
+ )
872
+ raise
873
+ logger.warning(
874
+ "Threaded embedding generation failed for model %s (attempt %s/%s), retrying in %.1fs",
875
+ embedding_model,
876
+ attempts,
877
+ max_attempts,
878
+ delay,
879
+ )
880
+ time.sleep(delay)
881
+ delay = min(delay * 2, 8.0)
882
+
883
+ if vectors is None:
884
+ raise RuntimeError(
885
+ f"Embedding generation failed for {embedding_model}: {last_exception}"
886
+ if last_exception
887
+ else f"Embedding generation failed for {embedding_model}"
888
+ )
889
+
890
+ if not vectors:
891
+ self.log(f"No vectors generated from documents for model {embedding_model}.")
892
+ return
893
+
894
+ # Get vector dimension for mapping
895
+ dim = len(vectors[0]) if vectors else 768 # default fallback
896
+
897
+ # Check for AOSS
898
+ auth_kwargs = self._build_auth_kwargs()
899
+ is_aoss = self._is_aoss_enabled(auth_kwargs.get("http_auth"))
900
+
901
+ # Validate engine with AOSS
902
+ engine = getattr(self, "engine", "jvector")
903
+ self._validate_aoss_with_engines(is_aoss=is_aoss, engine=engine)
904
+
905
+ # Create mapping with proper KNN settings
906
+ space_type = getattr(self, "space_type", "l2")
907
+ ef_construction = getattr(self, "ef_construction", 512)
908
+ m = getattr(self, "m", 16)
909
+
910
+ mapping = self._default_text_mapping(
911
+ dim=dim,
912
+ engine=engine,
913
+ space_type=space_type,
914
+ ef_construction=ef_construction,
915
+ m=m,
916
+ vector_field=dynamic_field_name, # Use dynamic field name
917
+ )
918
+
919
+ # Ensure index exists with baseline mapping
920
+ try:
921
+ if not client.indices.exists(index=self.index_name):
922
+ self.log(f"Creating index '{self.index_name}' with base mapping")
923
+ client.indices.create(index=self.index_name, body=mapping)
924
+ except RequestError as creation_error:
925
+ if creation_error.error != "resource_already_exists_exception":
926
+ logger.warning(f"Failed to create index '{self.index_name}': {creation_error}")
927
+
928
+ # Ensure the dynamic field exists in the index
929
+ self._ensure_embedding_field_mapping(
930
+ client=client,
931
+ index_name=self.index_name,
932
+ field_name=dynamic_field_name,
933
+ dim=dim,
934
+ engine=engine,
935
+ space_type=space_type,
936
+ ef_construction=ef_construction,
937
+ m=m,
938
+ )
939
+
940
+ self.log(f"Indexing {len(texts)} documents into '{self.index_name}' with model '{embedding_model}'...")
941
+ logger.info(f"Will store embeddings in field: {dynamic_field_name}")
942
+ logger.info(f"Will tag documents with embedding_model: {embedding_model}")
943
+
944
+ # Use the bulk ingestion with model tracking
945
+ return_ids = self._bulk_ingest_embeddings(
946
+ client=client,
947
+ index_name=self.index_name,
948
+ embeddings=vectors,
949
+ texts=texts,
950
+ metadatas=metadatas,
951
+ vector_field=dynamic_field_name, # Use dynamic field name
952
+ text_field="text",
953
+ embedding_model=embedding_model, # Track the model
954
+ mapping=mapping,
955
+ is_aoss=is_aoss,
956
+ )
957
+ self.log(metadatas)
958
+
959
+ self.log(f"Successfully indexed {len(return_ids)} documents with model {embedding_model}.")
960
+
961
+ # ---------- helpers for filters ----------
962
+ def _is_placeholder_term(self, term_obj: dict) -> bool:
963
+ # term_obj like {"filename": "__IMPOSSIBLE_VALUE__"}
964
+ return any(v == "__IMPOSSIBLE_VALUE__" for v in term_obj.values())
965
+
966
+ def _coerce_filter_clauses(self, filter_obj: dict | None) -> list[dict]:
967
+ """Convert filter expressions into OpenSearch-compatible filter clauses.
968
+
969
+ This method accepts two filter formats and converts them to standardized
970
+ OpenSearch query clauses:
971
+
972
+ Format A - Explicit filters:
973
+ {"filter": [{"term": {"field": "value"}}, {"terms": {"field": ["val1", "val2"]}}],
974
+ "limit": 10, "score_threshold": 1.5}
975
+
976
+ Format B - Context-style mapping:
977
+ {"data_sources": ["file1.pdf"], "document_types": ["pdf"], "owners": ["user1"]}
978
+
979
+ Args:
980
+ filter_obj: Filter configuration dictionary or None
981
+
982
+ Returns:
983
+ List of OpenSearch filter clauses (term/terms objects)
984
+ Placeholder values with "__IMPOSSIBLE_VALUE__" are ignored
985
+ """
986
+ if not filter_obj:
987
+ return []
988
+
989
+ # If it is a string, try to parse it once
990
+ if isinstance(filter_obj, str):
991
+ try:
992
+ filter_obj = json.loads(filter_obj)
993
+ except json.JSONDecodeError:
994
+ # Not valid JSON - treat as no filters
995
+ return []
996
+
997
+ # Case A: already an explicit list/dict under "filter"
998
+ if "filter" in filter_obj:
999
+ raw = filter_obj["filter"]
1000
+ if isinstance(raw, dict):
1001
+ raw = [raw]
1002
+ explicit_clauses: list[dict] = []
1003
+ for f in raw or []:
1004
+ if "term" in f and isinstance(f["term"], dict) and not self._is_placeholder_term(f["term"]):
1005
+ explicit_clauses.append(f)
1006
+ elif "terms" in f and isinstance(f["terms"], dict):
1007
+ field, vals = next(iter(f["terms"].items()))
1008
+ if isinstance(vals, list) and len(vals) > 0:
1009
+ explicit_clauses.append(f)
1010
+ return explicit_clauses
1011
+
1012
+ # Case B: convert context-style maps into clauses
1013
+ field_mapping = {
1014
+ "data_sources": "filename",
1015
+ "document_types": "mimetype",
1016
+ "owners": "owner",
1017
+ }
1018
+ context_clauses: list[dict] = []
1019
+ for k, values in filter_obj.items():
1020
+ if not isinstance(values, list):
1021
+ continue
1022
+ field = field_mapping.get(k, k)
1023
+ if len(values) == 0:
1024
+ # Match-nothing placeholder (kept to mirror your tool semantics)
1025
+ context_clauses.append({"term": {field: "__IMPOSSIBLE_VALUE__"}})
1026
+ elif len(values) == 1:
1027
+ if values[0] != "__IMPOSSIBLE_VALUE__":
1028
+ context_clauses.append({"term": {field: values[0]}})
1029
+ else:
1030
+ context_clauses.append({"terms": {field: values}})
1031
+ return context_clauses
1032
+
1033
+ def _detect_available_models(self, client: OpenSearch, filter_clauses: list[dict] | None = None) -> list[str]:
1034
+ """Detect which embedding models have documents in the index.
1035
+
1036
+ Uses aggregation to find all unique embedding_model values, optionally
1037
+ filtered to only documents matching the user's filter criteria.
1038
+
1039
+ Args:
1040
+ client: OpenSearch client instance
1041
+ filter_clauses: Optional filter clauses to scope model detection
1042
+
1043
+ Returns:
1044
+ List of embedding model names found in the index
1045
+ """
1046
+ try:
1047
+ agg_query = {"size": 0, "aggs": {"embedding_models": {"terms": {"field": "embedding_model", "size": 10}}}}
1048
+
1049
+ # Apply filters to model detection if any exist
1050
+ if filter_clauses:
1051
+ agg_query["query"] = {"bool": {"filter": filter_clauses}}
1052
+
1053
+ result = client.search(
1054
+ index=self.index_name,
1055
+ body=agg_query,
1056
+ params={"terminate_after": 0},
1057
+ )
1058
+ buckets = result.get("aggregations", {}).get("embedding_models", {}).get("buckets", [])
1059
+ models = [b["key"] for b in buckets if b["key"]]
1060
+
1061
+ logger.info(
1062
+ f"Detected embedding models in corpus: {models}"
1063
+ + (f" (with {len(filter_clauses)} filters)" if filter_clauses else "")
1064
+ )
1065
+ except (OpenSearchException, KeyError, ValueError) as e:
1066
+ logger.warning(f"Failed to detect embedding models: {e}")
1067
+ # Fallback to current model
1068
+ return [self._get_embedding_model_name()]
1069
+ else:
1070
+ return models
1071
+
1072
+ def _get_index_properties(self, client: OpenSearch) -> dict[str, Any] | None:
1073
+ """Retrieve flattened mapping properties for the current index."""
1074
+ try:
1075
+ mapping = client.indices.get_mapping(index=self.index_name)
1076
+ except OpenSearchException as e:
1077
+ logger.warning(
1078
+ f"Failed to fetch mapping for index '{self.index_name}': {e}. Proceeding without mapping metadata."
1079
+ )
1080
+ return None
1081
+
1082
+ properties: dict[str, Any] = {}
1083
+ for index_data in mapping.values():
1084
+ props = index_data.get("mappings", {}).get("properties", {})
1085
+ if isinstance(props, dict):
1086
+ properties.update(props)
1087
+ return properties
1088
+
1089
+ def _is_knn_vector_field(self, properties: dict[str, Any] | None, field_name: str) -> bool:
1090
+ """Check whether the field is mapped as a knn_vector."""
1091
+ if not field_name:
1092
+ return False
1093
+ if properties is None:
1094
+ logger.warning(f"Mapping metadata unavailable; assuming field '{field_name}' is usable.")
1095
+ return True
1096
+ field_def = properties.get(field_name)
1097
+ if not isinstance(field_def, dict):
1098
+ return False
1099
+ if field_def.get("type") == "knn_vector":
1100
+ return True
1101
+
1102
+ nested_props = field_def.get("properties")
1103
+ return bool(isinstance(nested_props, dict) and nested_props.get("type") == "knn_vector")
1104
+
1105
+ def _get_field_dimension(self, properties: dict[str, Any] | None, field_name: str) -> int | None:
1106
+ """Get the dimension of a knn_vector field from the index mapping.
1107
+
1108
+ Args:
1109
+ properties: Index properties from mapping
1110
+ field_name: Name of the vector field
1111
+
1112
+ Returns:
1113
+ Dimension of the field, or None if not found
1114
+ """
1115
+ if not field_name or properties is None:
1116
+ return None
1117
+
1118
+ field_def = properties.get(field_name)
1119
+ if not isinstance(field_def, dict):
1120
+ return None
1121
+
1122
+ # Check direct knn_vector field
1123
+ if field_def.get("type") == "knn_vector":
1124
+ return field_def.get("dimension")
1125
+
1126
+ # Check nested properties
1127
+ nested_props = field_def.get("properties")
1128
+ if isinstance(nested_props, dict) and nested_props.get("type") == "knn_vector":
1129
+ return nested_props.get("dimension")
1130
+
1131
+ return None
1132
+
1133
+ # ---------- search (multi-model hybrid) ----------
1134
+ def search(self, query: str | None = None) -> list[dict[str, Any]]:
1135
+ """Perform multi-model hybrid search combining multiple vector similarities and keyword matching.
1136
+
1137
+ This method executes a sophisticated search that:
1138
+ 1. Auto-detects all embedding models present in the index
1139
+ 2. Generates query embeddings for ALL detected models in parallel
1140
+ 3. Combines multiple KNN queries using dis_max (picks best match)
1141
+ 4. Adds keyword search with fuzzy matching (30% weight)
1142
+ 5. Applies optional filtering and score thresholds
1143
+ 6. Returns aggregations for faceted search
1144
+
1145
+ Search weights:
1146
+ - Semantic search (dis_max across all models): 70%
1147
+ - Keyword search: 30%
1148
+
1149
+ Args:
1150
+ query: Search query string (used for both vector embedding and keyword search)
1151
+
1152
+ Returns:
1153
+ List of search results with page_content, metadata, and relevance scores
1154
+
1155
+ Raises:
1156
+ ValueError: If embedding component is not provided or filter JSON is invalid
1157
+ """
1158
+ logger.info(self.ingest_data)
1159
+ client = self.build_client()
1160
+ q = (query or "").strip()
1161
+
1162
+ # Parse optional filter expression
1163
+ filter_obj = None
1164
+ if getattr(self, "filter_expression", "") and self.filter_expression.strip():
1165
+ try:
1166
+ filter_obj = json.loads(self.filter_expression)
1167
+ except json.JSONDecodeError as e:
1168
+ msg = f"Invalid filter_expression JSON: {e}"
1169
+ raise ValueError(msg) from e
1170
+
1171
+ if not self.embedding:
1172
+ msg = "Embedding is required to run hybrid search (KNN + keyword)."
1173
+ raise ValueError(msg)
1174
+
1175
+ # Build filter clauses first so we can use them in model detection
1176
+ filter_clauses = self._coerce_filter_clauses(filter_obj)
1177
+
1178
+ # Detect available embedding models in the index (scoped by filters)
1179
+ available_models = self._detect_available_models(client, filter_clauses)
1180
+
1181
+ if not available_models:
1182
+ logger.warning("No embedding models found in index, using current model")
1183
+ available_models = [self._get_embedding_model_name()]
1184
+
1185
+ # Generate embeddings for ALL detected models
1186
+ query_embeddings = {}
1187
+
1188
+ # Normalize embedding to list
1189
+ embeddings_list = self.embedding if isinstance(self.embedding, list) else [self.embedding]
1190
+
1191
+ # Create a comprehensive map of model names to embedding objects
1192
+ # Check all possible identifiers (deployment, model, model_id, model_name)
1193
+ # Also leverage available_models list from EmbeddingsWithModels
1194
+ # Handle duplicate identifiers by creating combined keys
1195
+ embedding_by_model = {}
1196
+ identifier_conflicts = {} # Track which identifiers have conflicts
1197
+
1198
+ for idx, emb_obj in enumerate(embeddings_list):
1199
+ # Get all possible identifiers for this embedding
1200
+ identifiers = []
1201
+ deployment = getattr(emb_obj, "deployment", None)
1202
+ model = getattr(emb_obj, "model", None)
1203
+ model_id = getattr(emb_obj, "model_id", None)
1204
+ model_name = getattr(emb_obj, "model_name", None)
1205
+ dimensions = getattr(emb_obj, "dimensions", None)
1206
+ available_models = getattr(emb_obj, "available_models", None)
1207
+
1208
+ logger.info(
1209
+ f"Embedding object {idx}: deployment={deployment}, model={model}, "
1210
+ f"model_id={model_id}, model_name={model_name}, dimensions={dimensions}, "
1211
+ f"available_models={available_models}"
1212
+ )
1213
+
1214
+ # If this embedding has available_models dict, map all models to their dedicated instances
1215
+ if available_models and isinstance(available_models, dict):
1216
+ logger.info(f"Embedding object {idx} provides {len(available_models)} models via available_models dict")
1217
+ for model_name_key, dedicated_embedding in available_models.items():
1218
+ if model_name_key and str(model_name_key).strip():
1219
+ model_str = str(model_name_key).strip()
1220
+ if model_str not in embedding_by_model:
1221
+ # Use the dedicated embedding instance from the dict
1222
+ embedding_by_model[model_str] = dedicated_embedding
1223
+ logger.info(f"Mapped available model '{model_str}' to dedicated embedding instance")
1224
+ else:
1225
+ # Conflict detected - track it
1226
+ if model_str not in identifier_conflicts:
1227
+ identifier_conflicts[model_str] = [embedding_by_model[model_str]]
1228
+ identifier_conflicts[model_str].append(dedicated_embedding)
1229
+ logger.warning(f"Available model '{model_str}' has conflict - used by multiple embeddings")
1230
+
1231
+ # Also map traditional identifiers (for backward compatibility)
1232
+ if deployment:
1233
+ identifiers.append(str(deployment))
1234
+ if model:
1235
+ identifiers.append(str(model))
1236
+ if model_id:
1237
+ identifiers.append(str(model_id))
1238
+ if model_name:
1239
+ identifiers.append(str(model_name))
1240
+
1241
+ # Map all identifiers to this embedding object
1242
+ for identifier in identifiers:
1243
+ if identifier not in embedding_by_model:
1244
+ embedding_by_model[identifier] = emb_obj
1245
+ logger.info(f"Mapped identifier '{identifier}' to embedding object {idx}")
1246
+ else:
1247
+ # Conflict detected - track it
1248
+ if identifier not in identifier_conflicts:
1249
+ identifier_conflicts[identifier] = [embedding_by_model[identifier]]
1250
+ identifier_conflicts[identifier].append(emb_obj)
1251
+ logger.warning(f"Identifier '{identifier}' has conflict - used by multiple embeddings")
1252
+
1253
+ # For embeddings with model+deployment, create combined identifier
1254
+ # This helps when deployment is the same but model differs
1255
+ if deployment and model and deployment != model:
1256
+ combined_id = f"{deployment}:{model}"
1257
+ if combined_id not in embedding_by_model:
1258
+ embedding_by_model[combined_id] = emb_obj
1259
+ logger.info(f"Created combined identifier '{combined_id}' for embedding object {idx}")
1260
+
1261
+ # Log conflicts
1262
+ if identifier_conflicts:
1263
+ logger.warning(
1264
+ f"Found {len(identifier_conflicts)} conflicting identifiers. "
1265
+ f"Consider using combined format 'deployment:model' or specifying unique model names."
1266
+ )
1267
+ for conflict_id, emb_list in identifier_conflicts.items():
1268
+ logger.warning(f" Conflict on '{conflict_id}': {len(emb_list)} embeddings use this identifier")
1269
+
1270
+ logger.info(f"Generating embeddings for {len(available_models)} models in index")
1271
+ logger.info(f"Available embedding identifiers: {list(embedding_by_model.keys())}")
1272
+
1273
+ for model_name in available_models:
1274
+ try:
1275
+ # Check if we have an embedding object for this model
1276
+ if model_name in embedding_by_model:
1277
+ # Use the matching embedding object directly
1278
+ emb_obj = embedding_by_model[model_name]
1279
+ emb_deployment = getattr(emb_obj, "deployment", None)
1280
+ emb_model = getattr(emb_obj, "model", None)
1281
+ emb_model_id = getattr(emb_obj, "model_id", None)
1282
+ emb_dimensions = getattr(emb_obj, "dimensions", None)
1283
+ emb_available_models = getattr(emb_obj, "available_models", None)
1284
+
1285
+ logger.info(
1286
+ f"Using embedding object for model '{model_name}': "
1287
+ f"deployment={emb_deployment}, model={emb_model}, model_id={emb_model_id}, "
1288
+ f"dimensions={emb_dimensions}"
1289
+ )
1290
+
1291
+ # Check if this is a dedicated instance from available_models dict
1292
+ if emb_available_models and isinstance(emb_available_models, dict):
1293
+ logger.info(
1294
+ f"Model '{model_name}' using dedicated instance from available_models dict "
1295
+ f"(pre-configured with correct model and dimensions)"
1296
+ )
1297
+
1298
+ # Use the embedding instance directly - no model switching needed!
1299
+ vec = emb_obj.embed_query(q)
1300
+ query_embeddings[model_name] = vec
1301
+ logger.info(f"Generated embedding for model: {model_name} (actual dimensions: {len(vec)})")
1302
+ else:
1303
+ # No matching embedding found for this model
1304
+ logger.warning(
1305
+ f"No matching embedding found for model '{model_name}'. "
1306
+ f"This model will be skipped. Available models: {list(embedding_by_model.keys())}"
1307
+ )
1308
+ except (RuntimeError, ValueError, ConnectionError, TimeoutError, AttributeError, KeyError) as e:
1309
+ logger.warning(f"Failed to generate embedding for {model_name}: {e}")
1310
+
1311
+ if not query_embeddings:
1312
+ msg = "Failed to generate embeddings for any model"
1313
+ raise ValueError(msg)
1314
+
1315
+ index_properties = self._get_index_properties(client)
1316
+ legacy_vector_field = getattr(self, "vector_field", "chunk_embedding")
1317
+
1318
+ # Build KNN queries for each model
1319
+ embedding_fields: list[str] = []
1320
+ knn_queries_with_candidates = []
1321
+ knn_queries_without_candidates = []
1322
+
1323
+ raw_num_candidates = getattr(self, "num_candidates", 1000)
1324
+ try:
1325
+ num_candidates = int(raw_num_candidates) if raw_num_candidates is not None else 0
1326
+ except (TypeError, ValueError):
1327
+ num_candidates = 0
1328
+ use_num_candidates = num_candidates > 0
1329
+
1330
+ for model_name, embedding_vector in query_embeddings.items():
1331
+ field_name = get_embedding_field_name(model_name)
1332
+ selected_field = field_name
1333
+ vector_dim = len(embedding_vector)
1334
+
1335
+ # Only use the expected dynamic field - no legacy fallback
1336
+ # This prevents dimension mismatches between models
1337
+ if not self._is_knn_vector_field(index_properties, selected_field):
1338
+ logger.warning(
1339
+ f"Skipping model {model_name}: field '{field_name}' is not mapped as knn_vector. "
1340
+ f"Documents must be indexed with this embedding model before querying."
1341
+ )
1342
+ continue
1343
+
1344
+ # Validate vector dimensions match the field dimensions
1345
+ field_dim = self._get_field_dimension(index_properties, selected_field)
1346
+ if field_dim is not None and field_dim != vector_dim:
1347
+ logger.error(
1348
+ f"Dimension mismatch for model '{model_name}': "
1349
+ f"Query vector has {vector_dim} dimensions but field '{selected_field}' expects {field_dim}. "
1350
+ f"Skipping this model to prevent search errors."
1351
+ )
1352
+ continue
1353
+
1354
+ logger.info(
1355
+ f"Adding KNN query for model '{model_name}': field='{selected_field}', "
1356
+ f"query_dims={vector_dim}, field_dims={field_dim or 'unknown'}"
1357
+ )
1358
+ embedding_fields.append(selected_field)
1359
+
1360
+ base_query = {
1361
+ "knn": {
1362
+ selected_field: {
1363
+ "vector": embedding_vector,
1364
+ "k": 50,
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ if use_num_candidates:
1370
+ query_with_candidates = copy.deepcopy(base_query)
1371
+ query_with_candidates["knn"][selected_field]["num_candidates"] = num_candidates
1372
+ else:
1373
+ query_with_candidates = base_query
1374
+
1375
+ knn_queries_with_candidates.append(query_with_candidates)
1376
+ knn_queries_without_candidates.append(base_query)
1377
+
1378
+ if not knn_queries_with_candidates:
1379
+ # No valid fields found - this can happen when:
1380
+ # 1. Index is empty (no documents yet)
1381
+ # 2. Embedding model has changed and field doesn't exist yet
1382
+ # Return empty results instead of failing
1383
+ logger.warning(
1384
+ "No valid knn_vector fields found for embedding models. "
1385
+ "This may indicate an empty index or missing field mappings. "
1386
+ "Returning empty search results."
1387
+ )
1388
+ return []
1389
+
1390
+ # Build exists filter - document must have at least one embedding field
1391
+ exists_any_embedding = {
1392
+ "bool": {"should": [{"exists": {"field": f}} for f in set(embedding_fields)], "minimum_should_match": 1}
1393
+ }
1394
+
1395
+ # Combine user filters with exists filter
1396
+ all_filters = [*filter_clauses, exists_any_embedding]
1397
+
1398
+ # Get limit and score threshold
1399
+ limit = (filter_obj or {}).get("limit", self.number_of_results)
1400
+ score_threshold = (filter_obj or {}).get("score_threshold", 0)
1401
+
1402
+ # Build multi-model hybrid query
1403
+ body = {
1404
+ "query": {
1405
+ "bool": {
1406
+ "should": [
1407
+ {
1408
+ "dis_max": {
1409
+ "tie_breaker": 0.0, # Take only the best match, no blending
1410
+ "boost": 0.7, # 70% weight for semantic search
1411
+ "queries": knn_queries_with_candidates,
1412
+ }
1413
+ },
1414
+ {
1415
+ "multi_match": {
1416
+ "query": q,
1417
+ "fields": ["text^2", "filename^1.5"],
1418
+ "type": "best_fields",
1419
+ "fuzziness": "AUTO",
1420
+ "boost": 0.3, # 30% weight for keyword search
1421
+ }
1422
+ },
1423
+ ],
1424
+ "minimum_should_match": 1,
1425
+ "filter": all_filters,
1426
+ }
1427
+ },
1428
+ "aggs": {
1429
+ "data_sources": {"terms": {"field": "filename", "size": 20}},
1430
+ "document_types": {"terms": {"field": "mimetype", "size": 10}},
1431
+ "owners": {"terms": {"field": "owner", "size": 10}},
1432
+ "embedding_models": {"terms": {"field": "embedding_model", "size": 10}},
1433
+ },
1434
+ "_source": [
1435
+ "filename",
1436
+ "mimetype",
1437
+ "page",
1438
+ "text",
1439
+ "source_url",
1440
+ "owner",
1441
+ "embedding_model",
1442
+ "allowed_users",
1443
+ "allowed_groups",
1444
+ ],
1445
+ "size": limit,
1446
+ }
1447
+
1448
+ if isinstance(score_threshold, (int, float)) and score_threshold > 0:
1449
+ body["min_score"] = score_threshold
1450
+
1451
+ logger.info(f"Executing multi-model hybrid search with {len(knn_queries_with_candidates)} embedding models")
1452
+
1453
+ try:
1454
+ resp = client.search(index=self.index_name, body=body, params={"terminate_after": 0})
1455
+ except RequestError as e:
1456
+ error_message = str(e)
1457
+ lowered = error_message.lower()
1458
+ if use_num_candidates and "num_candidates" in lowered:
1459
+ logger.warning(
1460
+ "Retrying search without num_candidates parameter due to cluster capabilities",
1461
+ error=error_message,
1462
+ )
1463
+ fallback_body = copy.deepcopy(body)
1464
+ try:
1465
+ fallback_body["query"]["bool"]["should"][0]["dis_max"]["queries"] = knn_queries_without_candidates
1466
+ except (KeyError, IndexError, TypeError) as inner_err:
1467
+ raise e from inner_err
1468
+ resp = client.search(
1469
+ index=self.index_name,
1470
+ body=fallback_body,
1471
+ params={"terminate_after": 0},
1472
+ )
1473
+ elif "knn_vector" in lowered or ("field" in lowered and "knn" in lowered):
1474
+ fallback_vector = next(iter(query_embeddings.values()), None)
1475
+ if fallback_vector is None:
1476
+ raise
1477
+ fallback_field = legacy_vector_field or "chunk_embedding"
1478
+ logger.warning(
1479
+ "KNN search failed for dynamic fields; falling back to legacy field '%s'.",
1480
+ fallback_field,
1481
+ )
1482
+ fallback_body = copy.deepcopy(body)
1483
+ fallback_body["query"]["bool"]["filter"] = filter_clauses
1484
+ knn_fallback = {
1485
+ "knn": {
1486
+ fallback_field: {
1487
+ "vector": fallback_vector,
1488
+ "k": 50,
1489
+ }
1490
+ }
1491
+ }
1492
+ if use_num_candidates:
1493
+ knn_fallback["knn"][fallback_field]["num_candidates"] = num_candidates
1494
+ fallback_body["query"]["bool"]["should"][0]["dis_max"]["queries"] = [knn_fallback]
1495
+ resp = client.search(
1496
+ index=self.index_name,
1497
+ body=fallback_body,
1498
+ params={"terminate_after": 0},
1499
+ )
1500
+ else:
1501
+ raise
1502
+ hits = resp.get("hits", {}).get("hits", [])
1503
+
1504
+ logger.info(f"Found {len(hits)} results")
1505
+
1506
+ return [
1507
+ {
1508
+ "page_content": hit["_source"].get("text", ""),
1509
+ "metadata": {k: v for k, v in hit["_source"].items() if k != "text"},
1510
+ "score": hit.get("_score"),
1511
+ }
1512
+ for hit in hits
1513
+ ]
1514
+
1515
+ def search_documents(self) -> list[Data]:
1516
+ """Search documents and return results as Data objects.
1517
+
1518
+ This is the main interface method that performs the multi-model search using the
1519
+ configured search_query and returns results in Langflow's Data format.
1520
+
1521
+ Returns:
1522
+ List of Data objects containing search results with text and metadata
1523
+
1524
+ Raises:
1525
+ Exception: If search operation fails
1526
+ """
1527
+ try:
1528
+ raw = self.search(self.search_query or "")
1529
+ return [Data(text=hit["page_content"], **hit["metadata"]) for hit in raw]
1530
+ self.log(self.ingest_data)
1531
+ except Exception as e:
1532
+ self.log(f"search_documents error: {e}")
1533
+ raise
1534
+
1535
+ # -------- dynamic UI handling (auth switch) --------
1536
+ async def update_build_config(self, build_config: dict, field_value: str, field_name: str | None = None) -> dict:
1537
+ """Dynamically update component configuration based on field changes.
1538
+
1539
+ This method handles real-time UI updates, particularly for authentication
1540
+ mode changes that show/hide relevant input fields.
1541
+
1542
+ Args:
1543
+ build_config: Current component configuration
1544
+ field_value: New value for the changed field
1545
+ field_name: Name of the field that changed
1546
+
1547
+ Returns:
1548
+ Updated build configuration with appropriate field visibility
1549
+ """
1550
+ try:
1551
+ if field_name == "auth_mode":
1552
+ mode = (field_value or "basic").strip().lower()
1553
+ is_basic = mode == "basic"
1554
+ is_jwt = mode == "jwt"
1555
+
1556
+ build_config["username"]["show"] = is_basic
1557
+ build_config["password"]["show"] = is_basic
1558
+
1559
+ build_config["jwt_token"]["show"] = is_jwt
1560
+ build_config["jwt_header"]["show"] = is_jwt
1561
+ build_config["bearer_prefix"]["show"] = is_jwt
1562
+
1563
+ build_config["username"]["required"] = is_basic
1564
+ build_config["password"]["required"] = is_basic
1565
+
1566
+ build_config["jwt_token"]["required"] = is_jwt
1567
+ build_config["jwt_header"]["required"] = is_jwt
1568
+ build_config["bearer_prefix"]["required"] = False
1569
+
1570
+ return build_config
1571
+
1572
+ except (KeyError, ValueError) as e:
1573
+ self.log(f"update_build_config error: {e}")
1574
+
1575
+ return build_config