Agents Knowledge Store
Classes
Classes
KnowledgeStoreClient
Main client for interacting with the knowledge store
Constructor
constructor(config: KnowledgeStoreConfig)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
config | KnowledgeStoreConfig | Yes | - Configuration for the knowledge store |
Methods
isConnected
Check if connected to Redis
isConnected(): Promise<boolean>
Returns:
Promise<boolean> -
disconnect
Disconnect from Redis
disconnect(): Promise<void>
Returns:
Promise<void> -
create
Create a new knowledge item
create(item: CreateKnowledgeItem): Promise<OperationResult<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
item | CreateKnowledgeItem | Yes | - Knowledge item to create |
Returns:
Promise<OperationResult<KnowledgeItem>> - Operation result with created item
Examples:
const result = await client.create({
type: KnowledgeType.DIRECTIVE,
namespace: 'project-123',
title: 'Always use TypeScript',
content: 'All code in this project must be written in TypeScript',
metadata: {
source: 'team-lead',
priority: KnowledgePriority.CRITICAL,
tags: ['code-standards', 'typescript']
}
});
get
Get a knowledge item by ID
get(namespace: string, id: string, trackAccess?: boolean | undefined): Promise<OperationResult<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | - Namespace of the item |
id | string | Yes | - ID of the item |
trackAccess | boolean | undefined | No | - Whether to increment access count (default: use config) |
Returns:
Promise<OperationResult<KnowledgeItem>> - Operation result with the item
update
Update a knowledge item
update(namespace: string, id: string, updates: UpdateKnowledgeItem): Promise<OperationResult<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | - Namespace of the item |
id | string | Yes | - ID of the item |
updates | UpdateKnowledgeItem | Yes | - Fields to update |
Returns:
Promise<OperationResult<KnowledgeItem>> - Operation result with updated item
delete
Delete a knowledge item
delete(namespace: string, id: string): Promise<OperationResult<void>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
namespace | string | Yes | - Namespace of the item |
id | string | Yes | - ID of the item |
Returns:
Promise<OperationResult<void>> - Operation result
search
Search for knowledge items
search(options?: SearchOptions): Promise<SearchResults<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options | SearchOptions | No | - Search options |
Returns:
Promise<SearchResults<KnowledgeItem>> - Search results with pagination
Examples:
const results = await client.search({
query: 'typescript',
filter: {
type: KnowledgeType.DIRECTIVE,
priority: [KnowledgePriority.HIGH, KnowledgePriority.CRITICAL],
tags: ['code-standards']
},
limit: 10,
sortBy: 'priority',
sortOrder: 'desc'
});
semanticSearch
Semantic search using vector similarity
semanticSearch(options: SemanticSearchOptions): Promise<SearchResults<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
options | SemanticSearchOptions | Yes | - Semantic search options with embedding vector |
Returns:
Promise<SearchResults<KnowledgeItem>> - Search results with similarity scores
Examples:
const embedding = await generateEmbedding('code quality best practices');
const results = await client.semanticSearch({
embedding,
threshold: 0.8,
limit: 5
});
getStats
Get statistics about the knowledge store
getStats(namespace?: string | undefined): Promise<KnowledgeStats>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
namespace | string | undefined | No | - Optional namespace to filter stats |
Returns:
Promise<KnowledgeStats> - Knowledge store statistics
batchCreate
Create multiple knowledge items in a batch
batchCreate(items: CreateKnowledgeItem[]): Promise<BatchOperationResult<KnowledgeItem>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
items | CreateKnowledgeItem[] | Yes | - Array of items to create |
Returns:
Promise<BatchOperationResult<KnowledgeItem>> - Batch operation result
batchDelete
Delete multiple knowledge items in a batch
batchDelete(items: { namespace: string; id: string; }[]): Promise<BatchOperationResult<void>>
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
items | { namespace: string; id: string; }[] | Yes | - Array of {namespace, id} to delete |
Returns:
Promise<BatchOperationResult<void>> - Batch operation result
KnowledgeStoreError
Custom error for knowledge store operations
Constructor
constructor(code: KnowledgeErrorCode, message: string, details?: any)
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
code | KnowledgeErrorCode | Yes | |
message | string | Yes | |
details | any | No |