@weavelogic/knowledge-graph-agent 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -3
- package/dist/_virtual/__vite-browser-external.js +2 -2
- package/dist/_virtual/__vite-browser-external.js.map +1 -1
- package/dist/_virtual/index12.js +7 -0
- package/dist/_virtual/index12.js.map +1 -0
- package/dist/_virtual/ort-web.min.js +8 -0
- package/dist/_virtual/ort-web.min.js.map +1 -0
- package/dist/_virtual/ort-web.min2.js +5 -0
- package/dist/_virtual/ort-web.min2.js.map +1 -0
- package/dist/agents/base-agent.d.ts +63 -0
- package/dist/agents/base-agent.d.ts.map +1 -1
- package/dist/agents/base-agent.js +139 -0
- package/dist/agents/base-agent.js.map +1 -1
- package/dist/agents/coordinator-agent.d.ts +422 -0
- package/dist/agents/coordinator-agent.d.ts.map +1 -0
- package/dist/agents/documenter-agent.d.ts +298 -0
- package/dist/agents/documenter-agent.d.ts.map +1 -0
- package/dist/agents/index.d.ts +11 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +4 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/mixins/index.d.ts +9 -0
- package/dist/agents/mixins/index.d.ts.map +1 -0
- package/dist/agents/mixins/trajectory-mixin.d.ts +112 -0
- package/dist/agents/mixins/trajectory-mixin.d.ts.map +1 -0
- package/dist/agents/optimizer-agent.d.ts +388 -0
- package/dist/agents/optimizer-agent.d.ts.map +1 -0
- package/dist/agents/planner-agent.d.ts +395 -0
- package/dist/agents/planner-agent.d.ts.map +1 -0
- package/dist/agents/registry.d.ts.map +1 -1
- package/dist/agents/registry.js +5 -0
- package/dist/agents/registry.js.map +1 -1
- package/dist/agents/reviewer-agent.d.ts +330 -0
- package/dist/agents/reviewer-agent.d.ts.map +1 -0
- package/dist/agents/types.d.ts +12 -1
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/types.js +1 -0
- package/dist/agents/types.js.map +1 -1
- package/dist/cli/commands/hive-mind/add-frontmatter.d.ts +102 -0
- package/dist/cli/commands/hive-mind/add-frontmatter.d.ts.map +1 -0
- package/dist/cli/commands/hive-mind/add-frontmatter.js +439 -0
- package/dist/cli/commands/hive-mind/add-frontmatter.js.map +1 -0
- package/dist/cli/commands/hive-mind/analyze-links.d.ts +80 -0
- package/dist/cli/commands/hive-mind/analyze-links.d.ts.map +1 -0
- package/dist/cli/commands/hive-mind/analyze-links.js +367 -0
- package/dist/cli/commands/hive-mind/analyze-links.js.map +1 -0
- package/dist/cli/commands/hive-mind/find-connections.d.ts +75 -0
- package/dist/cli/commands/hive-mind/find-connections.d.ts.map +1 -0
- package/dist/cli/commands/hive-mind/find-connections.js +347 -0
- package/dist/cli/commands/hive-mind/find-connections.js.map +1 -0
- package/dist/cli/commands/hive-mind/index.d.ts +37 -0
- package/dist/cli/commands/hive-mind/index.d.ts.map +1 -0
- package/dist/cli/commands/hive-mind/index.js +33 -0
- package/dist/cli/commands/hive-mind/index.js.map +1 -0
- package/dist/cli/commands/hive-mind/validate-names.d.ts +79 -0
- package/dist/cli/commands/hive-mind/validate-names.d.ts.map +1 -0
- package/dist/cli/commands/hive-mind/validate-names.js +353 -0
- package/dist/cli/commands/hive-mind/validate-names.js.map +1 -0
- package/dist/cli/commands/vector.js +2 -0
- package/dist/cli/commands/vector.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +7 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/equilibrium/agent-equilibrium.d.ts +194 -0
- package/dist/equilibrium/agent-equilibrium.d.ts.map +1 -0
- package/dist/equilibrium/agent-equilibrium.js +304 -0
- package/dist/equilibrium/agent-equilibrium.js.map +1 -0
- package/dist/equilibrium/graph-equilibrium.d.ts +177 -0
- package/dist/equilibrium/graph-equilibrium.d.ts.map +1 -0
- package/dist/equilibrium/index.d.ts +11 -0
- package/dist/equilibrium/index.d.ts.map +1 -0
- package/dist/equilibrium/memory-equilibrium.d.ts +153 -0
- package/dist/equilibrium/memory-equilibrium.d.ts.map +1 -0
- package/dist/graphql/resolvers/index.d.ts.map +1 -1
- package/dist/graphql/resolvers/queries.d.ts +11 -0
- package/dist/graphql/resolvers/queries.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/inference/index.d.ts +9 -0
- package/dist/inference/index.d.ts.map +1 -0
- package/dist/inference/model-selection.d.ts +131 -0
- package/dist/inference/model-selection.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/agent-booster-adapter.d.ts +265 -0
- package/dist/integrations/agentic-flow/adapters/agent-booster-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/agentdb-adapter.d.ts +197 -0
- package/dist/integrations/agentic-flow/adapters/agentdb-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/agentdb-vector-store.d.ts +249 -0
- package/dist/integrations/agentic-flow/adapters/agentdb-vector-store.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/base-adapter.d.ts +120 -0
- package/dist/integrations/agentic-flow/adapters/base-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/federation-hub-adapter.d.ts +444 -0
- package/dist/integrations/agentic-flow/adapters/federation-hub-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/index.d.ts +17 -0
- package/dist/integrations/agentic-flow/adapters/index.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/model-router-adapter.d.ts +242 -0
- package/dist/integrations/agentic-flow/adapters/model-router-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/quic-transport-adapter.d.ts +364 -0
- package/dist/integrations/agentic-flow/adapters/quic-transport-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/adapters/reasoning-bank-adapter.d.ts +209 -0
- package/dist/integrations/agentic-flow/adapters/reasoning-bank-adapter.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/benchmark/index.d.ts +9 -0
- package/dist/integrations/agentic-flow/benchmark/index.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/benchmark/vector-benchmark.d.ts +253 -0
- package/dist/integrations/agentic-flow/benchmark/vector-benchmark.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/config.d.ts +109 -0
- package/dist/integrations/agentic-flow/config.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/feature-flags.d.ts +140 -0
- package/dist/integrations/agentic-flow/feature-flags.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/index.d.ts +22 -0
- package/dist/integrations/agentic-flow/index.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/migration/index.d.ts +9 -0
- package/dist/integrations/agentic-flow/migration/index.d.ts.map +1 -0
- package/dist/integrations/agentic-flow/migration/migrate-to-agentdb.d.ts +242 -0
- package/dist/integrations/agentic-flow/migration/migrate-to-agentdb.d.ts.map +1 -0
- package/dist/learning/index.d.ts +91 -0
- package/dist/learning/index.d.ts.map +1 -0
- package/dist/learning/learning-loop.d.ts +176 -0
- package/dist/learning/learning-loop.d.ts.map +1 -0
- package/dist/learning/services/ab-testing-framework.d.ts +135 -0
- package/dist/learning/services/ab-testing-framework.d.ts.map +1 -0
- package/dist/learning/services/agent-priming-service.d.ts +207 -0
- package/dist/learning/services/agent-priming-service.d.ts.map +1 -0
- package/dist/learning/services/daily-log-generator.d.ts +113 -0
- package/dist/learning/services/daily-log-generator.d.ts.map +1 -0
- package/dist/learning/services/index.d.ts +14 -0
- package/dist/learning/services/index.d.ts.map +1 -0
- package/dist/learning/services/memory-extraction-service.d.ts +87 -0
- package/dist/learning/services/memory-extraction-service.d.ts.map +1 -0
- package/dist/learning/services/task-completion-consumer.d.ts +162 -0
- package/dist/learning/services/task-completion-consumer.d.ts.map +1 -0
- package/dist/learning/services/trajectory-tracker.d.ts +174 -0
- package/dist/learning/services/trajectory-tracker.d.ts.map +1 -0
- package/dist/learning/types.d.ts +516 -0
- package/dist/learning/types.d.ts.map +1 -0
- package/dist/mcp/clients/claude-flow-memory-client.d.ts +259 -0
- package/dist/mcp/clients/claude-flow-memory-client.d.ts.map +1 -0
- package/dist/mcp/clients/claude-flow-memory-client.js +305 -0
- package/dist/mcp/clients/claude-flow-memory-client.js.map +1 -0
- package/dist/mcp/clients/index.d.ts +11 -0
- package/dist/mcp/clients/index.d.ts.map +1 -0
- package/dist/mcp/clients/mcp-client-adapter.d.ts +146 -0
- package/dist/mcp/clients/mcp-client-adapter.d.ts.map +1 -0
- package/dist/mcp/clients/mcp-client-adapter.js +372 -0
- package/dist/mcp/clients/mcp-client-adapter.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/memory/vault-sync.d.ts +12 -0
- package/dist/memory/vault-sync.d.ts.map +1 -1
- package/dist/memory/vault-sync.js +94 -11
- package/dist/memory/vault-sync.js.map +1 -1
- package/dist/node_modules/@huggingface/jinja/dist/index.js +118 -0
- package/dist/node_modules/@huggingface/jinja/dist/index.js.map +1 -0
- package/dist/node_modules/@typescript-eslint/project-service/dist/index.js +1 -1
- package/dist/node_modules/@xenova/transformers/src/backends/onnx.js +24 -0
- package/dist/node_modules/@xenova/transformers/src/backends/onnx.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/configs.js +52 -0
- package/dist/node_modules/@xenova/transformers/src/configs.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/env.js +35 -0
- package/dist/node_modules/@xenova/transformers/src/env.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/models.js +3852 -0
- package/dist/node_modules/@xenova/transformers/src/models.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/tokenizers.js +144 -0
- package/dist/node_modules/@xenova/transformers/src/tokenizers.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/core.js +52 -0
- package/dist/node_modules/@xenova/transformers/src/utils/core.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/generation.js +623 -0
- package/dist/node_modules/@xenova/transformers/src/utils/generation.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/hub.js +395 -0
- package/dist/node_modules/@xenova/transformers/src/utils/hub.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/image.js +12 -0
- package/dist/node_modules/@xenova/transformers/src/utils/image.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/maths.js +89 -0
- package/dist/node_modules/@xenova/transformers/src/utils/maths.js.map +1 -0
- package/dist/node_modules/@xenova/transformers/src/utils/tensor.js +750 -0
- package/dist/node_modules/@xenova/transformers/src/utils/tensor.js.map +1 -0
- package/dist/node_modules/fdir/dist/index.js +13 -13
- package/dist/node_modules/fdir/dist/index.js.map +1 -1
- package/dist/node_modules/onnxruntime-common/dist/lib/backend-impl.js +67 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/backend-impl.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/env-impl.js +24 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/env-impl.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/env.js +6 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/env.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/index.js +11 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/index.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/inference-session-impl.js +162 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/inference-session-impl.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/inference-session.js +6 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/inference-session.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/tensor-impl.js +393 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/tensor-impl.js.map +1 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/tensor.js +6 -0
- package/dist/node_modules/onnxruntime-common/dist/lib/tensor.js.map +1 -0
- package/dist/node_modules/onnxruntime-web/dist/ort-web.min.js +12919 -0
- package/dist/node_modules/onnxruntime-web/dist/ort-web.min.js.map +1 -0
- package/dist/node_modules/tinyglobby/dist/index.js +14 -14
- package/dist/node_modules/tinyglobby/dist/index.js.map +1 -1
- package/dist/node_modules/typescript/lib/typescript.js +24 -24
- package/dist/node_modules/typescript/lib/typescript.js.map +1 -1
- package/dist/transport/agent-transport.d.ts +269 -0
- package/dist/transport/agent-transport.d.ts.map +1 -0
- package/dist/transport/index.d.ts +10 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/dist/vector/services/embedding-service.d.ts +244 -0
- package/dist/vector/services/embedding-service.d.ts.map +1 -0
- package/dist/vector/services/embedding-service.js +10 -0
- package/dist/vector/services/embedding-service.js.map +1 -0
- package/dist/vector/services/hybrid-search.d.ts +320 -0
- package/dist/vector/services/hybrid-search.d.ts.map +1 -0
- package/dist/vector/services/hybrid-search.js +3 -0
- package/dist/vector/services/hybrid-search.js.map +1 -0
- package/dist/vector/services/index.d.ts +4 -0
- package/dist/vector/services/index.d.ts.map +1 -1
- package/package.json +10 -1
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Transport Service
|
|
3
|
+
*
|
|
4
|
+
* High-level API combining QUIC Transport and Federation Hub for
|
|
5
|
+
* seamless agent communication and distributed execution.
|
|
6
|
+
*
|
|
7
|
+
* Provides:
|
|
8
|
+
* - Agent-to-agent messaging with automatic protocol selection
|
|
9
|
+
* - Distributed task execution across federation nodes
|
|
10
|
+
* - Parallel task execution with aggregation
|
|
11
|
+
* - Health monitoring and metrics
|
|
12
|
+
*
|
|
13
|
+
* @module transport/agent-transport
|
|
14
|
+
*/
|
|
15
|
+
import { QUICTransportAdapter, type LatencyStats } from '../integrations/agentic-flow/adapters/quic-transport-adapter.js';
|
|
16
|
+
import { FederationHubAdapter } from '../integrations/agentic-flow/adapters/federation-hub-adapter.js';
|
|
17
|
+
/**
|
|
18
|
+
* Transport configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface TransportConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Prefer QUIC protocol over HTTP when available
|
|
23
|
+
*/
|
|
24
|
+
preferQuic: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Fall back to HTTP if QUIC is unavailable
|
|
27
|
+
*/
|
|
28
|
+
fallbackToHttp: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Enable federation for distributed execution
|
|
31
|
+
*/
|
|
32
|
+
federationEnabled: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum retry attempts for failed operations
|
|
35
|
+
*/
|
|
36
|
+
maxRetries: number;
|
|
37
|
+
/**
|
|
38
|
+
* Timeout for send operations in milliseconds
|
|
39
|
+
*/
|
|
40
|
+
sendTimeout: number;
|
|
41
|
+
/**
|
|
42
|
+
* Timeout for distributed execution in milliseconds
|
|
43
|
+
*/
|
|
44
|
+
executionTimeout: number;
|
|
45
|
+
/**
|
|
46
|
+
* Enable automatic reconnection
|
|
47
|
+
*/
|
|
48
|
+
autoReconnect: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Interval between reconnection attempts in milliseconds
|
|
51
|
+
*/
|
|
52
|
+
reconnectInterval: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Default transport configuration
|
|
56
|
+
*/
|
|
57
|
+
export declare const defaultTransportConfig: TransportConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Transport health status
|
|
60
|
+
*/
|
|
61
|
+
export interface TransportHealth {
|
|
62
|
+
quic: boolean;
|
|
63
|
+
federation: boolean;
|
|
64
|
+
overallHealthy: boolean;
|
|
65
|
+
details: {
|
|
66
|
+
quicConnections?: number;
|
|
67
|
+
quicLatency?: number;
|
|
68
|
+
federationNodes?: number;
|
|
69
|
+
federationAgents?: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Transport metrics
|
|
74
|
+
*/
|
|
75
|
+
export interface TransportMetrics {
|
|
76
|
+
messagesSent: number;
|
|
77
|
+
messagesReceived: number;
|
|
78
|
+
bytesSent: number;
|
|
79
|
+
bytesReceived: number;
|
|
80
|
+
tasksExecuted: number;
|
|
81
|
+
tasksFailed: number;
|
|
82
|
+
averageLatencyMs: number;
|
|
83
|
+
p95LatencyMs: number;
|
|
84
|
+
errors: number;
|
|
85
|
+
reconnections: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Distributed execution options
|
|
89
|
+
*/
|
|
90
|
+
export interface DistributedExecutionOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Preferred nodes for execution
|
|
93
|
+
*/
|
|
94
|
+
preferredNodes?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* Required capabilities for the task
|
|
97
|
+
*/
|
|
98
|
+
requiredCapabilities?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Task priority
|
|
101
|
+
*/
|
|
102
|
+
priority?: 'low' | 'normal' | 'high' | 'critical';
|
|
103
|
+
/**
|
|
104
|
+
* Timeout override in milliseconds
|
|
105
|
+
*/
|
|
106
|
+
timeout?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Whether to spawn ephemeral agents
|
|
109
|
+
*/
|
|
110
|
+
spawnEphemeral?: boolean;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parallel execution result
|
|
114
|
+
*/
|
|
115
|
+
export interface ParallelExecutionResult<T = unknown> {
|
|
116
|
+
results: Array<{
|
|
117
|
+
taskId: string;
|
|
118
|
+
success: boolean;
|
|
119
|
+
result?: T;
|
|
120
|
+
error?: string;
|
|
121
|
+
nodeId?: string;
|
|
122
|
+
agentId?: string;
|
|
123
|
+
durationMs: number;
|
|
124
|
+
}>;
|
|
125
|
+
summary: {
|
|
126
|
+
total: number;
|
|
127
|
+
successful: number;
|
|
128
|
+
failed: number;
|
|
129
|
+
averageDurationMs: number;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Agent message for transport
|
|
134
|
+
*/
|
|
135
|
+
export interface AgentMessage {
|
|
136
|
+
id: string;
|
|
137
|
+
fromAgent: string;
|
|
138
|
+
toAgent?: string;
|
|
139
|
+
agentType?: string;
|
|
140
|
+
payload: unknown;
|
|
141
|
+
timestamp: number;
|
|
142
|
+
priority?: 'low' | 'normal' | 'high' | 'critical';
|
|
143
|
+
requiresResponse?: boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Agent Transport Service
|
|
147
|
+
*
|
|
148
|
+
* Unified transport layer for agent communication combining QUIC
|
|
149
|
+
* for low-latency messaging and Federation Hub for distributed
|
|
150
|
+
* task execution.
|
|
151
|
+
*/
|
|
152
|
+
export declare class AgentTransport {
|
|
153
|
+
private config;
|
|
154
|
+
private quic;
|
|
155
|
+
private federation;
|
|
156
|
+
private emitter;
|
|
157
|
+
private metrics;
|
|
158
|
+
private initialized;
|
|
159
|
+
private connections;
|
|
160
|
+
private agentEndpoints;
|
|
161
|
+
private latencies;
|
|
162
|
+
constructor(quic: QUICTransportAdapter, federation: FederationHubAdapter, config?: Partial<TransportConfig>);
|
|
163
|
+
/**
|
|
164
|
+
* Initialize the transport service
|
|
165
|
+
*/
|
|
166
|
+
initialize(): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Send a message to a specific agent
|
|
169
|
+
*
|
|
170
|
+
* @param agentId - Target agent ID
|
|
171
|
+
* @param message - Message to send
|
|
172
|
+
* @returns Response if requiresResponse is true
|
|
173
|
+
*/
|
|
174
|
+
sendToAgent(agentId: string, message: unknown): Promise<unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* Broadcast a message to all agents of a specific type
|
|
177
|
+
*
|
|
178
|
+
* @param agentType - Type of agents to broadcast to
|
|
179
|
+
* @param message - Message to broadcast
|
|
180
|
+
*/
|
|
181
|
+
broadcastToAgents(agentType: string, message: unknown): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Register an agent endpoint for direct messaging
|
|
184
|
+
*
|
|
185
|
+
* @param agentId - Agent ID
|
|
186
|
+
* @param endpoint - Agent endpoint address
|
|
187
|
+
*/
|
|
188
|
+
registerAgentEndpoint(agentId: string, endpoint: string): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Unregister an agent endpoint
|
|
191
|
+
*
|
|
192
|
+
* @param agentId - Agent ID to unregister
|
|
193
|
+
*/
|
|
194
|
+
unregisterAgentEndpoint(agentId: string): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Execute a task on the optimal node in the federation
|
|
197
|
+
*
|
|
198
|
+
* @param task - Task payload to execute
|
|
199
|
+
* @param options - Execution options
|
|
200
|
+
* @returns Execution result
|
|
201
|
+
*/
|
|
202
|
+
executeDistributed(task: unknown, options?: DistributedExecutionOptions): Promise<unknown>;
|
|
203
|
+
/**
|
|
204
|
+
* Execute multiple tasks in parallel across the federation
|
|
205
|
+
*
|
|
206
|
+
* @param tasks - Array of task payloads
|
|
207
|
+
* @param options - Execution options applied to all tasks
|
|
208
|
+
* @returns Aggregated results
|
|
209
|
+
*/
|
|
210
|
+
executeParallel<T = unknown>(tasks: unknown[], options?: DistributedExecutionOptions): Promise<ParallelExecutionResult<T>>;
|
|
211
|
+
/**
|
|
212
|
+
* Check transport health status
|
|
213
|
+
*
|
|
214
|
+
* @returns Health status for QUIC and Federation
|
|
215
|
+
*/
|
|
216
|
+
healthCheck(): Promise<TransportHealth>;
|
|
217
|
+
/**
|
|
218
|
+
* Get transport metrics
|
|
219
|
+
*
|
|
220
|
+
* @returns Combined metrics from all transport layers
|
|
221
|
+
*/
|
|
222
|
+
getMetrics(): Promise<TransportMetrics>;
|
|
223
|
+
/**
|
|
224
|
+
* Get latency statistics
|
|
225
|
+
*/
|
|
226
|
+
getLatencyStats(): Promise<LatencyStats>;
|
|
227
|
+
/**
|
|
228
|
+
* Reset transport metrics
|
|
229
|
+
*/
|
|
230
|
+
resetMetrics(): void;
|
|
231
|
+
/**
|
|
232
|
+
* Subscribe to transport events
|
|
233
|
+
*/
|
|
234
|
+
on(event: string, listener: (...args: unknown[]) => void): this;
|
|
235
|
+
/**
|
|
236
|
+
* Unsubscribe from transport events
|
|
237
|
+
*/
|
|
238
|
+
off(event: string, listener: (...args: unknown[]) => void): this;
|
|
239
|
+
/**
|
|
240
|
+
* Dispose of transport resources
|
|
241
|
+
*/
|
|
242
|
+
dispose(): Promise<void>;
|
|
243
|
+
/**
|
|
244
|
+
* Get current configuration
|
|
245
|
+
*/
|
|
246
|
+
getConfig(): TransportConfig;
|
|
247
|
+
/**
|
|
248
|
+
* Check if transport is initialized
|
|
249
|
+
*/
|
|
250
|
+
isInitialized(): boolean;
|
|
251
|
+
private ensureInitialized;
|
|
252
|
+
private shouldUseQuic;
|
|
253
|
+
private sendViaQuic;
|
|
254
|
+
private sendViaFederation;
|
|
255
|
+
private waitForTaskCompletion;
|
|
256
|
+
private createId;
|
|
257
|
+
private createInitialMetrics;
|
|
258
|
+
private recordLatency;
|
|
259
|
+
private calculateAverageLatency;
|
|
260
|
+
private calculateP95Latency;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Create a new AgentTransport instance with default adapters
|
|
264
|
+
*
|
|
265
|
+
* @param config - Transport configuration
|
|
266
|
+
* @returns Configured AgentTransport instance
|
|
267
|
+
*/
|
|
268
|
+
export declare function createAgentTransport(config?: Partial<TransportConfig>): AgentTransport;
|
|
269
|
+
//# sourceMappingURL=agent-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-transport.d.ts","sourceRoot":"","sources":["../../src/transport/agent-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EACL,oBAAoB,EAGpB,KAAK,YAAY,EAClB,MAAM,iEAAiE,CAAC;AACzE,OAAO,EACL,oBAAoB,EAIrB,MAAM,iEAAiE,CAAC;AAOzE;;GAEG;AACH,MAAM,WAAW,eAAe;I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,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAK/D;;OAEG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,IAAI;IAShE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB9B;;OAEG;IACH,SAAS,IAAI,eAAe;IAI5B;;OAEG;IACH,aAAa,IAAI,OAAO;YAQV,iBAAiB;IAM/B,OAAO,CAAC,aAAa;YAQP,WAAW;YAmCX,iBAAiB;YAejB,qBAAqB;IAyBnC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,uBAAuB;IAK/B,OAAO,CAAC,mBAAmB;CAM5B;AAMD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,cAAc,CAIhB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport Module
|
|
3
|
+
*
|
|
4
|
+
* Provides unified transport services for agent communication
|
|
5
|
+
* and distributed task execution.
|
|
6
|
+
*
|
|
7
|
+
* @module transport
|
|
8
|
+
*/
|
|
9
|
+
export { AgentTransport, createAgentTransport, type TransportConfig, type TransportHealth, type TransportMetrics, type DistributedExecutionOptions, type ParallelExecutionResult, type AgentMessage, defaultTransportConfig, } from './agent-transport.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
package/dist/vector/index.d.ts
CHANGED
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
*/
|
|
47
47
|
export { createRuVectorConfig, createHighPerformanceConfig, createLowMemoryConfig, createHybridSearchConfig, validateRuVectorConfig, getRecommendedConfig, DEFAULT_HNSW_CONFIG, DEFAULT_INDEX_CONFIG, DEFAULT_CACHE_CONFIG, DEFAULT_PERFORMANCE_CONFIG, defaultConfig, type RuVectorConfig, type VectorBackend, type ConfigValidationResult, type ValidationResult, type HNSWConfig, type PostgresBackendConfig, type CloudBackendConfig, type StandaloneBackendConfig, } from './config.js';
|
|
48
48
|
export type { DistanceMetric, IndexType, SearchSource, VectorEntry, SearchResult, HybridSearchQuery, HybridSearchResult, BatchInsertEntry, BatchInsertOperation, BatchInsertResult, VectorIndexStats, VectorSearchOptions, VectorIndexConfig, VectorStoreEvent, VectorStoreEventListener, IVectorStore, TrajectoryStep, AgentTrajectory, SonaLearningRecord, GraphNode, GraphEdge, CypherQueryResult, VectorUpdateOperation, VectorDeleteOperation, VectorDeleteResult, VectorNamespace, } from './types.js';
|
|
49
|
-
export { EnhancedVectorStore, createVectorStore, TrajectoryTracker, createTrajectoryTracker, type TrajectoryTrackerConfig, type DetectedPattern, } from './services/index.js';
|
|
49
|
+
export { EnhancedVectorStore, createVectorStore, TrajectoryTracker, createTrajectoryTracker, type TrajectoryTrackerConfig, type DetectedPattern, EmbeddingService, createEmbeddingService, getDefaultEmbeddingService, type EmbeddingConfig, type EmbeddingResult, type BatchEmbeddingResult, HybridSearch, createHybridSearch, type HybridSearchConfig, type FTSResult, type FTSProvider, type ExtendedHybridSearchResult, type HybridSearchQuery as ServiceHybridSearchQuery, type HybridSearchResponse, type SearchStats, } from './services/index.js';
|
|
50
50
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,cAAc,EACd,SAAS,EACT,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,cAAc,EACd,SAAS,EACT,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAC1B,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,0BAA0B,EAC/B,KAAK,iBAAiB,IAAI,wBAAwB,EAClD,KAAK,oBAAoB,EACzB,KAAK,WAAW,GACjB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding Service
|
|
3
|
+
*
|
|
4
|
+
* Provides text embedding generation using transformer models via @xenova/transformers.
|
|
5
|
+
* Uses the all-MiniLM-L6-v2 model (384 dimensions) by default for efficient local inference.
|
|
6
|
+
*
|
|
7
|
+
* @module vector/services/embedding-service
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for the embedding service
|
|
11
|
+
*/
|
|
12
|
+
export interface EmbeddingConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Model identifier for the embedding model
|
|
15
|
+
* @default 'Xenova/all-MiniLM-L6-v2'
|
|
16
|
+
*/
|
|
17
|
+
model: string;
|
|
18
|
+
/**
|
|
19
|
+
* Expected output dimensions for embeddings
|
|
20
|
+
* @default 384
|
|
21
|
+
*/
|
|
22
|
+
dimensions: number;
|
|
23
|
+
/**
|
|
24
|
+
* Maximum input text length in characters (not tokens)
|
|
25
|
+
* Longer texts will be truncated
|
|
26
|
+
* @default 512
|
|
27
|
+
*/
|
|
28
|
+
maxLength: number;
|
|
29
|
+
/**
|
|
30
|
+
* Number of texts to process in a single batch
|
|
31
|
+
* @default 32
|
|
32
|
+
*/
|
|
33
|
+
batchSize: number;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to normalize embeddings to unit length
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
normalize: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Pooling strategy for generating embeddings from token outputs
|
|
41
|
+
* @default 'mean'
|
|
42
|
+
*/
|
|
43
|
+
pooling: 'mean' | 'cls' | 'none';
|
|
44
|
+
/**
|
|
45
|
+
* Enable quantization for reduced memory usage
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
quantized: boolean;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Result of embedding generation
|
|
52
|
+
*/
|
|
53
|
+
export interface EmbeddingResult {
|
|
54
|
+
/**
|
|
55
|
+
* The embedding vector
|
|
56
|
+
*/
|
|
57
|
+
embedding: Float32Array;
|
|
58
|
+
/**
|
|
59
|
+
* Time taken to generate the embedding in milliseconds
|
|
60
|
+
*/
|
|
61
|
+
durationMs: number;
|
|
62
|
+
/**
|
|
63
|
+
* Number of input tokens (approximate)
|
|
64
|
+
*/
|
|
65
|
+
tokenCount?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of batch embedding generation
|
|
69
|
+
*/
|
|
70
|
+
export interface BatchEmbeddingResult {
|
|
71
|
+
/**
|
|
72
|
+
* Array of embedding vectors
|
|
73
|
+
*/
|
|
74
|
+
embeddings: Float32Array[];
|
|
75
|
+
/**
|
|
76
|
+
* Total time taken in milliseconds
|
|
77
|
+
*/
|
|
78
|
+
durationMs: number;
|
|
79
|
+
/**
|
|
80
|
+
* Number of texts successfully embedded
|
|
81
|
+
*/
|
|
82
|
+
successCount: number;
|
|
83
|
+
/**
|
|
84
|
+
* Number of texts that failed
|
|
85
|
+
*/
|
|
86
|
+
errorCount: number;
|
|
87
|
+
/**
|
|
88
|
+
* Error details for failed texts
|
|
89
|
+
*/
|
|
90
|
+
errors?: Array<{
|
|
91
|
+
index: number;
|
|
92
|
+
error: string;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Embedding Service
|
|
97
|
+
*
|
|
98
|
+
* Provides text embedding generation using transformer models.
|
|
99
|
+
* Supports single and batch operations with automatic initialization.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const service = new EmbeddingService();
|
|
104
|
+
* await service.initialize();
|
|
105
|
+
*
|
|
106
|
+
* // Single embedding
|
|
107
|
+
* const embedding = await service.embed('Hello, world!');
|
|
108
|
+
*
|
|
109
|
+
* // Batch embeddings
|
|
110
|
+
* const embeddings = await service.embedBatch([
|
|
111
|
+
* 'First document',
|
|
112
|
+
* 'Second document',
|
|
113
|
+
* 'Third document'
|
|
114
|
+
* ]);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare class EmbeddingService {
|
|
118
|
+
private pipeline;
|
|
119
|
+
private config;
|
|
120
|
+
private initPromise;
|
|
121
|
+
private isInitialized;
|
|
122
|
+
/**
|
|
123
|
+
* Create a new EmbeddingService
|
|
124
|
+
*
|
|
125
|
+
* @param config - Optional configuration overrides
|
|
126
|
+
*/
|
|
127
|
+
constructor(config?: Partial<EmbeddingConfig>);
|
|
128
|
+
/**
|
|
129
|
+
* Initialize the embedding pipeline
|
|
130
|
+
*
|
|
131
|
+
* Loads the transformer model. This is called automatically on first use
|
|
132
|
+
* but can be called explicitly to pre-load the model.
|
|
133
|
+
*
|
|
134
|
+
* @throws Error if model loading fails
|
|
135
|
+
*/
|
|
136
|
+
initialize(): Promise<void>;
|
|
137
|
+
private doInitialize;
|
|
138
|
+
/**
|
|
139
|
+
* Generate embedding for a single text
|
|
140
|
+
*
|
|
141
|
+
* @param text - Text to embed
|
|
142
|
+
* @returns Embedding result with vector and metadata
|
|
143
|
+
* @throws Error if not initialized or embedding fails
|
|
144
|
+
*/
|
|
145
|
+
embed(text: string): Promise<EmbeddingResult>;
|
|
146
|
+
/**
|
|
147
|
+
* Generate embeddings for multiple texts
|
|
148
|
+
*
|
|
149
|
+
* Processes texts in batches for efficiency.
|
|
150
|
+
*
|
|
151
|
+
* @param texts - Array of texts to embed
|
|
152
|
+
* @returns Batch result with embeddings and metadata
|
|
153
|
+
*/
|
|
154
|
+
embedBatch(texts: string[]): Promise<BatchEmbeddingResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Truncate text to maximum length
|
|
157
|
+
*
|
|
158
|
+
* @param text - Text to truncate
|
|
159
|
+
* @returns Truncated text
|
|
160
|
+
*/
|
|
161
|
+
private truncateText;
|
|
162
|
+
/**
|
|
163
|
+
* Extract embedding from pipeline output
|
|
164
|
+
*
|
|
165
|
+
* @param output - Pipeline output tensor
|
|
166
|
+
* @returns Float32Array embedding
|
|
167
|
+
*/
|
|
168
|
+
private extractEmbedding;
|
|
169
|
+
/**
|
|
170
|
+
* Extract multiple embeddings from batch output
|
|
171
|
+
*
|
|
172
|
+
* @param output - Pipeline output tensor for batch
|
|
173
|
+
* @param batchSize - Number of items in the batch
|
|
174
|
+
* @returns Array of embeddings
|
|
175
|
+
*/
|
|
176
|
+
private extractBatchEmbeddings;
|
|
177
|
+
/**
|
|
178
|
+
* Flatten nested array
|
|
179
|
+
*
|
|
180
|
+
* @param arr - Array to flatten
|
|
181
|
+
* @returns Flattened number array
|
|
182
|
+
*/
|
|
183
|
+
private flattenArray;
|
|
184
|
+
/**
|
|
185
|
+
* Get the embedding dimensions
|
|
186
|
+
*
|
|
187
|
+
* @returns Number of dimensions in generated embeddings
|
|
188
|
+
*/
|
|
189
|
+
getDimensions(): number;
|
|
190
|
+
/**
|
|
191
|
+
* Get the current configuration
|
|
192
|
+
*
|
|
193
|
+
* @returns Copy of the current configuration
|
|
194
|
+
*/
|
|
195
|
+
getConfig(): EmbeddingConfig;
|
|
196
|
+
/**
|
|
197
|
+
* Check if the service is initialized
|
|
198
|
+
*
|
|
199
|
+
* @returns True if initialized
|
|
200
|
+
*/
|
|
201
|
+
isReady(): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Get model information
|
|
204
|
+
*
|
|
205
|
+
* @returns Model details
|
|
206
|
+
*/
|
|
207
|
+
getModelInfo(): {
|
|
208
|
+
model: string;
|
|
209
|
+
dimensions: number;
|
|
210
|
+
quantized: boolean;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Create an embedding service instance
|
|
215
|
+
*
|
|
216
|
+
* Factory function for creating embedding services.
|
|
217
|
+
*
|
|
218
|
+
* @param config - Optional configuration overrides
|
|
219
|
+
* @returns New EmbeddingService instance
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Default configuration (all-MiniLM-L6-v2, 384 dimensions)
|
|
224
|
+
* const service = createEmbeddingService();
|
|
225
|
+
*
|
|
226
|
+
* // Custom configuration
|
|
227
|
+
* const customService = createEmbeddingService({
|
|
228
|
+
* model: 'Xenova/all-MiniLM-L12-v2',
|
|
229
|
+
* dimensions: 384,
|
|
230
|
+
* batchSize: 64,
|
|
231
|
+
* });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function createEmbeddingService(config?: Partial<EmbeddingConfig>): EmbeddingService;
|
|
235
|
+
/**
|
|
236
|
+
* Get the default embedding service
|
|
237
|
+
*
|
|
238
|
+
* Returns a shared singleton instance for convenience.
|
|
239
|
+
* Use createEmbeddingService() for custom configurations.
|
|
240
|
+
*
|
|
241
|
+
* @returns Default EmbeddingService instance
|
|
242
|
+
*/
|
|
243
|
+
export declare function getDefaultEmbeddingService(): EmbeddingService;
|
|
244
|
+
//# sourceMappingURL=embedding-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-service.d.ts","sourceRoot":"","sources":["../../../src/vector/services/embedding-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IAEjC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB;AAgBD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,EAAE,YAAY,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,UAAU,EAAE,YAAY,EAAE,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EA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B,0BAA0B,IAAI,gBAAgB,CAK7D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "../../node_modules/@xenova/transformers/src/tokenizers.js";
|
|
2
|
+
import "../../node_modules/@xenova/transformers/src/models.js";
|
|
3
|
+
import "fs";
|
|
4
|
+
import "path";
|
|
5
|
+
import "../../node_modules/@xenova/transformers/src/env.js";
|
|
6
|
+
import "../../node_modules/@xenova/transformers/src/utils/tensor.js";
|
|
7
|
+
import "../../node_modules/@xenova/transformers/src/utils/image.js";
|
|
8
|
+
import { createLogger } from "../../utils/logger.js";
|
|
9
|
+
createLogger("embedding-service");
|
|
10
|
+
//# sourceMappingURL=embedding-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-service.js","sources":["../../../src/vector/services/embedding-service.ts"],"sourcesContent":["/**\n * Embedding Service\n *\n * Provides text embedding generation using transformer models via @xenova/transformers.\n * Uses the all-MiniLM-L6-v2 model (384 dimensions) by default for efficient local inference.\n *\n * @module vector/services/embedding-service\n */\n\nimport { pipeline, type Pipeline, type FeatureExtractionPipeline } from '@xenova/transformers';\nimport { createLogger } from '../../utils/index.js';\n\nconst logger = createLogger('embedding-service');\n\n/**\n * Configuration for the embedding service\n */\nexport interface EmbeddingConfig {\n /**\n * Model identifier for the embedding model\n * @default 'Xenova/all-MiniLM-L6-v2'\n */\n model: string;\n\n /**\n * Expected output dimensions for embeddings\n * @default 384\n */\n dimensions: number;\n\n /**\n * Maximum input text length in characters (not tokens)\n * Longer texts will be truncated\n * @default 512\n */\n maxLength: number;\n\n /**\n * Number of texts to process in a single batch\n * @default 32\n */\n batchSize: number;\n\n /**\n * Whether to normalize embeddings to unit length\n * @default true\n */\n normalize: boolean;\n\n /**\n * Pooling strategy for generating embeddings from token outputs\n * @default 'mean'\n */\n pooling: 'mean' | 'cls' | 'none';\n\n /**\n * Enable quantization for reduced memory usage\n * @default false\n */\n quantized: boolean;\n}\n\n/**\n * Default configuration for embedding service\n * Uses all-MiniLM-L6-v2 which provides a good balance of quality and speed\n */\nconst DEFAULT_CONFIG: EmbeddingConfig = {\n model: 'Xenova/all-MiniLM-L6-v2',\n dimensions: 384,\n maxLength: 512,\n batchSize: 32,\n normalize: true,\n pooling: 'mean',\n quantized: false,\n};\n\n/**\n * Result of embedding generation\n */\nexport interface EmbeddingResult {\n /**\n * The embedding vector\n */\n embedding: Float32Array;\n\n /**\n * Time taken to generate the embedding in milliseconds\n */\n durationMs: number;\n\n /**\n * Number of input tokens (approximate)\n */\n tokenCount?: number;\n}\n\n/**\n * Result of batch embedding generation\n */\nexport interface BatchEmbeddingResult {\n /**\n * Array of embedding vectors\n */\n embeddings: Float32Array[];\n\n /**\n * Total time taken in milliseconds\n */\n durationMs: number;\n\n /**\n * Number of texts successfully embedded\n */\n successCount: number;\n\n /**\n * Number of texts that failed\n */\n errorCount: number;\n\n /**\n * Error details for failed texts\n */\n errors?: Array<{ index: number; error: string }>;\n}\n\n/**\n * Embedding Service\n *\n * Provides text embedding generation using transformer models.\n * Supports single and batch operations with automatic initialization.\n *\n * @example\n * ```typescript\n * const service = new EmbeddingService();\n * await service.initialize();\n *\n * // Single embedding\n * const embedding = await service.embed('Hello, world!');\n *\n * // Batch embeddings\n * const embeddings = await service.embedBatch([\n * 'First document',\n * 'Second document',\n * 'Third document'\n * ]);\n * ```\n */\nexport class EmbeddingService {\n private pipeline: FeatureExtractionPipeline | null = null;\n private config: EmbeddingConfig;\n private initPromise: Promise<void> | null = null;\n private isInitialized: boolean = false;\n\n /**\n * Create a new EmbeddingService\n *\n * @param config - Optional configuration overrides\n */\n constructor(config: Partial<EmbeddingConfig> = {}) {\n this.config = { ...DEFAULT_CONFIG, ...config };\n }\n\n /**\n * Initialize the embedding pipeline\n *\n * Loads the transformer model. This is called automatically on first use\n * but can be called explicitly to pre-load the model.\n *\n * @throws Error if model loading fails\n */\n async initialize(): Promise<void> {\n if (this.isInitialized) {\n return;\n }\n\n if (this.initPromise) {\n return this.initPromise;\n }\n\n this.initPromise = this.doInitialize();\n return this.initPromise;\n }\n\n private async doInitialize(): Promise<void> {\n try {\n logger.info('Loading embedding model', { model: this.config.model });\n const startTime = Date.now();\n\n // Load the feature extraction pipeline\n this.pipeline = (await pipeline(\n 'feature-extraction',\n this.config.model,\n { quantized: this.config.quantized }\n )) as FeatureExtractionPipeline;\n\n const durationMs = Date.now() - startTime;\n logger.info('Embedding model loaded', {\n model: this.config.model,\n durationMs,\n });\n\n this.isInitialized = true;\n } catch (error) {\n this.initPromise = null;\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Failed to load embedding model', new Error(message), {\n model: this.config.model,\n });\n throw new Error(`Failed to initialize embedding service: ${message}`);\n }\n }\n\n /**\n * Generate embedding for a single text\n *\n * @param text - Text to embed\n * @returns Embedding result with vector and metadata\n * @throws Error if not initialized or embedding fails\n */\n async embed(text: string): Promise<EmbeddingResult> {\n await this.initialize();\n\n if (!this.pipeline) {\n throw new Error('Embedding pipeline not initialized');\n }\n\n const startTime = Date.now();\n\n // Truncate text if too long\n const truncated = this.truncateText(text);\n\n try {\n const output = await this.pipeline(truncated, {\n pooling: this.config.pooling,\n normalize: this.config.normalize,\n });\n\n // Extract the embedding data\n const embedding = this.extractEmbedding(output);\n\n const durationMs = Date.now() - startTime;\n\n logger.debug('Generated embedding', {\n inputLength: text.length,\n truncated: text.length !== truncated.length,\n durationMs,\n });\n\n return {\n embedding,\n durationMs,\n tokenCount: Math.ceil(truncated.length / 4), // Rough estimate\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Embedding generation failed', new Error(message));\n throw new Error(`Failed to generate embedding: ${message}`);\n }\n }\n\n /**\n * Generate embeddings for multiple texts\n *\n * Processes texts in batches for efficiency.\n *\n * @param texts - Array of texts to embed\n * @returns Batch result with embeddings and metadata\n */\n async embedBatch(texts: string[]): Promise<BatchEmbeddingResult> {\n await this.initialize();\n\n if (!this.pipeline) {\n throw new Error('Embedding pipeline not initialized');\n }\n\n const startTime = Date.now();\n const results: Float32Array[] = [];\n const errors: Array<{ index: number; error: string }> = [];\n\n // Process in batches\n for (let i = 0; i < texts.length; i += this.config.batchSize) {\n const batch = texts.slice(i, i + this.config.batchSize);\n const truncatedBatch = batch.map((t) => this.truncateText(t));\n\n try {\n // Process batch\n const outputs = await this.pipeline(truncatedBatch, {\n pooling: this.config.pooling,\n normalize: this.config.normalize,\n });\n\n // Extract embeddings from batch output\n const batchEmbeddings = this.extractBatchEmbeddings(outputs, batch.length);\n results.push(...batchEmbeddings);\n } catch (error) {\n // Fall back to individual processing on batch error\n logger.warn('Batch embedding failed, falling back to individual', {\n batchIndex: i / this.config.batchSize,\n });\n\n for (let j = 0; j < batch.length; j++) {\n try {\n const output = await this.pipeline(truncatedBatch[j], {\n pooling: this.config.pooling,\n normalize: this.config.normalize,\n });\n results.push(this.extractEmbedding(output));\n } catch (individualError) {\n errors.push({\n index: i + j,\n error: individualError instanceof Error ? individualError.message : String(individualError),\n });\n // Push zero vector as placeholder\n results.push(new Float32Array(this.config.dimensions));\n }\n }\n }\n }\n\n const durationMs = Date.now() - startTime;\n\n logger.info('Batch embedding completed', {\n totalTexts: texts.length,\n successCount: texts.length - errors.length,\n errorCount: errors.length,\n durationMs,\n avgTimePerText: durationMs / texts.length,\n });\n\n return {\n embeddings: results,\n durationMs,\n successCount: texts.length - errors.length,\n errorCount: errors.length,\n errors: errors.length > 0 ? errors : undefined,\n };\n }\n\n /**\n * Truncate text to maximum length\n *\n * @param text - Text to truncate\n * @returns Truncated text\n */\n private truncateText(text: string): string {\n if (text.length <= this.config.maxLength * 4) {\n return text;\n }\n // Truncate at word boundary if possible\n const truncated = text.slice(0, this.config.maxLength * 4);\n const lastSpace = truncated.lastIndexOf(' ');\n if (lastSpace > this.config.maxLength * 2) {\n return truncated.slice(0, lastSpace);\n }\n return truncated;\n }\n\n /**\n * Extract embedding from pipeline output\n *\n * @param output - Pipeline output tensor\n * @returns Float32Array embedding\n */\n private extractEmbedding(output: unknown): Float32Array {\n // Handle different output formats from transformers.js\n if (output && typeof output === 'object') {\n const outputObj = output as Record<string, unknown>;\n\n // Check for .data property (Tensor object)\n if ('data' in outputObj && outputObj.data) {\n const data = outputObj.data;\n if (data instanceof Float32Array) {\n return data.slice(0, this.config.dimensions);\n }\n if (ArrayBuffer.isView(data)) {\n return new Float32Array(data.buffer, data.byteOffset, this.config.dimensions);\n }\n if (Array.isArray(data)) {\n return new Float32Array(data.slice(0, this.config.dimensions));\n }\n }\n\n // Check for nested array structure\n if (Array.isArray(outputObj)) {\n const flattened = this.flattenArray(outputObj);\n return new Float32Array(flattened.slice(0, this.config.dimensions));\n }\n }\n\n throw new Error('Unexpected output format from embedding pipeline');\n }\n\n /**\n * Extract multiple embeddings from batch output\n *\n * @param output - Pipeline output tensor for batch\n * @param batchSize - Number of items in the batch\n * @returns Array of embeddings\n */\n private extractBatchEmbeddings(output: unknown, batchSize: number): Float32Array[] {\n const results: Float32Array[] = [];\n\n if (output && typeof output === 'object') {\n const outputObj = output as Record<string, unknown>;\n\n if ('data' in outputObj && outputObj.data) {\n const data = outputObj.data;\n let dataArray: Float32Array;\n\n if (data instanceof Float32Array) {\n dataArray = data;\n } else if (ArrayBuffer.isView(data)) {\n dataArray = new Float32Array(data.buffer, data.byteOffset);\n } else if (Array.isArray(data)) {\n dataArray = new Float32Array(data as number[]);\n } else {\n throw new Error('Unexpected data format in batch output');\n }\n\n // Split the data array into individual embeddings\n for (let i = 0; i < batchSize; i++) {\n const start = i * this.config.dimensions;\n const embedding = dataArray.slice(start, start + this.config.dimensions);\n results.push(embedding);\n }\n\n return results;\n }\n }\n\n throw new Error('Unexpected output format from batch embedding pipeline');\n }\n\n /**\n * Flatten nested array\n *\n * @param arr - Array to flatten\n * @returns Flattened number array\n */\n private flattenArray(arr: unknown[]): number[] {\n const result: number[] = [];\n for (const item of arr) {\n if (Array.isArray(item)) {\n result.push(...this.flattenArray(item));\n } else if (typeof item === 'number') {\n result.push(item);\n }\n }\n return result;\n }\n\n /**\n * Get the embedding dimensions\n *\n * @returns Number of dimensions in generated embeddings\n */\n getDimensions(): number {\n return this.config.dimensions;\n }\n\n /**\n * Get the current configuration\n *\n * @returns Copy of the current configuration\n */\n getConfig(): EmbeddingConfig {\n return { ...this.config };\n }\n\n /**\n * Check if the service is initialized\n *\n * @returns True if initialized\n */\n isReady(): boolean {\n return this.isInitialized;\n }\n\n /**\n * Get model information\n *\n * @returns Model details\n */\n getModelInfo(): { model: string; dimensions: number; quantized: boolean } {\n return {\n model: this.config.model,\n dimensions: this.config.dimensions,\n quantized: this.config.quantized,\n };\n }\n}\n\n/**\n * Create an embedding service instance\n *\n * Factory function for creating embedding services.\n *\n * @param config - Optional configuration overrides\n * @returns New EmbeddingService instance\n *\n * @example\n * ```typescript\n * // Default configuration (all-MiniLM-L6-v2, 384 dimensions)\n * const service = createEmbeddingService();\n *\n * // Custom configuration\n * const customService = createEmbeddingService({\n * model: 'Xenova/all-MiniLM-L12-v2',\n * dimensions: 384,\n * batchSize: 64,\n * });\n * ```\n */\nexport function createEmbeddingService(config?: Partial<EmbeddingConfig>): EmbeddingService {\n return new EmbeddingService(config);\n}\n\n/**\n * Default embedding service singleton\n * Created lazily on first use\n */\nlet defaultService: EmbeddingService | null = null;\n\n/**\n * Get the default embedding service\n *\n * Returns a shared singleton instance for convenience.\n * Use createEmbeddingService() for custom configurations.\n *\n * @returns Default EmbeddingService instance\n */\nexport function getDefaultEmbeddingService(): EmbeddingService {\n if (!defaultService) {\n defaultService = new EmbeddingService();\n }\n return defaultService;\n}\n"],"names":[],"mappings":";;;;;;;;AAYe,aAAa,mBAAmB;"}
|