mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 04:13:56 +08:00
query只传递相关的文本
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ..base import MemoryProviderBase, logger
|
from ..base import MemoryProviderBase, logger
|
||||||
@@ -56,7 +57,16 @@ class MemoryProvider(MemoryProviderBase):
|
|||||||
|
|
||||||
filters = {"user_id": self.role_id}
|
filters = {"user_id": self.role_id}
|
||||||
|
|
||||||
results = self.client.search(query, filters=filters)
|
search_query = query
|
||||||
|
try:
|
||||||
|
if query.strip().startswith("{") and query.strip().endswith("}"):
|
||||||
|
data = json.loads(query)
|
||||||
|
if "content" in data:
|
||||||
|
search_query = data["content"]
|
||||||
|
except (json.JSONDecodeError, KeyError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
results = self.client.search(search_query, filters=filters)
|
||||||
if not results or "results" not in results:
|
if not results or "results" not in results:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Optional, Dict, Any
|
from typing import Optional, Dict, Any
|
||||||
|
|
||||||
@@ -207,7 +208,7 @@ class MemoryProvider(MemoryProviderBase):
|
|||||||
Query memories from PowerMem based on similarity search.
|
Query memories from PowerMem based on similarity search.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
query: The search query string
|
query: The search query string (may be JSON format with metadata)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Formatted string of relevant memories or empty string if none found
|
Formatted string of relevant memories or empty string if none found
|
||||||
@@ -221,6 +222,17 @@ class MemoryProvider(MemoryProviderBase):
|
|||||||
logger.bind(tag=TAG).debug("No role_id set, returning empty memory")
|
logger.bind(tag=TAG).debug("No role_id set, returning empty memory")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
# Extract content from JSON format if present (for ASR with emotion/language tags)
|
||||||
|
search_query = query
|
||||||
|
try:
|
||||||
|
if query.strip().startswith("{") and query.strip().endswith("}"):
|
||||||
|
data = json.loads(query)
|
||||||
|
if "content" in data:
|
||||||
|
search_query = data["content"]
|
||||||
|
except (json.JSONDecodeError, KeyError):
|
||||||
|
# If parsing fails, use original query
|
||||||
|
pass
|
||||||
|
|
||||||
result_parts = []
|
result_parts = []
|
||||||
|
|
||||||
# If user profile mode is enabled, include user profile in results
|
# If user profile mode is enabled, include user profile in results
|
||||||
@@ -234,14 +246,14 @@ class MemoryProvider(MemoryProviderBase):
|
|||||||
# UserMemory uses sync search
|
# UserMemory uses sync search
|
||||||
results = await asyncio.to_thread(
|
results = await asyncio.to_thread(
|
||||||
self.memory_client.search,
|
self.memory_client.search,
|
||||||
query=query,
|
query=search_query,
|
||||||
user_id=self.role_id,
|
user_id=self.role_id,
|
||||||
limit=30
|
limit=30
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# AsyncMemory uses async search
|
# AsyncMemory uses async search
|
||||||
results = await self.memory_client.search(
|
results = await self.memory_client.search(
|
||||||
query=query,
|
query=search_query,
|
||||||
user_id=self.role_id,
|
user_id=self.role_id,
|
||||||
limit=30
|
limit=30
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user