@@ -204,9 +204,21 @@ def get_embedding_model(tenant_id: str):
204204
205205 if model_type == "embedding" :
206206 # Get the es core
207- return OpenAICompatibleEmbedding (api_key = model_config .get ("api_key" , "" ), base_url = model_config .get ("base_url" , "" ), model_name = get_model_name_from_config (model_config ) or "" , embedding_dim = model_config .get ("max_tokens" , 1024 ))
207+ return OpenAICompatibleEmbedding (
208+ api_key = model_config .get ("api_key" , "" ),
209+ base_url = model_config .get ("base_url" , "" ),
210+ model_name = get_model_name_from_config (model_config ) or "" ,
211+ embedding_dim = model_config .get ("max_tokens" , 1024 ),
212+ ssl_verify = model_config .get ("ssl_verify" , True ),
213+ )
208214 elif model_type == "multi_embedding" :
209- return JinaEmbedding (api_key = model_config .get ("api_key" , "" ), base_url = model_config .get ("base_url" , "" ), model_name = get_model_name_from_config (model_config ) or "" , embedding_dim = model_config .get ("max_tokens" , 1024 ))
215+ return JinaEmbedding (
216+ api_key = model_config .get ("api_key" , "" ),
217+ base_url = model_config .get ("base_url" , "" ),
218+ model_name = get_model_name_from_config (model_config ) or "" ,
219+ embedding_dim = model_config .get ("max_tokens" , 1024 ),
220+ ssl_verify = model_config .get ("ssl_verify" , True ),
221+ )
210222 else :
211223 return None
212224
@@ -997,7 +1009,7 @@ async def summary_index_name(self,
9971009 ):
9981010 """
9991011 Generate a summary for the specified index using advanced Map-Reduce approach
1000-
1012+
10011013 New implementation:
10021014 1. Get documents and cluster them by semantic similarity
10031015 2. Map: Summarize each document individually
@@ -1019,17 +1031,17 @@ async def summary_index_name(self,
10191031 try :
10201032 if not tenant_id :
10211033 raise Exception ("Tenant ID is required for summary generation." )
1022-
1034+
10231035 from utils .document_vector_utils import (
10241036 process_documents_for_clustering ,
10251037 kmeans_cluster_documents ,
10261038 summarize_clusters_map_reduce ,
10271039 merge_cluster_summaries
10281040 )
1029-
1041+
10301042 # Use new Map-Reduce approach
10311043 sample_count = min (batch_size // 5 , 200 ) # Sample reasonable number of documents
1032-
1044+
10331045 # Define a helper function to run all blocking operations in a thread pool
10341046 def _generate_summary_sync ():
10351047 """Synchronous function that performs all blocking operations"""
@@ -1039,13 +1051,13 @@ def _generate_summary_sync():
10391051 vdb_core = vdb_core ,
10401052 sample_doc_count = sample_count
10411053 )
1042-
1054+
10431055 if not document_samples :
10441056 raise Exception ("No documents found in index." )
1045-
1057+
10461058 # Step 2: Cluster documents (CPU-intensive operation)
10471059 clusters = kmeans_cluster_documents (doc_embeddings , k = None )
1048-
1060+
10491061 # Step 3: Map-Reduce summarization (contains blocking LLM calls)
10501062 cluster_summaries = summarize_clusters_map_reduce (
10511063 document_samples = document_samples ,
@@ -1056,11 +1068,11 @@ def _generate_summary_sync():
10561068 model_id = model_id ,
10571069 tenant_id = tenant_id
10581070 )
1059-
1071+
10601072 # Step 4: Merge into final summary
10611073 final_summary = merge_cluster_summaries (cluster_summaries )
10621074 return final_summary
1063-
1075+
10641076 # Run blocking operations in a thread pool to avoid blocking the event loop
10651077 # Use get_running_loop() for better compatibility with modern asyncio
10661078 try :
@@ -1069,7 +1081,7 @@ def _generate_summary_sync():
10691081 # Fallback for edge cases
10701082 loop = asyncio .get_event_loop ()
10711083 final_summary = await loop .run_in_executor (None , _generate_summary_sync )
1072-
1084+
10731085 # Stream the result
10741086 async def generate_summary ():
10751087 try :
@@ -1080,12 +1092,12 @@ async def generate_summary():
10801092 yield "data: {\" status\" : \" completed\" }\n \n "
10811093 except Exception as e :
10821094 yield f"data: {{\" status\" : \" error\" , \" message\" : \" { e } \" }}\n \n "
1083-
1095+
10841096 return StreamingResponse (
10851097 generate_summary (),
10861098 media_type = "text/event-stream"
10871099 )
1088-
1100+
10891101 except Exception as e :
10901102 logger .error (f"Knowledge base summary generation failed: { str (e )} " , exc_info = True )
10911103 raise Exception (f"Failed to generate summary: { str (e )} " )
0 commit comments