Spaces:
Sleeping
Sleeping
improved FAQ retrival
Browse files
plugins/chatMemoryPlugin.py
CHANGED
|
@@ -31,12 +31,18 @@ class ChatMemoryPlugin:
|
|
| 31 |
self.logger.error(f"Failed to log SQL query: {str(e)}")
|
| 32 |
|
| 33 |
|
| 34 |
-
|
|
|
|
| 35 |
"""Retrieve FAQs using vector embeddings for semantic similarity"""
|
| 36 |
try:
|
| 37 |
-
faqs_dict = await self.chat_memory_handler.get_semantic_faqs(limit=limit, threshold=threshold)
|
| 38 |
faqs = [faq["representative_question"] for faq in faqs_dict]
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
self.logger.error(f"Semantic FAQ retrieval failed: {str(e)}")
|
| 42 |
return []
|
|
|
|
| 31 |
self.logger.error(f"Failed to log SQL query: {str(e)}")
|
| 32 |
|
| 33 |
|
| 34 |
+
@kernel_function(name="get_semantic_faqs")
|
| 35 |
+
async def get_semantic_faqs(self, limit:int=6, threshold: float = 0.1) -> List[str]:
|
| 36 |
"""Retrieve FAQs using vector embeddings for semantic similarity"""
|
| 37 |
try:
|
| 38 |
+
faqs_dict = await self.chat_memory_handler.get_semantic_faqs(limit=limit+5, threshold=threshold)
|
| 39 |
faqs = [faq["representative_question"] for faq in faqs_dict]
|
| 40 |
+
|
| 41 |
+
# Remove duplicates while preserving order
|
| 42 |
+
unique_faqs = list(dict.fromkeys(faqs))
|
| 43 |
+
|
| 44 |
+
self.logger.info(unique_faqs)
|
| 45 |
+
return unique_faqs[:limit]
|
| 46 |
except Exception as e:
|
| 47 |
self.logger.error(f"Semantic FAQ retrieval failed: {str(e)}")
|
| 48 |
return []
|