Skip to content
中文

retrievalQueryKey ​

CORE · function · Runtime value

Serialize a query into a stable structural key.

Object keys are sorted recursively while array positions are preserved. Values that JSON cannot represent, such as functions or undefined, make JSON.stringify return undefined and therefore produce an error instead of a colliding key.

Import ​

ts
import { retrievalQueryKey } from '@jangts/agent-core/kits/retrieval';
js
import { retrievalQueryKey } from '@jangts/agent-core/kits/retrieval';

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

Definition ​

Call ​

ts
retrievalQueryKey(value: unknown): string

Serialize a query into a stable structural key.

Object keys are sorted recursively while array positions are preserved. Values that JSON cannot represent, such as functions or undefined, make JSON.stringify return undefined and therefore produce an error instead of a colliding key.

ParameterTypePassingDescription
valueunknownRequired—

Returns: string.

Examples ​

Compare the stable prefix of two real inputs ​

Beginner · Node.js

ts
import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3
js
import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3

Different object key order keeps the same structure semantics ​

Configuration · Node.js

ts
import { retrievalQueryKey } from '@jangts/agent-core';
const first = retrievalQueryKey({ query: '服务状态', filters: { region: 'cn', active: true } });
const second = retrievalQueryKey({ filters: { active: true, region: 'cn' }, query: '服务状态' });
console.log(first === second); // true
console.log(retrievalQueryKey({ ids: ['a', 'b'] }) === retrievalQueryKey({ ids: ['b', 'a'] })); // false
js
import { retrievalQueryKey } from '@jangts/agent-core';
const first = retrievalQueryKey({ query: '服务状态', filters: { region: 'cn', active: true } });
const second = retrievalQueryKey({ filters: { active: true, region: 'cn' }, query: '服务状态' });
console.log(first === second); // true
console.log(retrievalQueryKey({ ids: ['a', 'b'] }) === retrievalQueryKey({ ids: ['b', 'a'] })); // false

Configure one read for the same product material ​

Beginner · Node.js

ts
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
type Source = { sourceId: string; text: string };
const state = { queryCount: 0, seen: new Set<string>(), sources: [] as Source[] };
const documents = [{ sourceId: 'manual', text: 'Agent Core 使用指南' }];
const retrieval = Retrieval.defineRetrieval({
  id: 'manual-search', description: '读取已确认的本地演示资料',
  assertInput(query: string) { if (!query.trim()) throw new Error('查询为空'); },
  state: () => state, limit: () => 2,
  execute: (query: string) => ({ sources: documents.filter(item => item.text.includes(query)) }),
});
console.log(retrieval.run('Agent', { app: {}, signal: new AbortController().signal }).result);
js
import { Retrieval } from '@jangts/agent-core/kits/retrieval';
const state = { queryCount: 0, seen: new Set(), sources: [] };
const documents = [{ sourceId: 'manual', text: 'Agent Core 使用指南' }];
const retrieval = Retrieval.defineRetrieval({
    id: 'manual-search', description: '读取已确认的本地演示资料',
    assertInput(query) { if (!query.trim())
        throw new Error('查询为空'); },
    state: () => state, limit: () => 2,
    execute: (query) => ({ sources: documents.filter(item => item.text.includes(query)) }),
});
console.log(retrieval.run('Agent', { app: {}, signal: new AbortController().signal }).result);

API reference, usage examples and developer guides.