5 分钟上手 OpenViking。
在开始使用 OpenViking 之前,请确保您的环境满足以下要求:
- Python 版本:3.10 或更高版本
- 操作系统:Linux、macOS、Windows
- 网络连接:需要稳定的网络连接(用于下载依赖包和访问模型服务)
OpenViking 支持通过 Python Package 安装作为本地库使用,也支持通过 Docker 快速启动独立服务。
pip install openviking --upgrade --force-reinstall如果你希望将 OpenViking 作为独立的服务运行,推荐使用 Docker。
-
准备配置文件与数据目录 在宿主机上创建数据目录,并准备好
ov.conf配置文件(配置项参考下方“配置环境”章节):mkdir -p ~/.openviking/data touch ~/.openviking/ov.conf
-
使用 Docker Compose 启动 创建
docker-compose.yml文件:services: openviking: image: ghcr.io/volcengine/openviking:main container_name: openviking ports: - "1933:1933" volumes: - ~/.openviking/ov.conf:/app/ov.conf - ~/.openviking/data:/app/data restart: unless-stopped
然后在同目录下执行启动命令:
docker-compose up -d
💡 Mac 本地网络访问提示 (Connection reset 报错):
默认情况下,OpenViking 为了安全仅监听
127.0.0.1。如果你在 Mac 上使用 Docker,宿主机可能无法直接通过localhost:1933访问。推荐解决方案:使用 socat 端口转发(无需修改配置): 在你的
docker-compose.yml中覆盖默认启动命令,利用socat在容器内部进行端口转发:services: openviking: image: ghcr.io/volcengine/openviking:main ports: - "1933:1934" # 将宿主机 1933 映射到容器 1934 volumes: - ~/.openviking/ov.conf:/app/ov.conf - ~/.openviking/data:/app/data command: /bin/sh -c "apt-get update && apt-get install -y socat && socat TCP-LISTEN:1934,fork,reuseaddr TCP:127.0.0.1:1933 & openviking-server"这样即可完美解决 Mac 宿主机的访问问题。
OpenViking 需要以下模型能力:
- VLM 模型:用于图像和内容理解
- Embedding 模型:用于向量化和语义检索
OpenViking 支持多种模型服务:
- 火山引擎(豆包模型):推荐使用,成本低、性能好,新用户有免费额度。如需购买和开通,请参考:火山引擎购买指南
- OpenAI 模型:支持 GPT-4V 等 VLM 模型和 OpenAI Embedding 模型
- 其他自定义模型服务:支持兼容 OpenAI API 格式的模型服务
创建配置文件 ~/.openviking/ov.conf:
{
"embedding": {
"dense": {
"api_base" : "<api-endpoint>",
"api_key" : "<your-api-key>",
"provider" : "<provider-type>",
"dimension": 1024,
"model" : "<model-name>"
}
},
"vlm": {
"api_base" : "<api-endpoint>",
"api_key" : "<your-api-key>",
"provider" : "<provider-type>",
"model" : "<model-name>"
}
}各模型服务的完整配置示例请参见 配置指南 - 配置示例。
配置文件放在默认路径 ~/.openviking/ov.conf 时,无需额外设置,OpenViking 会自动加载。
如果配置文件放在其他位置,需要通过环境变量指定:
export OPENVIKING_CONFIG_FILE=/path/to/your/ov.conf创建 example.py:
import openviking as ov
# Initialize OpenViking client with data directory
client = ov.OpenViking(path="./data")
try:
# Initialize the client
client.initialize()
# Add resource (supports URL, file, or directory)
add_result = client.add_resource(
path="https://raw.githubusercontent.com/volcengine/OpenViking/refs/heads/main/README.md"
)
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}")python example.pyDirectory structure:
...
Content preview: ...
Wait for semantic processing...
Abstract:
...
Overview:
...
Search results:
viking://resources/... (score: 0.8523)
...
恭喜!你已成功运行 OpenViking。
想要将 OpenViking 作为共享服务运行?请参见 快速开始:服务端模式。