Initial commit
This commit is contained in:
28
server/brain/search.py
Normal file
28
server/brain/search.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
brain/search.py — Semantic search over the thought database.
|
||||
|
||||
Generates an embedding for the query text, then runs pgvector similarity
|
||||
search. All logic is thin wrappers over database.py primitives.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def semantic_search(
|
||||
query: str,
|
||||
threshold: float = 0.7,
|
||||
limit: int = 10,
|
||||
user_id: str | None = None,
|
||||
) -> list[dict]:
|
||||
"""
|
||||
Embed the query and return matching thoughts ranked by similarity.
|
||||
Returns an empty list if Brain DB is unavailable.
|
||||
"""
|
||||
from .embeddings import get_embedding
|
||||
from .database import search_thoughts
|
||||
|
||||
embedding = await get_embedding(query)
|
||||
return await search_thoughts(embedding, threshold=threshold, limit=limit, user_id=user_id)
|
||||
Reference in New Issue
Block a user