fix: Update models and viz to use int-only doc_id

- algorithms.py: Revert SearchResult.id to int (all docs use int IDs now)
- semantic.py: Revert SemanticSearchResult.id to int, remove Union import
- viz_routes.py: Remove str() conversion when querying doc_id from Qdrant
- viz_routes.py: Convert doc_id from query param to int in chunk context

Fixes vector visualization which was collapsing all chunks to a single
point because Qdrant queries were failing to match doc_id (string vs int).
This commit is contained in:
Chris Coutinho
2025-11-20 12:32:27 +01:00
parent d0691d5aa0
commit f1a5fac1b9
3 changed files with 6 additions and 4 deletions
+4 -2
View File
@@ -235,7 +235,7 @@ async def vector_visualization_search(request: Request) -> JSONResponse:
must_conditions = [ must_conditions = [
FieldCondition( FieldCondition(
key="doc_id", key="doc_id",
match=MatchValue(value=str(result.id)), match=MatchValue(value=result.id),
), ),
FieldCondition( FieldCondition(
key="user_id", key="user_id",
@@ -524,6 +524,8 @@ async def chunk_context_endpoint(request: Request) -> JSONResponse:
start = int(start_str) start = int(start_str)
end = int(end_str) end = int(end_str)
# Convert doc_id to int (all document types use int IDs)
doc_id_int = int(doc_id)
# Get authenticated Nextcloud client # Get authenticated Nextcloud client
from nextcloud_mcp_server.auth.userinfo_routes import ( from nextcloud_mcp_server.auth.userinfo_routes import (
@@ -536,7 +538,7 @@ async def chunk_context_endpoint(request: Request) -> JSONResponse:
chunk_context = await get_chunk_with_context( chunk_context = await get_chunk_with_context(
nc_client=nc_client, nc_client=nc_client,
user_id=request.user.display_name, # User ID from auth user_id=request.user.display_name, # User ID from auth
doc_id=doc_id, doc_id=doc_id_int,
doc_type=doc_type, doc_type=doc_type,
chunk_start=start, chunk_start=start,
chunk_end=end, chunk_end=end,
+1 -1
View File
@@ -10,7 +10,7 @@ from .base import BaseResponse
class SemanticSearchResult(BaseModel): class SemanticSearchResult(BaseModel):
"""Model for semantic search results with additional metadata.""" """Model for semantic search results with additional metadata."""
id: int = Field(description="Document ID") id: int = Field(description="Document ID (int for all document types)")
doc_type: str = Field( doc_type: str = Field(
description="Document type (note, calendar_event, deck_card, etc.)" description="Document type (note, calendar_event, deck_card, etc.)"
) )
+1 -1
View File
@@ -123,7 +123,7 @@ class SearchResult:
"""A single search result with metadata and score. """A single search result with metadata and score.
Attributes: Attributes:
id: Document ID id: Document ID (int for all document types)
doc_type: Document type (note, file, calendar, contact, etc.) doc_type: Document type (note, file, calendar, contact, etc.)
title: Document title title: Document title
excerpt: Content excerpt showing match context excerpt: Content excerpt showing match context