Fix unified tools to use near_vector instead of near_text
The Weaviate collections have vectorizer: "none", so near_text searches fail silently. Changed all search handlers to: - Import get_embedder from embedding_service - Generate query vectors manually - Use near_vector for semantic search Affected handlers: - search_memories_handler - trace_concept_evolution_handler - check_consistency_handler Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,9 @@ import os
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
# Import embedder for vector search (since Weaviate vectorizer is "none")
|
||||||
|
from memory.core.embedding_service import get_embedder
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Input Models
|
# Input Models
|
||||||
@@ -110,11 +113,18 @@ async def search_memories_handler(input_data: SearchMemoriesInput) -> Dict[str,
|
|||||||
Search across both Thoughts and Conversations.
|
Search across both Thoughts and Conversations.
|
||||||
|
|
||||||
Returns unified results sorted by relevance or date.
|
Returns unified results sorted by relevance or date.
|
||||||
|
Uses near_vector with embedder since Weaviate vectorizer is "none".
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = get_weaviate_client()
|
client = get_weaviate_client()
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
|
# Get embedder for vector search
|
||||||
|
embedder = get_embedder()
|
||||||
|
query_vector = None
|
||||||
|
if input_data.query:
|
||||||
|
query_vector = embedder.embed_batch([input_data.query])[0].tolist()
|
||||||
|
|
||||||
# Parse date filters
|
# Parse date filters
|
||||||
since_dt = parse_relative_date(input_data.since) if input_data.since else None
|
since_dt = parse_relative_date(input_data.since) if input_data.since else None
|
||||||
before_dt = parse_relative_date(input_data.before) if input_data.before else None
|
before_dt = parse_relative_date(input_data.before) if input_data.before else None
|
||||||
@@ -124,9 +134,9 @@ async def search_memories_handler(input_data: SearchMemoriesInput) -> Dict[str,
|
|||||||
try:
|
try:
|
||||||
thought_collection = client.collections.get("Thought")
|
thought_collection = client.collections.get("Thought")
|
||||||
|
|
||||||
if input_data.query:
|
if query_vector:
|
||||||
thought_results = thought_collection.query.near_text(
|
thought_results = thought_collection.query.near_vector(
|
||||||
query=input_data.query,
|
near_vector=query_vector,
|
||||||
limit=input_data.n_results,
|
limit=input_data.n_results,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
@@ -174,9 +184,9 @@ async def search_memories_handler(input_data: SearchMemoriesInput) -> Dict[str,
|
|||||||
try:
|
try:
|
||||||
conv_collection = client.collections.get("Conversation")
|
conv_collection = client.collections.get("Conversation")
|
||||||
|
|
||||||
if input_data.query:
|
if query_vector:
|
||||||
conv_results = conv_collection.query.near_text(
|
conv_results = conv_collection.query.near_vector(
|
||||||
query=input_data.query,
|
near_vector=query_vector,
|
||||||
limit=input_data.n_results,
|
limit=input_data.n_results,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
@@ -256,16 +266,21 @@ async def trace_concept_evolution_handler(input_data: TraceConceptEvolutionInput
|
|||||||
Trace the evolution of a concept through thoughts and conversations over time.
|
Trace the evolution of a concept through thoughts and conversations over time.
|
||||||
|
|
||||||
Returns a timeline showing how the concept appeared and evolved.
|
Returns a timeline showing how the concept appeared and evolved.
|
||||||
|
Uses near_vector with embedder since Weaviate vectorizer is "none".
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = get_weaviate_client()
|
client = get_weaviate_client()
|
||||||
timeline = []
|
timeline = []
|
||||||
|
|
||||||
|
# Get embedder for vector search
|
||||||
|
embedder = get_embedder()
|
||||||
|
concept_vector = embedder.embed_batch([input_data.concept])[0].tolist()
|
||||||
|
|
||||||
# Search Thoughts for the concept
|
# Search Thoughts for the concept
|
||||||
try:
|
try:
|
||||||
thought_collection = client.collections.get("Thought")
|
thought_collection = client.collections.get("Thought")
|
||||||
thought_results = thought_collection.query.near_text(
|
thought_results = thought_collection.query.near_vector(
|
||||||
query=input_data.concept,
|
near_vector=concept_vector,
|
||||||
limit=input_data.limit,
|
limit=input_data.limit,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
@@ -291,8 +306,8 @@ async def trace_concept_evolution_handler(input_data: TraceConceptEvolutionInput
|
|||||||
# Search Conversations for the concept
|
# Search Conversations for the concept
|
||||||
try:
|
try:
|
||||||
conv_collection = client.collections.get("Conversation")
|
conv_collection = client.collections.get("Conversation")
|
||||||
conv_results = conv_collection.query.near_text(
|
conv_results = conv_collection.query.near_vector(
|
||||||
query=input_data.concept,
|
near_vector=concept_vector,
|
||||||
limit=input_data.limit,
|
limit=input_data.limit,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
@@ -343,16 +358,21 @@ async def check_consistency_handler(input_data: CheckConsistencyInput) -> Dict[s
|
|||||||
Check if a statement is consistent with existing thoughts and conversations.
|
Check if a statement is consistent with existing thoughts and conversations.
|
||||||
|
|
||||||
Searches for similar content and identifies potential contradictions.
|
Searches for similar content and identifies potential contradictions.
|
||||||
|
Uses near_vector with embedder since Weaviate vectorizer is "none".
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
client = get_weaviate_client()
|
client = get_weaviate_client()
|
||||||
related_content = []
|
related_content = []
|
||||||
|
|
||||||
|
# Get embedder for vector search
|
||||||
|
embedder = get_embedder()
|
||||||
|
statement_vector = embedder.embed_batch([input_data.statement])[0].tolist()
|
||||||
|
|
||||||
# Search for similar thoughts
|
# Search for similar thoughts
|
||||||
try:
|
try:
|
||||||
thought_collection = client.collections.get("Thought")
|
thought_collection = client.collections.get("Thought")
|
||||||
thought_results = thought_collection.query.near_text(
|
thought_results = thought_collection.query.near_vector(
|
||||||
query=input_data.statement,
|
near_vector=statement_vector,
|
||||||
limit=10,
|
limit=10,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
@@ -375,8 +395,8 @@ async def check_consistency_handler(input_data: CheckConsistencyInput) -> Dict[s
|
|||||||
# Search for similar conversations
|
# Search for similar conversations
|
||||||
try:
|
try:
|
||||||
conv_collection = client.collections.get("Conversation")
|
conv_collection = client.collections.get("Conversation")
|
||||||
conv_results = conv_collection.query.near_text(
|
conv_results = conv_collection.query.near_vector(
|
||||||
query=input_data.statement,
|
near_vector=statement_vector,
|
||||||
limit=10,
|
limit=10,
|
||||||
return_metadata=MetadataQuery(distance=True),
|
return_metadata=MetadataQuery(distance=True),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user