Compare commits

...

2 Commits

Author SHA1 Message Date
b6f01f9b3f skip content < 100 chars 2025-12-26 03:36:28 +01:00
499a3cb170 debug cleanup 2025-12-26 03:26:33 +01:00

View File

@@ -35,18 +35,12 @@ mcp = FastMCP("Cavepedia MCP")
def get_user_roles() -> list[str]:
"""Extract user roles from the X-User-Roles header."""
headers = get_http_headers()
print(f"DEBUG: All headers received: {dict(headers)}")
roles_header = headers.get("x-user-roles", "")
print(f"DEBUG: x-user-roles header value: '{roles_header}'")
if roles_header:
try:
roles = json.loads(roles_header)
print(f"DEBUG: Parsed roles: {roles}")
return roles
except json.JSONDecodeError as e:
print(f"DEBUG: JSON decode error: {e}")
return json.loads(roles_header)
except json.JSONDecodeError:
return []
print("DEBUG: No roles header found, returning empty list")
return []
def is_sources_only() -> bool:
@@ -82,7 +76,7 @@ def search_caving_documents(query: str, priority_prefixes: list[str] | None = No
top_n = 2
candidate_limit = top_n * 4
rows = conn.execute(
'SELECT * FROM embeddings WHERE embedding IS NOT NULL AND role = ANY(%s) ORDER BY embedding <=> %s::vector LIMIT %s',
'SELECT * FROM embeddings WHERE embedding IS NOT NULL AND LENGTH(content) > 100 AND role = ANY(%s) ORDER BY embedding <=> %s::vector LIMIT %s',
(roles, query_embedding, candidate_limit)
).fetchall()
@@ -102,6 +96,7 @@ def search_caving_documents(query: str, priority_prefixes: list[str] | None = No
sources_only = is_sources_only()
for result in rerank_resp.results:
row = rows[result.index]
content = row['content'] or ''
score = result.relevance_score
# Boost score if key starts with any priority prefix (e.g., 'nss/aca')
@@ -113,7 +108,6 @@ def search_caving_documents(query: str, priority_prefixes: list[str] | None = No
if sources_only:
docs.append({'key': row['key'], 'relevance': round(score, 3)})
else:
content = row['content'] or ''
docs.append({'key': row['key'], 'content': content, 'relevance': round(score, 3)})
# Re-sort by boosted score and return top_n