notebook
This commit is contained in:
+12
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user