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
import { retrievalQueryKey } from '@jangts/agent-core/kits/retrieval';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
retrievalQueryKey(value: unknown): stringSerialize 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.
| Parameter | Type | Passing | Description |
|---|---|---|---|
value | unknown | Required | — |
Returns: string.
Examples
- Structural query keys and text common prefixes: Small pure functions for stable comparison and usage analysis, not an authorization, hashing, or semantic deduplication system.
- Retrieval: a synchronous retrieval lifecycle with quota: Keep normalization, validation, deduplication, authorization, reading, and follow-up effects on one deterministic call path.
Compare the stable prefix of two real inputs
Beginner · Node.js
import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3import { commonPrefixLength } from '@jangts/agent-core';
console.log(commonPrefixLength('服务:正常', '服务:繁忙')); // 3Different object key order keeps the same structure semantics
Configuration · Node.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'] })); // falseimport { 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'] })); // falseConfigure one read for the same product material
Beginner · Node.js
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);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);