Skip to content
English

VectorSearchQuery ​

KIT · interface · 类型合同

Search options excluding the query vector, which search takes alongside them.

导入 ​

ts
import type { VectorSearchQuery } from '@jangts/agent-core/kits/vector-search';
js
/** @typedef {import('@jangts/agent-core/kits/vector-search').VectorSearchQuery} VectorSearchQuery */

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits、@jangts/agent-core/kits/vector-search。

定义 ​

ts
interface VectorSearchQuery<Document>

泛型参数 ​

类型参数约束默认类型
Document——

字段结构 ​

字段类型必需说明
limitnumber必需只读。Maximum hits returned, 1..1000.
filter(document: Readonly<Document>) => boolean必需只读。Synchronous predicate over a document snapshot; false excludes the candidate.
minScorenumber | undefined可省略只读。Minimum cosine score in [-1, 1]; defaults to -1, which keeps every candidate.
groupBy((document: Readonly<Document>) => string) | undefined可省略只读。Optional group key; only the best hit per group is kept, defaulting to the document id.

成员目录 ​

成员用途
filterSynchronous predicate over a document snapshot; false excludes the candidate.

成员详情 ​

filter ​

Synchronous predicate over a document snapshot; false excludes the candidate.

ts
VectorSearchQuery.filter(document: Readonly<Document>): boolean
参数类型传递说明
documentReadonly<Document>必需—

返回: boolean。

使用示例 ​

先在同一空间检索说明片段 ​

入门 · Node.js

二维向量用于展示合同;不代表真实文本 embedding 或检索质量。

ts
import { VectorSearch } from '@jangts/agent-core/kits/vector-search';
const index = new VectorSearch<{ id: string; text: string }>({ identity: 'demo-direction-v1', dimensions: 2 });
index.upsert({ document: { id: 'workflow', text: '工作流说明' }, vector: [1, 0] });
index.upsert({ document: { id: 'model', text: '模型说明' }, vector: [0, 1] });
console.log(index.search({ vector: [0.9, 0.1], limit: 2, filter: () => true }));
js
import { VectorSearch } from '@jangts/agent-core/kits/vector-search';
const index = new VectorSearch({ identity: 'demo-direction-v1', dimensions: 2 });
index.upsert({ document: { id: 'workflow', text: '工作流说明' }, vector: [1, 0] });
index.upsert({ document: { id: 'model', text: '模型说明' }, vector: [0, 1] });
console.log(index.search({ vector: [0.9, 0.1], limit: 2, filter: () => true }));

相同 search 增加权限、阈值和文档分组 ​

配置 · Node.js

ts
import { VectorSearch } from '@jangts/agent-core/kits/vector-search';
type Chunk = { id: string; documentId: string; audience: string; text: string };
const index = new VectorSearch<Chunk>({ identity: 'demo-direction-v1', dimensions: 2 });
index.upsert({ document: { id: 'manual-1', documentId: 'manual', audience: 'public', text: '工作流定义' }, vector: [1, 0] });
index.upsert({ document: { id: 'manual-2', documentId: 'manual', audience: 'public', text: '工作流调用' }, vector: [0.95, 0.05] });
index.upsert({ document: { id: 'private-1', documentId: 'private', audience: 'owner', text: '内部说明' }, vector: [1, 0] });
console.log(index.search({ vector: [1, 0], limit: 5, minScore: 0.5, filter: row => row.audience === 'public', groupBy: row => row.documentId }));
js
import { VectorSearch } from '@jangts/agent-core/kits/vector-search';
const index = new VectorSearch({ identity: 'demo-direction-v1', dimensions: 2 });
index.upsert({ document: { id: 'manual-1', documentId: 'manual', audience: 'public', text: '工作流定义' }, vector: [1, 0] });
index.upsert({ document: { id: 'manual-2', documentId: 'manual', audience: 'public', text: '工作流调用' }, vector: [0.95, 0.05] });
index.upsert({ document: { id: 'private-1', documentId: 'private', audience: 'owner', text: '内部说明' }, vector: [1, 0] });
console.log(index.search({ vector: [1, 0], limit: 5, minScore: 0.5, filter: row => row.audience === 'public', groupBy: row => row.documentId }));

相关策略源码 ​

接口参考、使用示例与开发指南。