Files
OpenViking/bot/tests/example.py
T
chenjwandDuTao c4cdb5fb1b Fix/bot Fix Memory Consolidation Issues and Integrate Vikingbot as OpenViking Optional Dependency (#492)
* fix

* add log

* add log

* update

* Opt memory

* Opt memory

* Opt memory

* Opt memory

* Fix memory consolidation issues: duplicate session write, hook error, and async

- Fix _consolidate_memory hook error by creating temporary Session when given message list
- Remove duplicate session save logic from _consolidate_memory (handled by caller)
- Make normal memory consolidation async like /new command
- Other fixes: streaming response in CLI and OpenAPI channel

* Integrate vikingbot as openviking optional dependency

- Add vikingbot dependencies to pyproject.toml optional-dependencies
- Update install prompts from vikingbot[X] to openviking[bot-X]
- Update README installation instructions
- Configure setuptools to find vikingbot in bot/ directory
- Add vikingbot package data and script entry

* Remove bot/pyproject.toml

vikingbot is now integrated as part of openviking, no need for separate pyproject.toml

* Update vikingbot installation instructions in root READMEs

- Update from 'uv pip install -e bot/' to 'uv pip install -e ".[bot]"'
- Add quotes around openviking[bot] for shell safety

* update

* Use singleton pattern for VikingClient in hooks

Cache VikingClient instances by workspace_id to avoid repeated client creation
- Add _client_cache dictionary for caching
- Add get_cached_client() helper function
- Update both hooks to use cached client

* Use global singleton for VikingClient instead of per-workspace cache

- Change from per-workspace_id cache to true global singleton
- Create client with None as agent_id (works for all workspaces)
- Simplify client management

* uv run ruff format

---------

Co-authored-by: DuTao <dutao.1786@bytedance.com>
2026-03-09 22:11:03 +08:00

48 lines
1.5 KiB
Python

import openviking as ov
# Initialize OpenViking client with data directory
client = ov.SyncOpenViking(path="./data")
try:
# Initialize the client
client.initialize()
# Add resource (supports URL, file, or directory)
add_result = client.add_resource(
path="/Users/bytedance/Downloads/exp/experience_data_mini.json",
resource_type="json", # 明确指定类型
tags=["large_data", "agent_context", "structured"],
)
root_uri = add_result["root_uri"]
# Explore the resource tree structure
ls_result = client.ls(root_uri)
print(f"Directory structure:\n{ls_result}\n")
# Use glob to find markdown files
glob_result = client.glob(pattern="**/*.md", uri=root_uri)
if glob_result["matches"]:
content = client.read(glob_result["matches"][0])
print(f"Content preview: {content[:200]}...\n")
# Wait for semantic processing to complete
print("Wait for semantic processing...")
client.wait_processed()
# Get abstract and overview of the resource
abstract = client.abstract(root_uri)
overview = client.overview(root_uri)
print(f"Abstract:\n{abstract}\n\nOverview:\n{overview}\n")
# Perform semantic search
results = client.find("what is openviking", target_uri=root_uri)
print("Search results:")
for r in results.resources:
print(f" {r.uri} (score: {r.score:.4f})")
# Close the client
client.close()
except Exception as e:
print(f"Error: {e}")