@@ -184,24 +184,53 @@ async def code_endpoint(request: Request):
184184 # If RAG requested, perform semantic search and build context
185185 if use_rag :
186186 try :
187- retrieved = search_semantic (prompt , database_path , top_k = top_k )
188- # Build context WITHOUT including snippets: only include file references and scores
187+ # Retrieve with content included
188+ retrieved = search_semantic (prompt , database_path , top_k = top_k , include_content = True )
189+ # Build context WITH actual file content for better RAG results
189190 context_parts = []
190191 total_len = len (combined_context )
191192 for r in retrieved :
192- part = f"File: { r .get ('path' )} (score: { r .get ('score' , 0 ):.4f} )\n "
193+ content = r .get ("content" , "" )
194+ path = r .get ("path" , "" )
195+ score = r .get ("score" , 0 )
196+
197+ # Include file path, score, and actual content
198+ part = f"File: { path } (score: { score :.4f} )\n { content } \n "
199+
193200 if total_len + len (part ) > TOTAL_CONTEXT_LIMIT :
201+ # If full content doesn't fit, try to include at least partial content
202+ remaining = TOTAL_CONTEXT_LIMIT - total_len
203+ if remaining > 200 : # Only include if we have meaningful space
204+ truncated_content = content [:remaining - 100 ] + "..."
205+ part = f"File: { path } (score: { score :.4f} )\n { truncated_content } \n "
206+ context_parts .append (part )
207+ used_context .append ({
208+ "path" : path ,
209+ "score" : score ,
210+ "content" : truncated_content ,
211+ "file_id" : r .get ("file_id" ),
212+ "chunk_index" : r .get ("chunk_index" )
213+ })
194214 break
215+
195216 context_parts .append (part )
196217 total_len += len (part )
197- used_context .append ({"path" : r .get ("path" ), "score" : r .get ("score" )})
218+ used_context .append ({
219+ "path" : path ,
220+ "score" : score ,
221+ "content" : content ,
222+ "file_id" : r .get ("file_id" ),
223+ "chunk_index" : r .get ("chunk_index" )
224+ })
225+
198226 if context_parts :
199- retrieved_text = "\n " .join (context_parts )
227+ retrieved_text = "\n --- \n " .join (context_parts )
200228 if combined_context :
201- combined_context = combined_context + "\n \n Retrieved:\n " + retrieved_text
229+ combined_context = combined_context + "\n \n Retrieved Context :\n " + retrieved_text
202230 else :
203- combined_context = "Retrieved:\n " + retrieved_text
204- except Exception :
231+ combined_context = "Retrieved Context:\n " + retrieved_text
232+ except Exception as e :
233+ logger .exception (f"RAG search failed: { e } " )
205234 used_context = []
206235
207236 # Call the coding model with prompt and combined_context
0 commit comments