Skip to content
中文

TextSearchQuery ​

KIT · interface · Type contract

Search input: a hard result limit and an App-owned filter, both required on every query.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits, @jangts/agent-core/kits/search.

Definition ​

ts
interface TextSearchQuery<Document>

Type parameters ​

Type parameterConstraintDefault type
Document{ id: string }—

Field structure ​

FieldTypeRequiredDescription
limitnumberRequiredRead-only. Maximum number of hits returned.
filter(document: Readonly<Partial<Document>> & { id: string; }) => booleanRequiredRead-only. Required on every query; the application owns authorization and applicability.

Member index ​

MemberPurpose
filterRequired on every query; the application owns authorization and applicability.

Member details ​

filter ​

Required on every query; the application owns authorization and applicability.

ts
TextSearchQuery.filter(document: Readonly<Partial<Document>> & { id: string; }): boolean
ParameterTypePassingDescription
documentReadonly<Partial<Document>> & { id: string; }Required—
Fields of document
FieldTypeRequiredDescription
idPartial<Document>["id"] & stringRequiredSee the type definition and usage context.

Returns: boolean.

Examples ​

First index two interface documents ​

Beginner · Node.js

ts
import { TextSearch } from '@jangts/agent-core/kits/search';
type Document = { id: string; title: string; body: string };
const index = new TextSearch<Document>({ indexRevision: 'manual-v1', fields: ['title', 'body'], storedFields: ['title'] });
index.upsert({ id: 'workflow', title: 'Workflow', body: 'Define reusable agent nodes.' });
index.upsert({ id: 'model', title: 'Model', body: 'Bind a model provider.' });
console.log(index.search({ query: 'agent', limit: 5, filter: () => true }));
js
import { TextSearch } from '@jangts/agent-core/kits/search';
const index = new TextSearch({ indexRevision: 'manual-v1', fields: ['title', 'body'], storedFields: ['title'] });
index.upsert({ id: 'workflow', title: 'Workflow', body: 'Define reusable agent nodes.' });
index.upsert({ id: 'model', title: 'Model', body: 'Bind a model provider.' });
console.log(index.search({ query: 'agent', limit: 5, filter: () => true }));

Configuration · Node.js

Metadata allowed for filtering must be registered as storedFields; field filtering must rely on a trusted App identity and must not trust an identity the model claims.

ts
import { TextSearch } from '@jangts/agent-core/kits/search';
type Document = { id: string; title: string; body: string; audience: string };
const options = { indexRevision: 'manual-v2', fields: ['title', 'body'] as const, storedFields: ['title', 'audience'] as const, boost: { title: 3 }, combineWith: 'AND' as const };
const index = new TextSearch<Document>(options);
index.upsert({ id: 'workflow', title: 'Agent Workflow', body: 'Define reusable nodes.', audience: 'public' });
index.upsert({ id: 'private', title: 'Agent internals', body: 'Internal notes.', audience: 'owner' });
const restored = TextSearch.restore<Document>(options, index.snapshot());
console.log(restored.search({ query: 'agent', limit: 5, filter: document => document.audience === 'public' }));
await restored.remove('workflow');
js
import { TextSearch } from '@jangts/agent-core/kits/search';
const options = { indexRevision: 'manual-v2', fields: ['title', 'body'], storedFields: ['title', 'audience'], boost: { title: 3 }, combineWith: 'AND' };
const index = new TextSearch(options);
index.upsert({ id: 'workflow', title: 'Agent Workflow', body: 'Define reusable nodes.', audience: 'public' });
index.upsert({ id: 'private', title: 'Agent internals', body: 'Internal notes.', audience: 'owner' });
const restored = TextSearch.restore(options, index.snapshot());
console.log(restored.search({ query: 'agent', limit: 5, filter: document => document.audience === 'public' }));
await restored.remove('workflow');

API reference, usage examples and developer guides.