This commit is contained in:
2026-06-09 15:46:34 +02:00
parent 8c01fd6e1a
commit 96f3b2c280
4 changed files with 29 additions and 5 deletions
+12 -5
View File
@@ -411,7 +411,8 @@ def search(
try:
# ── Full-text search ──
conditions = ["deleted = FALSE", "fts @@ plainto_tsquery('simple', %s)"]
conditions = ["deleted = FALSE",
"fts @@ plainto_tsquery('simple', kb_immutable_unaccent(%s))"]
params: list[Any] = [query]
if types:
@@ -427,14 +428,17 @@ def search(
conditions.append("importance >= %s")
params.append(min_importance)
if not include_sessions:
conditions.append("mem_type != 'summary' OR session_id IS NOT NULL")
# Vyřaď session summaries (summary + session_id), ale ponech
# samostatné summary záznamy. POZOR na závorky — bez nich by se
# OR navázalo na celý WHERE a obešlo všechny ostatní filtry.
conditions.append("(mem_type != 'summary' OR session_id IS NULL)")
where = " AND ".join(conditions)
rows = conn.execute(
f"""
SELECT id, mem_type, title, content, summary, tags,
project, source, session_id, importance, created_at,
ts_rank(fts, plainto_tsquery('simple', %s)) AS score
ts_rank(fts, plainto_tsquery('simple', kb_immutable_unaccent(%s))) AS score
FROM kb_memories
WHERE {where}
ORDER BY score DESC, importance DESC
@@ -446,8 +450,11 @@ def search(
fts_ids = {r["id"] for r in rows}
results = [_row_to_dict(r) for r in rows]
# ── Vector search (pouze pokud semantic=True) ──
query_emb = get_embedding(query) if semantic else None
# ── Vector search ──
# Spustí se když semantic=True, NEBO jako automatický fallback,
# pokud full-text nic nenašel (synonyma / významová shoda).
need_semantic = semantic or not rows
query_emb = get_embedding(query) if need_semantic else None
if query_emb:
try:
import numpy as np