vesper-memory 0.5.2 → 0.5.3
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/README.md +41 -10
- package/config/claude-rules/memory-discipline.md +39 -0
- package/config/claude-rules/vesper.md +218 -0
- package/dist/cli.js +59 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -2
- package/dist/cli 2.js +0 -583
- package/dist/cli.d 2.ts +0 -8
- package/dist/cli.d.ts 2.map +0 -1
- package/dist/cli.js 2.map +0 -1
- package/dist/config 2/rate-limits.d.ts +0 -76
- package/dist/config 2/rate-limits.d.ts.map +0 -1
- package/dist/config 2/rate-limits.js +0 -161
- package/dist/config 2/rate-limits.js.map +0 -1
- package/dist/consolidation 2/pipeline.d.ts +0 -52
- package/dist/consolidation 2/pipeline.d.ts.map +0 -1
- package/dist/consolidation 2/pipeline.js +0 -193
- package/dist/consolidation 2/pipeline.js.map +0 -1
- package/dist/embeddings 2/client.d.ts +0 -94
- package/dist/embeddings 2/client.d.ts.map +0 -1
- package/dist/embeddings 2/client.js +0 -144
- package/dist/embeddings 2/client.js.map +0 -1
- package/dist/memory-layers 2/semantic-memory.d.ts +0 -33
- package/dist/memory-layers 2/semantic-memory.d.ts.map +0 -1
- package/dist/memory-layers 2/semantic-memory.js +0 -114
- package/dist/memory-layers 2/semantic-memory.js.map +0 -1
- package/dist/memory-layers 2/skill-library.d.ts +0 -25
- package/dist/memory-layers 2/skill-library.d.ts.map +0 -1
- package/dist/memory-layers 2/skill-library.js +0 -54
- package/dist/memory-layers 2/skill-library.js.map +0 -1
- package/dist/memory-layers 2/working-memory.d.ts +0 -57
- package/dist/memory-layers 2/working-memory.d.ts.map +0 -1
- package/dist/memory-layers 2/working-memory.js +0 -153
- package/dist/memory-layers 2/working-memory.js.map +0 -1
- package/dist/middleware 2/auth.d.ts +0 -287
- package/dist/middleware 2/auth.d.ts.map +0 -1
- package/dist/middleware 2/auth.js +0 -610
- package/dist/middleware 2/auth.js.map +0 -1
- package/dist/monitoring 2/health.d.ts +0 -241
- package/dist/monitoring 2/health.d.ts.map +0 -1
- package/dist/monitoring 2/health.js +0 -649
- package/dist/monitoring 2/health.js.map +0 -1
- package/dist/monitoring 2/metrics.d.ts +0 -153
- package/dist/monitoring 2/metrics.d.ts.map +0 -1
- package/dist/monitoring 2/metrics.js +0 -349
- package/dist/monitoring 2/metrics.js.map +0 -1
- package/dist/retrieval 2/hybrid-search.d.ts +0 -186
- package/dist/retrieval 2/hybrid-search.d.ts.map +0 -1
- package/dist/retrieval 2/hybrid-search.js +0 -327
- package/dist/retrieval 2/hybrid-search.js.map +0 -1
- package/dist/router 2/smart-router.d.ts +0 -111
- package/dist/router 2/smart-router.d.ts.map +0 -1
- package/dist/router 2/smart-router.js +0 -383
- package/dist/router 2/smart-router.js.map +0 -1
- package/dist/security 2/rate-limit-middleware.d.ts +0 -119
- package/dist/security 2/rate-limit-middleware.d.ts.map +0 -1
- package/dist/security 2/rate-limit-middleware.js +0 -193
- package/dist/security 2/rate-limit-middleware.js.map +0 -1
- package/dist/server 2.js +0 -861
- package/dist/server-wrapper 2.js +0 -170
- package/dist/server-wrapper.d 2.ts +0 -12
- package/dist/server-wrapper.d.ts 2.map +0 -1
- package/dist/server-wrapper.js 2.map +0 -1
- package/dist/server.d 2.ts +0 -14
- package/dist/server.d.ts 2.map +0 -1
- package/dist/server.js 2.map +0 -1
- package/dist/synthesis 2/conflict-detector.d.ts +0 -43
- package/dist/synthesis 2/conflict-detector.d.ts.map +0 -1
- package/dist/synthesis 2/conflict-detector.js +0 -125
- package/dist/synthesis 2/conflict-detector.js.map +0 -1
- package/dist/utils 2/monitoring.d.ts +0 -25
- package/dist/utils 2/monitoring.d.ts.map +0 -1
- package/dist/utils 2/monitoring.js +0 -41
- package/dist/utils 2/monitoring.js.map +0 -1
- package/dist/utils 2/rate-limiter.d.ts +0 -97
- package/dist/utils 2/rate-limiter.d.ts.map +0 -1
- package/dist/utils 2/rate-limiter.js +0 -166
- package/dist/utils 2/rate-limiter.js.map +0 -1
- package/dist/utils 2/validation.d.ts +0 -139
- package/dist/utils 2/validation.d.ts.map +0 -1
- package/dist/utils 2/validation.js +0 -195
- package/dist/utils 2/validation.js.map +0 -1
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hybrid Search Engine
|
|
3
|
-
*
|
|
4
|
-
* Implements multi-index retrieval combining dense embeddings, sparse vectors,
|
|
5
|
-
* and BM25 full-text search. Currently implements dense search with RRF fusion
|
|
6
|
-
* stubs for future sparse/BM25 integration.
|
|
7
|
-
*
|
|
8
|
-
* Retrieval Pipeline:
|
|
9
|
-
* - Dense embeddings (BGE-large, 1024-dim)
|
|
10
|
-
* - Sparse vectors (SPLADE++, coming soon)
|
|
11
|
-
* - BM25 full-text search (coming soon)
|
|
12
|
-
* - ColBERT late-interaction reranking (Phase 2)
|
|
13
|
-
* - Reciprocal Rank Fusion (k=60)
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Dense search result from vector similarity
|
|
17
|
-
*/
|
|
18
|
-
export interface DenseSearchResult {
|
|
19
|
-
id: string;
|
|
20
|
-
score: number;
|
|
21
|
-
payload?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Sparse search result from sparse embeddings
|
|
25
|
-
*/
|
|
26
|
-
export interface SparseSearchResult {
|
|
27
|
-
id: string;
|
|
28
|
-
score: number;
|
|
29
|
-
payload?: Record<string, unknown>;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* BM25 full-text search result
|
|
33
|
-
*/
|
|
34
|
-
export interface BM25SearchResult {
|
|
35
|
-
id: string;
|
|
36
|
-
score: number;
|
|
37
|
-
payload?: Record<string, unknown>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Unified search result after RRF fusion
|
|
41
|
-
*/
|
|
42
|
-
export interface HybridSearchResult {
|
|
43
|
-
id: string;
|
|
44
|
-
denseScore?: number;
|
|
45
|
-
sparseScore?: number;
|
|
46
|
-
bm25Score?: number;
|
|
47
|
-
fusedScore: number;
|
|
48
|
-
payload?: Record<string, unknown>;
|
|
49
|
-
rank: number;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Qdrant Hybrid Search Engine
|
|
53
|
-
*
|
|
54
|
-
* Manages vector operations and retrieval across multiple index types.
|
|
55
|
-
* Currently focused on dense search; sparse and BM25 stubs provided for future phases.
|
|
56
|
-
*/
|
|
57
|
-
export declare class HybridSearchEngine {
|
|
58
|
-
private client;
|
|
59
|
-
private collectionName;
|
|
60
|
-
private vectorSize;
|
|
61
|
-
/**
|
|
62
|
-
* Initialize the hybrid search engine
|
|
63
|
-
*
|
|
64
|
-
* @param qdrantUrl - Qdrant server URL (default: http://localhost:6333)
|
|
65
|
-
* @param collectionName - Name of the collection (default: memory-vectors)
|
|
66
|
-
* @param vectorSize - Dimension of dense vectors (default: 1024 for BGE-large)
|
|
67
|
-
* @param apiKey - Optional Qdrant API key for authentication
|
|
68
|
-
*/
|
|
69
|
-
constructor(qdrantUrl?: string, collectionName?: string, vectorSize?: number, apiKey?: string);
|
|
70
|
-
/**
|
|
71
|
-
* Initialize collection with proper schema
|
|
72
|
-
*
|
|
73
|
-
* Creates a collection with:
|
|
74
|
-
* - Dense vectors (1024-dim, cosine similarity)
|
|
75
|
-
* - Payload storage for metadata
|
|
76
|
-
* - Future: sparse vectors, BM25 indexes
|
|
77
|
-
*/
|
|
78
|
-
initializeCollection(): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Dense vector search using cosine similarity
|
|
81
|
-
*
|
|
82
|
-
* Performs semantic search using dense embeddings (BGE-large, 1024-dim).
|
|
83
|
-
* Returns top-k results ranked by similarity score.
|
|
84
|
-
*
|
|
85
|
-
* @param queryVector - Query embedding (1024-dim array)
|
|
86
|
-
* @param topK - Number of results to return (default: 5)
|
|
87
|
-
* @returns Array of dense search results sorted by score (highest first)
|
|
88
|
-
*/
|
|
89
|
-
denseSearch(queryVector: number[], topK?: number): Promise<DenseSearchResult[]>;
|
|
90
|
-
/**
|
|
91
|
-
* Sparse vector search using SPLADE++ (stub)
|
|
92
|
-
*
|
|
93
|
-
* TODO: Phase 2 implementation
|
|
94
|
-
* - Integrate SPLADE++ sparse embeddings
|
|
95
|
-
* - Query sparse index in Qdrant
|
|
96
|
-
* - Return top-k sparse results
|
|
97
|
-
*
|
|
98
|
-
* @param querySparseVector - Query sparse embedding
|
|
99
|
-
* @param topK - Number of results to return
|
|
100
|
-
* @returns Array of sparse search results
|
|
101
|
-
*/
|
|
102
|
-
sparseSearch(_querySparseVector: Record<number, number>, _topK?: number): Promise<SparseSearchResult[]>;
|
|
103
|
-
/**
|
|
104
|
-
* BM25 full-text search (stub)
|
|
105
|
-
*
|
|
106
|
-
* TODO: Phase 2 implementation
|
|
107
|
-
* - Integrate BM25 index (Qdrant or external)
|
|
108
|
-
* - Tokenize and search query text
|
|
109
|
-
* - Return top-k BM25 results
|
|
110
|
-
*
|
|
111
|
-
* @param queryText - Query text for full-text search
|
|
112
|
-
* @param topK - Number of results to return
|
|
113
|
-
* @returns Array of BM25 search results
|
|
114
|
-
*/
|
|
115
|
-
bm25Search(_queryText: string, _topK?: number): Promise<BM25SearchResult[]>;
|
|
116
|
-
/**
|
|
117
|
-
* Reciprocal Rank Fusion combining multiple indexes
|
|
118
|
-
*
|
|
119
|
-
* Implements RRF formula to combine rankings from dense, sparse, and BM25 indexes:
|
|
120
|
-
* RRF(d) = Σ 1 / (k + rank(d))
|
|
121
|
-
*
|
|
122
|
-
* where k is the fusion parameter (default 60) and rank is the position in each ranking.
|
|
123
|
-
*
|
|
124
|
-
* TODO: Phase 2 - Integrate with sparse/BM25 results once available
|
|
125
|
-
*
|
|
126
|
-
* @param denseResults - Results from dense search
|
|
127
|
-
* @param sparseResults - Results from sparse search
|
|
128
|
-
* @param bm25Results - Results from BM25 search
|
|
129
|
-
* @param k - RRF fusion parameter (default: 60)
|
|
130
|
-
* @returns Fused results sorted by RRF score
|
|
131
|
-
*/
|
|
132
|
-
static rrfFusion(denseResults: DenseSearchResult[], sparseResults?: SparseSearchResult[], bm25Results?: BM25SearchResult[], k?: number): HybridSearchResult[];
|
|
133
|
-
/**
|
|
134
|
-
* Hybrid search combining all available indexes
|
|
135
|
-
*
|
|
136
|
-
* Currently implements dense search only. Will be extended to include
|
|
137
|
-
* sparse vectors and BM25 once those are implemented in Phase 2.
|
|
138
|
-
*
|
|
139
|
-
* Pipeline:
|
|
140
|
-
* 1. Dense vector search (semantic search)
|
|
141
|
-
* 2. Sparse vector search (keyword-level semantics)
|
|
142
|
-
* 3. BM25 full-text search
|
|
143
|
-
* 4. Reciprocal Rank Fusion
|
|
144
|
-
*
|
|
145
|
-
* @param queryVector - Query embedding (1024-dim for BGE-large)
|
|
146
|
-
* @param topK - Number of final results to return (default: 5)
|
|
147
|
-
* @returns Array of fused results ranked by combined scores
|
|
148
|
-
*/
|
|
149
|
-
hybridSearch(queryVector: number[], topK?: number): Promise<HybridSearchResult[]>;
|
|
150
|
-
/**
|
|
151
|
-
* Add or update a memory record with embedding
|
|
152
|
-
*
|
|
153
|
-
* @param id - Unique identifier for the memory
|
|
154
|
-
* @param vector - Dense embedding (1024-dim)
|
|
155
|
-
* @param payload - Associated metadata (content, timestamp, source, etc.)
|
|
156
|
-
*/
|
|
157
|
-
upsertMemory(id: string, vector: number[], payload?: Record<string, unknown>): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Delete a memory record
|
|
160
|
-
*
|
|
161
|
-
* @param id - Unique identifier of the memory to delete
|
|
162
|
-
*/
|
|
163
|
-
deleteMemory(id: string): Promise<void>;
|
|
164
|
-
/**
|
|
165
|
-
* Get collection statistics
|
|
166
|
-
*
|
|
167
|
-
* @returns Object containing collection size, vector count, etc.
|
|
168
|
-
*/
|
|
169
|
-
getCollectionStats(): Promise<Record<string, unknown>>;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Factory function to create and initialize a hybrid search engine
|
|
173
|
-
*
|
|
174
|
-
* Usage:
|
|
175
|
-
* ```typescript
|
|
176
|
-
* const engine = await createHybridSearchEngine();
|
|
177
|
-
* const results = await engine.hybridSearch(queryVector);
|
|
178
|
-
* ```
|
|
179
|
-
*
|
|
180
|
-
* @param qdrantUrl - Qdrant server URL (default: http://localhost:6333)
|
|
181
|
-
* @param collectionName - Name of the collection (default: memory-vectors)
|
|
182
|
-
* @param vectorSize - Dimension of dense vectors (default: 1024 for BGE-large)
|
|
183
|
-
* @param apiKey - Optional Qdrant API key for authentication
|
|
184
|
-
*/
|
|
185
|
-
export declare function createHybridSearchEngine(qdrantUrl?: string, collectionName?: string, vectorSize?: number, apiKey?: string): Promise<HybridSearchEngine>;
|
|
186
|
-
//# sourceMappingURL=hybrid-search.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hybrid-search.d.ts","sourceRoot":"","sources":["../../src/retrieval/hybrid-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC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AAU,GACf,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAchC;;;;;;OAMG;IACG,YAAY,CAChB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;;OAIG;IACG,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7C;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAiB7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,wBAAwB,CAC5C,SAAS,CAAC,EAAE,MAAM,EAClB,cAAc,CAAC,EAAE,MAAM,EACvB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,kBAAkB,CAAC,CAI7B"}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hybrid Search Engine
|
|
3
|
-
*
|
|
4
|
-
* Implements multi-index retrieval combining dense embeddings, sparse vectors,
|
|
5
|
-
* and BM25 full-text search. Currently implements dense search with RRF fusion
|
|
6
|
-
* stubs for future sparse/BM25 integration.
|
|
7
|
-
*
|
|
8
|
-
* Retrieval Pipeline:
|
|
9
|
-
* - Dense embeddings (BGE-large, 1024-dim)
|
|
10
|
-
* - Sparse vectors (SPLADE++, coming soon)
|
|
11
|
-
* - BM25 full-text search (coming soon)
|
|
12
|
-
* - ColBERT late-interaction reranking (Phase 2)
|
|
13
|
-
* - Reciprocal Rank Fusion (k=60)
|
|
14
|
-
*/
|
|
15
|
-
import { QdrantClient } from "@qdrant/js-client-rest";
|
|
16
|
-
import { validateVector, sanitizeCollectionName } from "../utils/validation.js";
|
|
17
|
-
/**
|
|
18
|
-
* Qdrant Hybrid Search Engine
|
|
19
|
-
*
|
|
20
|
-
* Manages vector operations and retrieval across multiple index types.
|
|
21
|
-
* Currently focused on dense search; sparse and BM25 stubs provided for future phases.
|
|
22
|
-
*/
|
|
23
|
-
export class HybridSearchEngine {
|
|
24
|
-
client;
|
|
25
|
-
collectionName;
|
|
26
|
-
vectorSize;
|
|
27
|
-
/**
|
|
28
|
-
* Initialize the hybrid search engine
|
|
29
|
-
*
|
|
30
|
-
* @param qdrantUrl - Qdrant server URL (default: http://localhost:6333)
|
|
31
|
-
* @param collectionName - Name of the collection (default: memory-vectors)
|
|
32
|
-
* @param vectorSize - Dimension of dense vectors (default: 1024 for BGE-large)
|
|
33
|
-
* @param apiKey - Optional Qdrant API key for authentication
|
|
34
|
-
*/
|
|
35
|
-
constructor(qdrantUrl = "http://localhost:6333", collectionName = "memory-vectors", vectorSize = 1024, apiKey) {
|
|
36
|
-
// Sanitize collection name to prevent injection attacks (SEC-012)
|
|
37
|
-
this.collectionName = sanitizeCollectionName(collectionName);
|
|
38
|
-
this.vectorSize = vectorSize;
|
|
39
|
-
const clientConfig = {
|
|
40
|
-
url: qdrantUrl,
|
|
41
|
-
};
|
|
42
|
-
// Add API key if provided
|
|
43
|
-
if (apiKey) {
|
|
44
|
-
clientConfig.apiKey = apiKey;
|
|
45
|
-
}
|
|
46
|
-
this.client = new QdrantClient(clientConfig);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Initialize collection with proper schema
|
|
50
|
-
*
|
|
51
|
-
* Creates a collection with:
|
|
52
|
-
* - Dense vectors (1024-dim, cosine similarity)
|
|
53
|
-
* - Payload storage for metadata
|
|
54
|
-
* - Future: sparse vectors, BM25 indexes
|
|
55
|
-
*/
|
|
56
|
-
async initializeCollection() {
|
|
57
|
-
try {
|
|
58
|
-
// Check if collection exists
|
|
59
|
-
const collections = await this.client.getCollections();
|
|
60
|
-
const collectionExists = collections.collections.some((c) => c.name === this.collectionName);
|
|
61
|
-
if (collectionExists) {
|
|
62
|
-
console.log(`Collection '${this.collectionName}' already exists`);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
// Create new collection with dense vector index
|
|
66
|
-
await this.client.createCollection(this.collectionName, {
|
|
67
|
-
vectors: {
|
|
68
|
-
size: this.vectorSize,
|
|
69
|
-
distance: "Cosine",
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
console.log(`Created collection '${this.collectionName}' with ${this.vectorSize}-dim vectors`);
|
|
73
|
-
// TODO: Phase 2 - Add sparse vector index
|
|
74
|
-
// TODO: Phase 2 - Add BM25 index
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.error("Failed to initialize collection:", error instanceof Error ? error.message : error);
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Dense vector search using cosine similarity
|
|
83
|
-
*
|
|
84
|
-
* Performs semantic search using dense embeddings (BGE-large, 1024-dim).
|
|
85
|
-
* Returns top-k results ranked by similarity score.
|
|
86
|
-
*
|
|
87
|
-
* @param queryVector - Query embedding (1024-dim array)
|
|
88
|
-
* @param topK - Number of results to return (default: 5)
|
|
89
|
-
* @returns Array of dense search results sorted by score (highest first)
|
|
90
|
-
*/
|
|
91
|
-
async denseSearch(queryVector, topK = 5) {
|
|
92
|
-
// Validate vector dimensions and values (SEC-005)
|
|
93
|
-
validateVector(queryVector, this.vectorSize);
|
|
94
|
-
try {
|
|
95
|
-
const searchResults = await this.client.search(this.collectionName, {
|
|
96
|
-
vector: queryVector,
|
|
97
|
-
limit: topK,
|
|
98
|
-
with_payload: true,
|
|
99
|
-
with_vector: false,
|
|
100
|
-
});
|
|
101
|
-
return searchResults.map((result) => ({
|
|
102
|
-
id: String(result.id),
|
|
103
|
-
score: result.score,
|
|
104
|
-
payload: result.payload ?? undefined,
|
|
105
|
-
}));
|
|
106
|
-
}
|
|
107
|
-
catch (error) {
|
|
108
|
-
console.error("Dense search failed:", error instanceof Error ? error.message : error);
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Sparse vector search using SPLADE++ (stub)
|
|
114
|
-
*
|
|
115
|
-
* TODO: Phase 2 implementation
|
|
116
|
-
* - Integrate SPLADE++ sparse embeddings
|
|
117
|
-
* - Query sparse index in Qdrant
|
|
118
|
-
* - Return top-k sparse results
|
|
119
|
-
*
|
|
120
|
-
* @param querySparseVector - Query sparse embedding
|
|
121
|
-
* @param topK - Number of results to return
|
|
122
|
-
* @returns Array of sparse search results
|
|
123
|
-
*/
|
|
124
|
-
async sparseSearch(_querySparseVector, _topK = 5) {
|
|
125
|
-
console.warn("sparseSearch: Not yet implemented (Phase 2)");
|
|
126
|
-
return [];
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* BM25 full-text search (stub)
|
|
130
|
-
*
|
|
131
|
-
* TODO: Phase 2 implementation
|
|
132
|
-
* - Integrate BM25 index (Qdrant or external)
|
|
133
|
-
* - Tokenize and search query text
|
|
134
|
-
* - Return top-k BM25 results
|
|
135
|
-
*
|
|
136
|
-
* @param queryText - Query text for full-text search
|
|
137
|
-
* @param topK - Number of results to return
|
|
138
|
-
* @returns Array of BM25 search results
|
|
139
|
-
*/
|
|
140
|
-
async bm25Search(_queryText, _topK = 5) {
|
|
141
|
-
console.warn("bm25Search: Not yet implemented (Phase 2)");
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Reciprocal Rank Fusion combining multiple indexes
|
|
146
|
-
*
|
|
147
|
-
* Implements RRF formula to combine rankings from dense, sparse, and BM25 indexes:
|
|
148
|
-
* RRF(d) = Σ 1 / (k + rank(d))
|
|
149
|
-
*
|
|
150
|
-
* where k is the fusion parameter (default 60) and rank is the position in each ranking.
|
|
151
|
-
*
|
|
152
|
-
* TODO: Phase 2 - Integrate with sparse/BM25 results once available
|
|
153
|
-
*
|
|
154
|
-
* @param denseResults - Results from dense search
|
|
155
|
-
* @param sparseResults - Results from sparse search
|
|
156
|
-
* @param bm25Results - Results from BM25 search
|
|
157
|
-
* @param k - RRF fusion parameter (default: 60)
|
|
158
|
-
* @returns Fused results sorted by RRF score
|
|
159
|
-
*/
|
|
160
|
-
static rrfFusion(denseResults, sparseResults = [], bm25Results = [], k = 60) {
|
|
161
|
-
// Create a map to accumulate scores
|
|
162
|
-
const resultMap = new Map();
|
|
163
|
-
// Process dense results
|
|
164
|
-
denseResults.forEach((result, index) => {
|
|
165
|
-
const rrfScore = 1 / (k + index + 1);
|
|
166
|
-
resultMap.set(result.id, {
|
|
167
|
-
id: result.id,
|
|
168
|
-
denseScore: result.score,
|
|
169
|
-
fusedScore: rrfScore,
|
|
170
|
-
payload: result.payload,
|
|
171
|
-
rank: 0, // Will be set after final sort
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
// Process sparse results
|
|
175
|
-
sparseResults.forEach((result, index) => {
|
|
176
|
-
const rrfScore = 1 / (k + index + 1);
|
|
177
|
-
const existing = resultMap.get(result.id);
|
|
178
|
-
if (existing) {
|
|
179
|
-
existing.sparseScore = result.score;
|
|
180
|
-
existing.fusedScore += rrfScore;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
resultMap.set(result.id, {
|
|
184
|
-
id: result.id,
|
|
185
|
-
sparseScore: result.score,
|
|
186
|
-
fusedScore: rrfScore,
|
|
187
|
-
payload: result.payload,
|
|
188
|
-
rank: 0,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
// Process BM25 results
|
|
193
|
-
bm25Results.forEach((result, index) => {
|
|
194
|
-
const rrfScore = 1 / (k + index + 1);
|
|
195
|
-
const existing = resultMap.get(result.id);
|
|
196
|
-
if (existing) {
|
|
197
|
-
existing.bm25Score = result.score;
|
|
198
|
-
existing.fusedScore += rrfScore;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
resultMap.set(result.id, {
|
|
202
|
-
id: result.id,
|
|
203
|
-
bm25Score: result.score,
|
|
204
|
-
fusedScore: rrfScore,
|
|
205
|
-
payload: result.payload,
|
|
206
|
-
rank: 0,
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
// Sort by fused score and assign ranks
|
|
211
|
-
const fused = Array.from(resultMap.values())
|
|
212
|
-
.sort((a, b) => b.fusedScore - a.fusedScore)
|
|
213
|
-
.map((result, index) => {
|
|
214
|
-
result.rank = index + 1;
|
|
215
|
-
return result;
|
|
216
|
-
});
|
|
217
|
-
return fused;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Hybrid search combining all available indexes
|
|
221
|
-
*
|
|
222
|
-
* Currently implements dense search only. Will be extended to include
|
|
223
|
-
* sparse vectors and BM25 once those are implemented in Phase 2.
|
|
224
|
-
*
|
|
225
|
-
* Pipeline:
|
|
226
|
-
* 1. Dense vector search (semantic search)
|
|
227
|
-
* 2. Sparse vector search (keyword-level semantics)
|
|
228
|
-
* 3. BM25 full-text search
|
|
229
|
-
* 4. Reciprocal Rank Fusion
|
|
230
|
-
*
|
|
231
|
-
* @param queryVector - Query embedding (1024-dim for BGE-large)
|
|
232
|
-
* @param topK - Number of final results to return (default: 5)
|
|
233
|
-
* @returns Array of fused results ranked by combined scores
|
|
234
|
-
*/
|
|
235
|
-
async hybridSearch(queryVector, topK = 5) {
|
|
236
|
-
// Phase 1: Dense search only
|
|
237
|
-
const denseResults = await this.denseSearch(queryVector, topK);
|
|
238
|
-
// Phase 2: Will add sparse and BM25
|
|
239
|
-
// const sparseResults = await this.sparseSearch(querySparseVector, topK);
|
|
240
|
-
// const bm25Results = await this.bm25Search(queryText, topK);
|
|
241
|
-
// Combine results with RRF
|
|
242
|
-
const fused = HybridSearchEngine.rrfFusion(denseResults);
|
|
243
|
-
return fused.slice(0, topK);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Add or update a memory record with embedding
|
|
247
|
-
*
|
|
248
|
-
* @param id - Unique identifier for the memory
|
|
249
|
-
* @param vector - Dense embedding (1024-dim)
|
|
250
|
-
* @param payload - Associated metadata (content, timestamp, source, etc.)
|
|
251
|
-
*/
|
|
252
|
-
async upsertMemory(id, vector, payload) {
|
|
253
|
-
// Validate vector dimensions and values (SEC-005)
|
|
254
|
-
validateVector(vector, this.vectorSize);
|
|
255
|
-
try {
|
|
256
|
-
await this.client.upsert(this.collectionName, {
|
|
257
|
-
points: [
|
|
258
|
-
{
|
|
259
|
-
id: id,
|
|
260
|
-
vector: vector,
|
|
261
|
-
payload: payload || {},
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
catch (error) {
|
|
267
|
-
console.error("Failed to upsert memory:", error instanceof Error ? error.message : error);
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Delete a memory record
|
|
273
|
-
*
|
|
274
|
-
* @param id - Unique identifier of the memory to delete
|
|
275
|
-
*/
|
|
276
|
-
async deleteMemory(id) {
|
|
277
|
-
try {
|
|
278
|
-
await this.client.delete(this.collectionName, {
|
|
279
|
-
points: [id],
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
console.error("Failed to delete memory:", error instanceof Error ? error.message : error);
|
|
284
|
-
throw error;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Get collection statistics
|
|
289
|
-
*
|
|
290
|
-
* @returns Object containing collection size, vector count, etc.
|
|
291
|
-
*/
|
|
292
|
-
async getCollectionStats() {
|
|
293
|
-
try {
|
|
294
|
-
const info = await this.client.getCollection(this.collectionName);
|
|
295
|
-
return {
|
|
296
|
-
pointsCount: info.points_count,
|
|
297
|
-
indexedVectorsCount: info.indexed_vectors_count,
|
|
298
|
-
segmentsCount: info.segments_count,
|
|
299
|
-
status: info.status,
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
catch (error) {
|
|
303
|
-
console.error("Failed to get collection stats:", error instanceof Error ? error.message : error);
|
|
304
|
-
throw error;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Factory function to create and initialize a hybrid search engine
|
|
310
|
-
*
|
|
311
|
-
* Usage:
|
|
312
|
-
* ```typescript
|
|
313
|
-
* const engine = await createHybridSearchEngine();
|
|
314
|
-
* const results = await engine.hybridSearch(queryVector);
|
|
315
|
-
* ```
|
|
316
|
-
*
|
|
317
|
-
* @param qdrantUrl - Qdrant server URL (default: http://localhost:6333)
|
|
318
|
-
* @param collectionName - Name of the collection (default: memory-vectors)
|
|
319
|
-
* @param vectorSize - Dimension of dense vectors (default: 1024 for BGE-large)
|
|
320
|
-
* @param apiKey - Optional Qdrant API key for authentication
|
|
321
|
-
*/
|
|
322
|
-
export async function createHybridSearchEngine(qdrantUrl, collectionName, vectorSize, apiKey) {
|
|
323
|
-
const engine = new HybridSearchEngine(qdrantUrl, collectionName, vectorSize, apiKey);
|
|
324
|
-
await engine.initializeCollection();
|
|
325
|
-
return engine;
|
|
326
|
-
}
|
|
327
|
-
//# sourceMappingURL=hybrid-search.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hybrid-search.js","sourceRoot":"","sources":["../../src/retrieval/hybrid-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAmDhF;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAe;IACrB,cAAc,CAAS;IACvB,UAAU,CAAS;IAE3B;;;;;;;OAOG;IACH,YACE,YAAoB,uBAAuB,EAC3C,iBAAyB,gBAAgB,EACzC,aAAqB,IAAI,EACzB,MAAe;QAEf,kEAAkE;QAClE,IAAI,CAAC,cAAc,GAAG,sBAAsB,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,CAAC,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C;IACH,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB;QACtB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAClE,OAAO;gBACL,WAAW,EAAE,IAAI,CAAC,YAAY;gBAC9B,mBAAmB,EAAE,IAAI,CAAC,qBAAqB;gBAC/C,aAAa,EAAE,IAAI,CAAC,cAAc;gBAClC,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,iCAAiC,EACjC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAC/C,CAAC;YACF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,SAAkB,EAClB,cAAuB,EACvB,UAAmB,EACnB,MAAe;IAEf,MAAM,MAAM,GAAG,IAAI,kBAAkB,CAAC,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IACrF,MAAM,MAAM,CAAC,oBAAoB,EAAE,CAAC;IACpC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Smart Query Router
|
|
3
|
-
*
|
|
4
|
-
* Implements intelligent routing logic from v3.0 plan:
|
|
5
|
-
* 1. Always check working memory first (fast path)
|
|
6
|
-
* 2. Classify query type using regex patterns
|
|
7
|
-
* 3. Route to appropriate handler based on classification
|
|
8
|
-
* 4. Fall back to hybrid search for complex queries
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Query type enumeration
|
|
12
|
-
* Used to classify queries and route to appropriate handlers
|
|
13
|
-
*/
|
|
14
|
-
export declare enum QueryType {
|
|
15
|
-
FACTUAL = "factual",
|
|
16
|
-
PREFERENCE = "preference",
|
|
17
|
-
PROJECT = "project",
|
|
18
|
-
TEMPORAL = "temporal",
|
|
19
|
-
SKILL = "skill",
|
|
20
|
-
COMPLEX = "complex"
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Query classification result
|
|
24
|
-
*/
|
|
25
|
-
export interface ClassificationResult {
|
|
26
|
-
type: QueryType;
|
|
27
|
-
confidence: number;
|
|
28
|
-
matchedPattern?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Context for routing decisions
|
|
32
|
-
*/
|
|
33
|
-
export interface RoutingContext {
|
|
34
|
-
userId: string;
|
|
35
|
-
conversationId: string;
|
|
36
|
-
timestamp: Date;
|
|
37
|
-
metadata?: Record<string, unknown>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Memory result from any layer
|
|
41
|
-
*/
|
|
42
|
-
export interface MemoryResult {
|
|
43
|
-
id: string;
|
|
44
|
-
source: "working" | "semantic" | "procedural" | "hybrid";
|
|
45
|
-
content: string;
|
|
46
|
-
similarity: number;
|
|
47
|
-
timestamp: Date;
|
|
48
|
-
confidence?: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Classify a query into one of the six query types
|
|
52
|
-
*
|
|
53
|
-
* Uses simple regex patterns to identify query intent without LLM calls.
|
|
54
|
-
* Falls back to 'complex' for ambiguous queries.
|
|
55
|
-
*
|
|
56
|
-
* Patterns (in order of specificity):
|
|
57
|
-
* - skill: "like before", "same as", "same way", "how you", "analyze"
|
|
58
|
-
* - factual: "what is", "who is", "where is"
|
|
59
|
-
* - temporal: "last week", "yesterday", "recently", etc.
|
|
60
|
-
* - preference: "prefer", "want", "style", "favorite"
|
|
61
|
-
* - project: "project", "working on", "decided", "building", "creating", "developing"
|
|
62
|
-
* - complex: fallback for anything else
|
|
63
|
-
*/
|
|
64
|
-
export declare function classifyQuery(query: string): ClassificationResult;
|
|
65
|
-
/**
|
|
66
|
-
* Smart query router following v3.0 plan retrieval strategy
|
|
67
|
-
*
|
|
68
|
-
* Routing decision tree:
|
|
69
|
-
* 1. Check working memory first (5ms, high confidence threshold)
|
|
70
|
-
* 2. Classify query type with regex
|
|
71
|
-
* 3. Route to appropriate handler:
|
|
72
|
-
* - factual: direct entity lookup
|
|
73
|
-
* - preference: preference retrieval
|
|
74
|
-
* - project: graph traversal with HippoRAG
|
|
75
|
-
* - temporal: time-based filtering
|
|
76
|
-
* - skill: skill library search
|
|
77
|
-
* - complex: hybrid search (dense + sparse + BM25)
|
|
78
|
-
*
|
|
79
|
-
* @param query - The user's query string
|
|
80
|
-
* @param context - Routing context (user, conversation, etc.)
|
|
81
|
-
* @returns Promise resolving to array of memory results
|
|
82
|
-
*
|
|
83
|
-
* @throws Error if query is empty or context is invalid
|
|
84
|
-
*/
|
|
85
|
-
export declare function retrieve(query: string, context: RoutingContext): Promise<MemoryResult[]>;
|
|
86
|
-
/**
|
|
87
|
-
* Extract entity name from a query
|
|
88
|
-
*
|
|
89
|
-
* Implementation stub for entity extraction
|
|
90
|
-
* Will later integrate with NER or simple heuristics
|
|
91
|
-
*/
|
|
92
|
-
export declare function extractEntityName(query: string): string | null;
|
|
93
|
-
/**
|
|
94
|
-
* Extract domain/category from a query
|
|
95
|
-
*
|
|
96
|
-
* Implementation stub for domain extraction
|
|
97
|
-
* Used for preference and skill queries
|
|
98
|
-
*/
|
|
99
|
-
export declare function extractDomain(query: string): string | null;
|
|
100
|
-
/**
|
|
101
|
-
* Parse temporal references from query
|
|
102
|
-
*
|
|
103
|
-
* Implementation stub for temporal parsing
|
|
104
|
-
* Will extract time ranges like "last week", "yesterday", etc.
|
|
105
|
-
*/
|
|
106
|
-
export interface TimeRange {
|
|
107
|
-
startDate: Date;
|
|
108
|
-
endDate: Date;
|
|
109
|
-
}
|
|
110
|
-
export declare function parseTimeRange(query: string): TimeRange | null;
|
|
111
|
-
//# sourceMappingURL=smart-router.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"smart-router.d.ts","sourceRoot":"","sources":["../../src/router/smart-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;GAGG;AACH,oBAAY,SAAS;IACnB,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,SAAS,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CA0FjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC,CAyDzB;AAmND;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI9D;AAED;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