Initial commit

This commit is contained in:
2026-04-08 12:43:24 +02:00
commit be674c2f93
148 changed files with 25007 additions and 0 deletions

28
server/brain/search.py Normal file
View 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)