Skip to content

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

fix(resource): resolve 'file exists' errors on resource add (#845)

bot-of-qin-ctxfba4c1792d32
diff --git a/examples/cloud/GUIDE.md b/examples/cloud/GUIDE.md
index 82dc32386..60a9993a5 100644
--- a/examples/cloud/GUIDE.md
+++ b/examples/cloud/GUIDE.md
@@ -2,7 +2,6 @@
本文档介绍如何将 OpenViking 部署到火山引擎云上,使用 TOS(对象存储)+ VikingDB(向量数据库)+ 方舟大模型作为后端。
-
## 概览
云上部署架构:
diff --git a/openviking/utils/embedding_utils.py b/openviking/utils/embedding_utils.py
index 35aeadccb..d0b9bca37 100644
--- a/openviking/utils/embedding_utils.py
+++ b/openviking/utils/embedding_utils.py
@@ -325,13 +325,13 @@ async def index_resource(
abstract = ""
overview = ""
- if await viking_fs.exists(abstract_uri):
- content = await viking_fs.read_file(abstract_uri)
+ 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")
- if await viking_fs.exists(overview_uri):
- content = await viking_fs.read_file(overview_uri)
+ 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")
diff --git a/openviking/utils/resource_processor.py b/openviking/utils/resource_processor.py
index 9dd61f971..9f9ef43f9 100644
--- a/openviking/utils/resource_processor.py
+++ b/openviking/utils/resource_processor.py
@@ -228,13 +228,16 @@ class ResourceProcessor:
dst_path = viking_fs._uri_to_path(root_uri, ctx=ctx)
parent_path = dst_path.rsplit("/", 1)[0] if "/" in dst_path else dst_path
- parent_uri = "/".join(root_uri.rsplit("/", 1)[:-1])
+ parent_uri = "/".join(root_uri.rstrip("/").rsplit("/", 1)[:-1])
if parent_uri:
await viking_fs.mkdir(parent_uri, exist_ok=True, ctx=ctx)
async with LockContext(lock_manager, [parent_path], lock_mode="point"):
if candidate_uri:
- root_uri = await self.tree_builder._resolve_unique_uri(candidate_uri)
+ with viking_fs.bind_request_context(ctx):
+ root_uri = await self.tree_builder._resolve_unique_uri(
+ candidate_uri
+ )
result["root_uri"] = root_uri
dst_path = viking_fs._uri_to_path(root_uri, ctx=ctx)