From b09206c5d0d0a6f96bead8e53fc990b897fc5a57 Mon Sep 17 00:00:00 2001 From: yc111233 Date: Fri, 10 Apr 2026 03:43:20 +0800 Subject: [PATCH] fix: derive context_type from URI in index_resource index_resource() always passed the default context_type="resource" to vectorize_directory_meta() and vectorize_file(), even when indexing memory directories (URIs containing /memories/). This caused all records created via the /api/v1/content/reindex endpoint to be tagged as "resource" instead of "memory", breaking stats aggregation (which filters on context_type="memory") and search scoping. Use the existing get_context_type_for_uri() helper to derive the correct context_type from the URI and pass it through to both vectorize_directory_meta() and vectorize_file(). Co-Authored-By: Claude Opus 4.6 --- openviking/utils/embedding_utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/openviking/utils/embedding_utils.py b/openviking/utils/embedding_utils.py index cf442cc0a1b..bb0e7dcf127 100644 --- a/openviking/utils/embedding_utils.py +++ b/openviking/utils/embedding_utils.py @@ -11,6 +11,7 @@ from typing import Dict, Optional from openviking.core.context import Context, ContextLevel, ResourceContentType, Vectorize +from openviking.core.directories import get_context_type_for_uri from openviking.server.identity import RequestContext from openviking.storage.queuefs import get_queue_manager from openviking.storage.queuefs.embedding_msg_converter import EmbeddingMsgConverter @@ -326,8 +327,13 @@ async def index_resource( 1. Reads .abstract.md and .overview.md and vectorizes them. 2. Scans files in the directory and vectorizes them. + + The context_type is derived from the URI so that memory directories + (``/memories/``) are indexed as ``"memory"`` rather than the default + ``"resource"``. """ viking_fs = get_viking_fs() + context_type = get_context_type_for_uri(uri) # 1. Index Directory Metadata abstract_uri = f"{uri}/.abstract.md" @@ -347,7 +353,9 @@ async def index_resource( overview = content.decode("utf-8") if abstract or overview: - await vectorize_directory_meta(uri, abstract, overview, ctx=ctx) + await vectorize_directory_meta( + uri, abstract, overview, context_type=context_type, ctx=ctx + ) # 2. Index Files try: @@ -368,7 +376,11 @@ async def index_resource( # For direct indexing, we might not have summaries. # We pass empty summary_dict, vectorize_file will try to read content for text files. await vectorize_file( - file_path=file_uri, summary_dict={"name": file_name}, parent_uri=uri, ctx=ctx + file_path=file_uri, + summary_dict={"name": file_name}, + parent_uri=uri, + context_type=context_type, + ctx=ctx, ) except Exception as e: