File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -94,6 +94,13 @@ def cluster_tips(
9494 threshold = self .config .clustering_threshold
9595
9696 entities = self .get_all_entities (namespace_id , filters = {"type" : "guideline" }, limit = limit )
97+ if len (entities ) >= limit :
98+ logger .warning (
99+ "Fetched %d entities (hit limit=%d); clustering results may be incomplete. "
100+ "Consider increasing the limit." ,
101+ len (entities ),
102+ limit ,
103+ )
97104 return cluster_entities (entities , threshold = threshold )
98105
99106 def consolidate_tips (
@@ -134,8 +141,13 @@ def consolidate_tips(
134141 )
135142 for tip in consolidated_tips
136143 ]
137- if new_entities :
138- self .update_entities (namespace_id , new_entities , enable_conflict_resolution = False )
144+ if not new_entities :
145+ logger .warning (
146+ "LLM returned no consolidated tips for cluster (IDs: %s); skipping deletion." ,
147+ [e .id for e in cluster ],
148+ )
149+ continue
150+ self .update_entities (namespace_id , new_entities , enable_conflict_resolution = False )
139151 except Exception :
140152 logger .warning (
141153 "Failed to consolidate cluster of %d entities (IDs: %s); skipping." ,
Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ def combine_cluster(entities: list[RecordedEntity]) -> list[Tip]:
183183 for attempt in range (3 ):
184184 try :
185185 if constrained_decoding_supported :
186- clean_response = (
186+ content = (
187187 completion (
188188 model = llm_settings .tips_model ,
189189 messages = [{"role" : "user" , "content" : prompt }],
@@ -193,8 +193,11 @@ def combine_cluster(entities: list[RecordedEntity]) -> list[Tip]:
193193 .choices [0 ]
194194 .message .content
195195 )
196+ if content is None :
197+ raise KaizenException ("LLM returned None content for combine_cluster" )
198+ clean_response = content
196199 else :
197- response = (
200+ content = (
198201 completion (
199202 model = llm_settings .tips_model ,
200203 messages = [{"role" : "user" , "content" : prompt }],
@@ -203,7 +206,9 @@ def combine_cluster(entities: list[RecordedEntity]) -> list[Tip]:
203206 .choices [0 ]
204207 .message .content
205208 )
206- clean_response = clean_llm_response (response )
209+ if content is None :
210+ raise KaizenException ("LLM returned None content for combine_cluster" )
211+ clean_response = clean_llm_response (content )
207212
208213 return TipGenerationResponse .model_validate (json .loads (clean_response )).tips
209214 except Exception as e :
You can’t perform that action at this time.
0 commit comments