Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(storage): pass context_type in _enqueue_direct_vectorization and handle str from read_file (#1853)

yc1112330d0318a66c13
diff --git a/openviking/storage/local_fs.py b/openviking/storage/local_fs.py
index d68bd615d..9ecfd26d2 100644
--- a/openviking/storage/local_fs.py
+++ b/openviking/storage/local_fs.py
@@ -6,6 +6,7 @@ import os
import re
import zipfile
+from openviking.core.directories import get_context_type_for_uri
from openviking.resource.watch_storage import is_watch_task_control_uri
from openviking.server.identity import RequestContext
from openviking.utils.embedding_utils import vectorize_directory_meta, vectorize_file
@@ -132,11 +133,17 @@ async def _enqueue_direct_vectorization(viking_fs, uri: str, ctx: RequestContext
overview = content.decode("utf-8") if isinstance(content, bytes) else content
except Exception:
return
- await vectorize_directory_meta(dir_uri, abstract, overview, ctx=ctx)
+ await vectorize_directory_meta(
+ dir_uri, abstract, overview, context_type=get_context_type_for_uri(dir_uri), ctx=ctx
+ )
async def index_file(file_uri: str, parent_uri: str, name: str) -> None:
await vectorize_file(
- file_path=file_uri, summary_dict={"name": name}, parent_uri=parent_uri, ctx=ctx
+ file_path=file_uri,
+ summary_dict={"name": name},
+ parent_uri=parent_uri,
+ context_type=get_context_type_for_uri(file_uri),
+ ctx=ctx,
)
await asyncio.gather(*(index_dir(dir_uri) for dir_uri in dir_uris))
diff --git a/openviking/utils/embedding_utils.py b/openviking/utils/embedding_utils.py
index 04148b9cc..451163c5c 100644
--- a/openviking/utils/embedding_utils.py
+++ b/openviking/utils/embedding_utils.py
@@ -454,13 +454,11 @@ async def index_resource(
if await viking_fs.exists(abstract_uri, ctx=ctx):
content = await viking_fs.read_file(abstract_uri, ctx=ctx)
- if isinstance(content, bytes):
- abstract = content.decode("utf-8")
+ abstract = content.decode("utf-8") if isinstance(content, bytes) else content
if await viking_fs.exists(overview_uri, ctx=ctx):
content = await viking_fs.read_file(overview_uri, ctx=ctx)
- if isinstance(content, bytes):
- overview = content.decode("utf-8")
+ overview = content.decode("utf-8") if isinstance(content, bytes) else content
if abstract or overview:
await vectorize_directory_meta(uri, abstract, overview, context_type=context_type, ctx=ctx)