You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
检索(Retrival)
grep-模式搜索
复制全文
下载 pdf
grep-模式搜索

概述

/api/v1/search/grep 接口用于基于模式在指定 URI 范围内搜索内容。
它更适合做关键字、正则模式和精确文本匹配,而不是语义召回。常用于在目录、文档集或代码资源中查找某个特定字段、术语或配置项。

前置条件

完成 API 鉴权说明 页面的 API Key 获取后,可调用本接口执行模式搜索。

请求接口

URI

/api/v1/search/grep
统一资源标识符。

请求方法

POST
客户端对服务器请求的操作类型。

请求头

参数

说明

Content-Type

application/json

请求消息类型

Authorization

Bearer {api_key}

鉴权

X-OpenViking-Agent

{agent_id}

Agent ID

请求参数

参数

类型

必选

默认值

备注

uri

string

--

要搜索的 Viking URI

pattern

string

--

搜索模式,支持正则表达式

case_insensitive

bool

false

是否忽略大小写

exclude_uri

string

--

需要排除的 URI 前缀

node_limit

int

--

最大搜索节点数

level_limit

int

5

最大目录遍历深度

响应消息

字段

参数说明

status

请求状态,成功为 "ok",失败为 "error"

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

pattern 或请求参数非法

NOT_FOUND

指定 uri 不存在

完整示例

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
  }
}
最近更新时间:2026.05.26 11:19:27
这个页面对您有帮助吗?
有用
有用
无用
无用