Finds relevant documentation based on the provided queries. Args: queries (List[Dict]): List of query dictionaries with 'type' and 'query' keys k (int, optional): Number of results to return per query. Defaults to 5 trace_id (str, optional): Trace identif
(self, queries: List[Dict], k: int = 5, trace_id: str = None, topic: str = None, scene_number: int = None)
| 245 | vector_store.persist() |
| 246 | |
| 247 | def find_relevant_docs(self, queries: List[Dict], k: int = 5, trace_id: str = None, topic: str = None, scene_number: int = None) -> List[str]: |
| 248 | """Finds relevant documentation based on the provided queries. |
| 249 | |
| 250 | Args: |
| 251 | queries (List[Dict]): List of query dictionaries with 'type' and 'query' keys |
| 252 | k (int, optional): Number of results to return per query. Defaults to 5 |
| 253 | trace_id (str, optional): Trace identifier for logging. Defaults to None |
| 254 | topic (str, optional): Topic name for logging. Defaults to None |
| 255 | scene_number (int, optional): Scene number for logging. Defaults to None |
| 256 | |
| 257 | Returns: |
| 258 | List[str]: Formatted string containing relevant documentation snippets |
| 259 | """ |
| 260 | manim_core_formatted_results = [] |
| 261 | manim_plugin_formatted_results = [] |
| 262 | |
| 263 | # Create a Langfuse span if enabled |
| 264 | if self.use_langfuse: |
| 265 | langfuse = Langfuse() |
| 266 | span = langfuse.span( |
| 267 | trace_id=trace_id, # Use the passed trace_id |
| 268 | name=f"RAG search for {topic} - scene {scene_number}", |
| 269 | metadata={ |
| 270 | "topic": topic, |
| 271 | "scene_number": scene_number, |
| 272 | "session_id": self.session_id |
| 273 | } |
| 274 | ) |
| 275 | |
| 276 | # Separate queries by type |
| 277 | manim_core_queries = [query for query in queries if query["type"] == "manim-core"] |
| 278 | manim_plugin_queries = [query for query in queries if query["type"] != "manim-core" and query["type"] in self.plugin_stores] |
| 279 | |
| 280 | if len([q for q in queries if q["type"] != "manim-core"]) != len(manim_plugin_queries): |
| 281 | print("Warning: Some plugin queries were skipped because their types weren't found in available plugin stores") |
| 282 | |
| 283 | # Search in core manim docs |
| 284 | for query in manim_core_queries: |
| 285 | query_text = query["query"] |
| 286 | self.core_vector_store._embedding_function.parent_observation_id = span.id |
| 287 | manim_core_results = self.core_vector_store.similarity_search_with_relevance_scores( |
| 288 | query=query_text, |
| 289 | k=k, |
| 290 | score_threshold=0.5 |
| 291 | ) |
| 292 | for result in manim_core_results: |
| 293 | manim_core_formatted_results.append({ |
| 294 | "query": query_text, |
| 295 | "source": result[0].metadata['source'], |
| 296 | "content": result[0].page_content, |
| 297 | "score": result[1] |
| 298 | }) |
| 299 | |
| 300 | # Search in relevant plugin docs |
| 301 | for query in manim_plugin_queries: |
| 302 | plugin_name = query["type"] |
| 303 | query_text = query["query"] |
| 304 | self.plugin_stores[plugin_name]._embedding_function.parent_observation_id = span.id |
no outgoing calls
no test coverage detected