向量数据库VikingDB
/api/v1/search/grep 接口用于基于模式在指定 URI 范围内搜索内容。
它更适合做关键字、正则模式和精确文本匹配,而不是语义召回。常用于在目录、文档集或代码资源中查找某个特定字段、术语或配置项。
完成 API 鉴权说明 页面的 API Key 获取后,可调用本接口执行模式搜索。
/api/v1/search/grep
统一资源标识符。
POST
客户端对服务器请求的操作类型。
参数 | 值 | 说明 |
|---|---|---|
Content-Type |
| 请求消息类型 |
Authorization |
| 鉴权 |
X-OpenViking-Agent |
| Agent ID |
参数 | 类型 | 必选 | 默认值 | 备注 |
|---|---|---|---|---|
uri | string | 是 | -- | 要搜索的 Viking URI |
pattern | string | 是 | -- | 搜索模式,支持正则表达式 |
case_insensitive | bool | 否 | false | 是否忽略大小写 |
exclude_uri | string | 否 | -- | 需要排除的 URI 前缀 |
node_limit | int | 否 | -- | 最大搜索节点数 |
level_limit | int | 否 | 5 | 最大目录遍历深度 |
字段 | 参数说明 |
|---|---|
status | 请求状态,成功为 |
result | 成功时返回的数据对象 |
result.matches | 命中的结果列表 |
result.matches[].uri | 命中文件 URI |
result.matches[].line | 命中的行号 |
result.matches[].content | 命中的文本内容 |
result.count | 命中总数 |
error | 失败时返回的错误对象 |
error.code | 错误码字符串 |
error.message | 可读的错误描述 |
error.code | 说明 |
|---|---|
UNAUTHENTICATED | 缺少 API Key 或 API Key 无效 |
PERMISSION_DENIED | API Key 权限不足 |
INVALID_ARGUMENT |
|
NOT_FOUND | 指定 |
curl -X POST `https://xxx/api/v1/search/grep` \ -H "Authorization: Bearer {api_key}" \ -H "X-OpenViking-Agent: {agent_id}" \ -H "Content-Type: application/json" \ -d '{ "uri": "viking://resources/", "pattern": "authentication", "case_insensitive": true }'
执行成功返回:
{ "status": "ok", "result": { "matches": [ { "uri": "viking://resources/docs/auth.md", "line": 15, "content": "User authentication is handled by..." } ], "count": 1 } }