@danielsimonjr/memory-mcp 0.47.1 → 9.8.0
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 +22 -0
- package/README.md +2000 -194
- package/dist/__tests__/file-path.test.js +5 -5
- package/dist/__tests__/knowledge-graph.test.js +3 -8
- package/dist/core/EntityManager.d.ts +266 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +85 -133
- package/dist/core/GraphEventEmitter.d.ts +202 -0
- package/dist/core/GraphEventEmitter.d.ts.map +1 -0
- package/dist/core/GraphEventEmitter.js +346 -0
- package/dist/core/GraphStorage.d.ts +395 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +643 -31
- package/dist/core/GraphTraversal.d.ts +141 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +573 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/{features → core}/HierarchyManager.js +14 -9
- package/dist/core/ManagerContext.d.ts +72 -0
- package/dist/core/ManagerContext.d.ts.map +1 -0
- package/dist/core/ManagerContext.js +118 -0
- package/dist/core/ObservationManager.d.ts +85 -0
- package/dist/core/ObservationManager.d.ts.map +1 -0
- package/dist/core/ObservationManager.js +51 -57
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +31 -7
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +917 -0
- package/dist/core/StorageFactory.d.ts +45 -0
- package/dist/core/StorageFactory.d.ts.map +1 -0
- package/dist/core/StorageFactory.js +64 -0
- package/dist/core/TransactionManager.d.ts +464 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +490 -13
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -2
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +14 -13
- package/dist/features/ArchiveManager.d.ts +133 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +221 -14
- package/dist/features/CompressionManager.d.ts +117 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +189 -20
- package/dist/features/IOManager.d.ts +225 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +1041 -0
- package/dist/features/StreamingExporter.d.ts +123 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +203 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +5 -6
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -45
- package/dist/memory.jsonl +1 -18
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +9 -3
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +156 -9
- package/dist/search/EmbeddingService.d.ts +178 -0
- package/dist/search/EmbeddingService.d.ts.map +1 -0
- package/dist/search/EmbeddingService.js +358 -0
- package/dist/search/FuzzySearch.d.ts +118 -0
- package/dist/search/FuzzySearch.d.ts.map +1 -0
- package/dist/search/FuzzySearch.js +241 -25
- package/dist/search/QueryCostEstimator.d.ts +111 -0
- package/dist/search/QueryCostEstimator.d.ts.map +1 -0
- package/dist/search/QueryCostEstimator.js +355 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +54 -6
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +2 -4
- package/dist/search/SearchManager.d.ts +326 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +148 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +1 -1
- package/dist/search/SemanticSearch.d.ts +149 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +323 -0
- package/dist/search/TFIDFEventSync.d.ts +85 -0
- package/dist/search/TFIDFEventSync.d.ts.map +1 -0
- package/dist/search/TFIDFEventSync.js +133 -0
- package/dist/search/TFIDFIndexManager.d.ts +151 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +232 -17
- package/dist/search/VectorStore.d.ts +235 -0
- package/dist/search/VectorStore.d.ts.map +1 -0
- package/dist/search/VectorStore.js +311 -0
- package/dist/search/index.d.ts +21 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +12 -0
- package/dist/server/MCPServer.d.ts +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +4 -4
- package/dist/server/responseCompressor.d.ts +94 -0
- package/dist/server/responseCompressor.d.ts.map +1 -0
- package/dist/server/responseCompressor.js +127 -0
- package/dist/server/toolDefinitions.d.ts +27 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -0
- package/dist/server/toolDefinitions.js +189 -18
- package/dist/server/toolHandlers.d.ts +41 -0
- package/dist/server/toolHandlers.d.ts.map +1 -0
- package/dist/server/toolHandlers.js +467 -75
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/types.d.ts +1654 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +9 -0
- package/dist/utils/compressedCache.d.ts +192 -0
- package/dist/utils/compressedCache.d.ts.map +1 -0
- package/dist/utils/compressedCache.js +309 -0
- package/dist/utils/compressionUtil.d.ts +214 -0
- package/dist/utils/compressionUtil.d.ts.map +1 -0
- package/dist/utils/compressionUtil.js +247 -0
- package/dist/utils/constants.d.ts +245 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +124 -0
- package/dist/utils/entityUtils.d.ts +321 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +434 -4
- package/dist/utils/errors.d.ts +95 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +24 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +69 -31
- package/dist/utils/indexes.d.ts +270 -0
- package/dist/utils/indexes.d.ts.map +1 -0
- package/dist/utils/indexes.js +526 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/operationUtils.d.ts +124 -0
- package/dist/utils/operationUtils.d.ts.map +1 -0
- package/dist/utils/operationUtils.js +175 -0
- package/dist/utils/parallelUtils.d.ts +72 -0
- package/dist/utils/parallelUtils.d.ts.map +1 -0
- package/dist/utils/parallelUtils.js +169 -0
- package/dist/utils/schemas.d.ts +374 -0
- package/dist/utils/schemas.d.ts.map +1 -0
- package/dist/utils/schemas.js +302 -2
- package/dist/utils/searchAlgorithms.d.ts +99 -0
- package/dist/utils/searchAlgorithms.d.ts.map +1 -0
- package/dist/utils/searchAlgorithms.js +167 -0
- package/dist/utils/searchCache.d.ts +108 -0
- package/dist/utils/searchCache.d.ts.map +1 -0
- package/dist/utils/taskScheduler.d.ts +290 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +466 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +9 -0
- package/dist/workers/levenshteinWorker.d.ts +60 -0
- package/dist/workers/levenshteinWorker.d.ts.map +1 -0
- package/dist/workers/levenshteinWorker.js +98 -0
- package/package.json +17 -4
- package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
- package/dist/__tests__/integration/workflows.test.js +0 -449
- package/dist/__tests__/performance/benchmarks.test.js +0 -413
- package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
- package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
- package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
- package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
- package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
- package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
- package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
- package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
- package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
- package/dist/core/KnowledgeGraphManager.js +0 -423
- package/dist/features/BackupManager.js +0 -311
- package/dist/features/ExportManager.js +0 -305
- package/dist/features/ImportExportManager.js +0 -50
- package/dist/features/ImportManager.js +0 -328
- package/dist/types/analytics.types.js +0 -6
- package/dist/types/entity.types.js +0 -7
- package/dist/types/import-export.types.js +0 -7
- package/dist/types/search.types.js +0 -7
- package/dist/types/tag.types.js +0 -6
- package/dist/utils/dateUtils.js +0 -89
- package/dist/utils/filterUtils.js +0 -155
- package/dist/utils/levenshtein.js +0 -62
- package/dist/utils/pathUtils.js +0 -115
- package/dist/utils/responseFormatter.js +0 -55
- package/dist/utils/tagUtils.js +0 -107
- package/dist/utils/tfidf.js +0 -90
- package/dist/utils/validationHelper.js +0 -99
- package/dist/utils/validationUtils.js +0 -109
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Filter Chain
|
|
3
|
+
*
|
|
4
|
+
* Centralizes filter logic for all search implementations to eliminate
|
|
5
|
+
* duplicate filtering code across BasicSearch, BooleanSearch, FuzzySearch,
|
|
6
|
+
* and RankedSearch.
|
|
7
|
+
*
|
|
8
|
+
* @module search/SearchFilterChain
|
|
9
|
+
*/
|
|
10
|
+
import type { Entity } from '../types/index.js';
|
|
11
|
+
import { type ValidatedPagination } from '../utils/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Search filter configuration options.
|
|
14
|
+
* All filters are optional - entities pass if filter is not specified.
|
|
15
|
+
*/
|
|
16
|
+
export interface SearchFilters {
|
|
17
|
+
/** Tags to filter by (any match) */
|
|
18
|
+
tags?: string[];
|
|
19
|
+
/** Minimum importance (0-10, inclusive) */
|
|
20
|
+
minImportance?: number;
|
|
21
|
+
/** Maximum importance (0-10, inclusive) */
|
|
22
|
+
maxImportance?: number;
|
|
23
|
+
/** Entity type to filter by (exact match) */
|
|
24
|
+
entityType?: string;
|
|
25
|
+
/** Created after date (ISO 8601, inclusive) */
|
|
26
|
+
createdAfter?: string;
|
|
27
|
+
/** Created before date (ISO 8601, inclusive) */
|
|
28
|
+
createdBefore?: string;
|
|
29
|
+
/** Modified after date (ISO 8601, inclusive) */
|
|
30
|
+
modifiedAfter?: string;
|
|
31
|
+
/** Modified before date (ISO 8601, inclusive) */
|
|
32
|
+
modifiedBefore?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Centralized filter chain for all search implementations.
|
|
36
|
+
* Ensures consistent filtering behavior across search types.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const filters: SearchFilters = { tags: ['important'], minImportance: 5 };
|
|
41
|
+
* const filtered = SearchFilterChain.applyFilters(entities, filters);
|
|
42
|
+
* const pagination = SearchFilterChain.validatePagination(0, 50);
|
|
43
|
+
* const result = SearchFilterChain.paginate(filtered, pagination);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare class SearchFilterChain {
|
|
47
|
+
/**
|
|
48
|
+
* Applies all filters to an array of entities.
|
|
49
|
+
* Entities must pass ALL specified filters to be included.
|
|
50
|
+
*
|
|
51
|
+
* @param entities - Entities to filter
|
|
52
|
+
* @param filters - Filter criteria to apply
|
|
53
|
+
* @returns Filtered entities array
|
|
54
|
+
*/
|
|
55
|
+
static applyFilters(entities: readonly Entity[], filters: SearchFilters): Entity[];
|
|
56
|
+
/**
|
|
57
|
+
* Checks if an entity passes all active filters.
|
|
58
|
+
* Short-circuits on first failing filter for performance.
|
|
59
|
+
*
|
|
60
|
+
* @param entity - Entity to check
|
|
61
|
+
* @param filters - Filter criteria
|
|
62
|
+
* @param normalizedSearchTags - Pre-normalized search tags (for efficiency)
|
|
63
|
+
* @returns true if entity passes all filters
|
|
64
|
+
*/
|
|
65
|
+
static entityPassesFilters(entity: Entity, filters: SearchFilters, normalizedSearchTags?: string[]): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if any filters are actually specified.
|
|
68
|
+
* Used for early return optimization.
|
|
69
|
+
*
|
|
70
|
+
* @param filters - Filter criteria to check
|
|
71
|
+
* @returns true if at least one filter is active
|
|
72
|
+
*/
|
|
73
|
+
static hasActiveFilters(filters: SearchFilters): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Validates and returns pagination parameters.
|
|
76
|
+
* Delegates to paginationUtils.validatePagination.
|
|
77
|
+
*
|
|
78
|
+
* @param offset - Starting position
|
|
79
|
+
* @param limit - Maximum results
|
|
80
|
+
* @returns Validated pagination object
|
|
81
|
+
*/
|
|
82
|
+
static validatePagination(offset?: number, limit?: number): ValidatedPagination;
|
|
83
|
+
/**
|
|
84
|
+
* Applies pagination to a filtered result set.
|
|
85
|
+
*
|
|
86
|
+
* @param entities - Entities to paginate
|
|
87
|
+
* @param pagination - Validated pagination parameters
|
|
88
|
+
* @returns Paginated slice of entities
|
|
89
|
+
*/
|
|
90
|
+
static paginate(entities: Entity[], pagination: ValidatedPagination): Entity[];
|
|
91
|
+
/**
|
|
92
|
+
* Convenience method to apply both filters and pagination in one call.
|
|
93
|
+
*
|
|
94
|
+
* @param entities - Entities to process
|
|
95
|
+
* @param filters - Filter criteria
|
|
96
|
+
* @param offset - Pagination offset
|
|
97
|
+
* @param limit - Pagination limit
|
|
98
|
+
* @returns Filtered and paginated entities
|
|
99
|
+
*/
|
|
100
|
+
static filterAndPaginate(entities: Entity[], filters: SearchFilters, offset?: number, limit?: number): Entity[];
|
|
101
|
+
/**
|
|
102
|
+
* Applies tag filter only. Useful when other filters are handled separately.
|
|
103
|
+
*
|
|
104
|
+
* @param entities - Entities to filter
|
|
105
|
+
* @param tags - Tags to filter by
|
|
106
|
+
* @returns Filtered entities
|
|
107
|
+
*/
|
|
108
|
+
static filterByTags(entities: Entity[], tags?: string[]): Entity[];
|
|
109
|
+
/**
|
|
110
|
+
* Applies importance filter only. Useful when other filters are handled separately.
|
|
111
|
+
*
|
|
112
|
+
* @param entities - Entities to filter
|
|
113
|
+
* @param minImportance - Minimum importance
|
|
114
|
+
* @param maxImportance - Maximum importance
|
|
115
|
+
* @returns Filtered entities
|
|
116
|
+
*/
|
|
117
|
+
static filterByImportance(entities: Entity[], minImportance?: number, maxImportance?: number): Entity[];
|
|
118
|
+
}
|
|
119
|
+
export type { ValidatedPagination };
|
|
120
|
+
//# sourceMappingURL=SearchFilterChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchFilterChain.d.ts","sourceRoot":"","sources":["../../src/search/SearchFilterChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAML,KAAK,mBAAmB,EACzB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAA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AAE;IAMX;;;;;;OAMG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAclE;;;;;;;OAOG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAQ,EAAE,MAAM,EAAE,EAClB,aAAa,CAAC,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM,EAAE;CASZ;AAGD,YAAY,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -7,9 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module search/SearchFilterChain
|
|
9
9
|
*/
|
|
10
|
-
import { normalizeTags, hasMatchingTag } from '../utils/
|
|
11
|
-
import { isWithinImportanceRange } from '../utils/filterUtils.js';
|
|
12
|
-
import { validatePagination, applyPagination } from '../utils/paginationUtils.js';
|
|
10
|
+
import { normalizeTags, hasMatchingTag, isWithinImportanceRange, validatePagination, applyPagination, } from '../utils/index.js';
|
|
13
11
|
/**
|
|
14
12
|
* Centralized filter chain for all search implementations.
|
|
15
13
|
* Ensures consistent filtering behavior across search types.
|
|
@@ -34,7 +32,7 @@ export class SearchFilterChain {
|
|
|
34
32
|
static applyFilters(entities, filters) {
|
|
35
33
|
// Early return if no filters are active
|
|
36
34
|
if (!this.hasActiveFilters(filters)) {
|
|
37
|
-
return entities;
|
|
35
|
+
return [...entities];
|
|
38
36
|
}
|
|
39
37
|
// Pre-normalize tags once for efficiency
|
|
40
38
|
const normalizedSearchTags = filters.tags?.length
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Manager
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates all search types (basic, ranked, boolean, fuzzy).
|
|
5
|
+
* Focused on search operations only (Phase 4: Consolidate God Objects).
|
|
6
|
+
*
|
|
7
|
+
* @module search/SearchManager
|
|
8
|
+
*/
|
|
9
|
+
import type { KnowledgeGraph, SearchResult, SavedSearch, AutoSearchResult } from '../types/index.js';
|
|
10
|
+
import type { GraphStorage } from '../core/GraphStorage.js';
|
|
11
|
+
import { QueryCostEstimator } from './QueryCostEstimator.js';
|
|
12
|
+
/**
|
|
13
|
+
* Unified search manager providing access to all search types.
|
|
14
|
+
*
|
|
15
|
+
* Phase 4 Sprint 5: Manages search caches across all search types.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SearchManager {
|
|
18
|
+
private basicSearch;
|
|
19
|
+
private rankedSearch;
|
|
20
|
+
private booleanSearcher;
|
|
21
|
+
private fuzzySearcher;
|
|
22
|
+
private searchSuggestions;
|
|
23
|
+
private savedSearchManager;
|
|
24
|
+
private storage;
|
|
25
|
+
private queryEstimator;
|
|
26
|
+
constructor(storage: GraphStorage, savedSearchesFilePath: string);
|
|
27
|
+
/**
|
|
28
|
+
* Phase 4 Sprint 5: Clear all search caches.
|
|
29
|
+
*
|
|
30
|
+
* Clears caches in all search types: fuzzy, boolean, and ranked token cache.
|
|
31
|
+
* Call this when the graph has been modified to ensure fresh results.
|
|
32
|
+
*/
|
|
33
|
+
clearAllCaches(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Phase 4 Sprint 5: Clear fuzzy search cache.
|
|
36
|
+
*/
|
|
37
|
+
clearFuzzyCache(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Phase 4 Sprint 5: Clear boolean search cache.
|
|
40
|
+
*/
|
|
41
|
+
clearBooleanCache(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Phase 4 Sprint 5: Clear ranked search token cache.
|
|
44
|
+
*/
|
|
45
|
+
clearRankedCache(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Perform a simple text-based search across entity names and observations.
|
|
48
|
+
*
|
|
49
|
+
* This is the primary search method that searches through entity names,
|
|
50
|
+
* observations, and types using case-insensitive substring matching.
|
|
51
|
+
* Optionally filter by tags and importance range.
|
|
52
|
+
*
|
|
53
|
+
* @param query - Text to search for (case-insensitive, searches names/observations/types)
|
|
54
|
+
* @param tags - Optional array of tags to filter results (lowercase)
|
|
55
|
+
* @param minImportance - Optional minimum importance value (0-10)
|
|
56
|
+
* @param maxImportance - Optional maximum importance value (0-10)
|
|
57
|
+
* @returns KnowledgeGraph containing matching entities and their relations
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
62
|
+
*
|
|
63
|
+
* // Simple text search
|
|
64
|
+
* const results = await manager.searchNodes('Alice');
|
|
65
|
+
*
|
|
66
|
+
* // Search with tag filter
|
|
67
|
+
* const engineeringResults = await manager.searchNodes('project', ['engineering']);
|
|
68
|
+
*
|
|
69
|
+
* // Search with importance range
|
|
70
|
+
* const importantResults = await manager.searchNodes('critical', undefined, 8, 10);
|
|
71
|
+
*
|
|
72
|
+
* // Combined filters
|
|
73
|
+
* const filtered = await manager.searchNodes('bug', ['backend'], 5, 10);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
searchNodes(query: string, tags?: string[], minImportance?: number, maxImportance?: number): Promise<KnowledgeGraph>;
|
|
77
|
+
/**
|
|
78
|
+
* Open specific nodes by name.
|
|
79
|
+
*
|
|
80
|
+
* @param names - Array of entity names
|
|
81
|
+
* @returns Knowledge graph with specified entities
|
|
82
|
+
*/
|
|
83
|
+
openNodes(names: string[]): Promise<KnowledgeGraph>;
|
|
84
|
+
/**
|
|
85
|
+
* Search by date range.
|
|
86
|
+
*
|
|
87
|
+
* @param startDate - Optional start date (ISO 8601)
|
|
88
|
+
* @param endDate - Optional end date (ISO 8601)
|
|
89
|
+
* @param entityType - Optional entity type filter
|
|
90
|
+
* @param tags - Optional tags filter
|
|
91
|
+
* @returns Filtered knowledge graph
|
|
92
|
+
*/
|
|
93
|
+
searchByDateRange(startDate?: string, endDate?: string, entityType?: string, tags?: string[]): Promise<KnowledgeGraph>;
|
|
94
|
+
/**
|
|
95
|
+
* Perform TF-IDF ranked search with relevance scoring.
|
|
96
|
+
*
|
|
97
|
+
* Uses Term Frequency-Inverse Document Frequency algorithm to rank results
|
|
98
|
+
* by relevance to the query. Results are sorted by score (highest first).
|
|
99
|
+
* This is ideal for finding the most relevant entities for a search query.
|
|
100
|
+
*
|
|
101
|
+
* @param query - Search query (analyzed for term frequency)
|
|
102
|
+
* @param tags - Optional array of tags to filter results (lowercase)
|
|
103
|
+
* @param minImportance - Optional minimum importance value (0-10)
|
|
104
|
+
* @param maxImportance - Optional maximum importance value (0-10)
|
|
105
|
+
* @param limit - Maximum number of results to return (default: 50, max: 200)
|
|
106
|
+
* @returns Array of SearchResult objects sorted by relevance score (descending)
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
111
|
+
*
|
|
112
|
+
* // Basic ranked search
|
|
113
|
+
* const results = await manager.searchNodesRanked('machine learning algorithms');
|
|
114
|
+
* results.forEach(r => {
|
|
115
|
+
* console.log(`${r.entity.name} (score: ${r.score})`);
|
|
116
|
+
* });
|
|
117
|
+
*
|
|
118
|
+
* // Limit to top 10 most relevant results
|
|
119
|
+
* const top10 = await manager.searchNodesRanked('database optimization', undefined, undefined, undefined, 10);
|
|
120
|
+
*
|
|
121
|
+
* // Ranked search with filters
|
|
122
|
+
* const relevantImportant = await manager.searchNodesRanked(
|
|
123
|
+
* 'security vulnerability',
|
|
124
|
+
* ['security', 'critical'],
|
|
125
|
+
* 8,
|
|
126
|
+
* 10,
|
|
127
|
+
* 20
|
|
128
|
+
* );
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
searchNodesRanked(query: string, tags?: string[], minImportance?: number, maxImportance?: number, limit?: number): Promise<SearchResult[]>;
|
|
132
|
+
/**
|
|
133
|
+
* Perform boolean search with AND, OR, NOT operators.
|
|
134
|
+
*
|
|
135
|
+
* Supports complex boolean logic for precise search queries.
|
|
136
|
+
* Use AND/OR/NOT operators (case-insensitive) to combine search terms.
|
|
137
|
+
* Parentheses are supported for grouping.
|
|
138
|
+
*
|
|
139
|
+
* @param query - Boolean query string (e.g., "alice AND bob", "frontend OR backend NOT legacy")
|
|
140
|
+
* @param tags - Optional array of tags to filter results (lowercase)
|
|
141
|
+
* @param minImportance - Optional minimum importance value (0-10)
|
|
142
|
+
* @param maxImportance - Optional maximum importance value (0-10)
|
|
143
|
+
* @returns KnowledgeGraph containing entities matching the boolean expression
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
148
|
+
*
|
|
149
|
+
* // AND operator - entities matching all terms
|
|
150
|
+
* const both = await manager.booleanSearch('database AND performance');
|
|
151
|
+
*
|
|
152
|
+
* // OR operator - entities matching any term
|
|
153
|
+
* const either = await manager.booleanSearch('frontend OR backend');
|
|
154
|
+
*
|
|
155
|
+
* // NOT operator - exclude terms
|
|
156
|
+
* const excluding = await manager.booleanSearch('API NOT deprecated');
|
|
157
|
+
*
|
|
158
|
+
* // Complex queries with grouping
|
|
159
|
+
* const complex = await manager.booleanSearch('(react OR vue) AND (component OR hook) NOT legacy');
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
booleanSearch(query: string, tags?: string[], minImportance?: number, maxImportance?: number): Promise<KnowledgeGraph>;
|
|
163
|
+
/**
|
|
164
|
+
* Perform fuzzy search with typo tolerance.
|
|
165
|
+
*
|
|
166
|
+
* Uses Levenshtein distance to find entities that approximately match the query,
|
|
167
|
+
* making it ideal for handling typos and variations in spelling.
|
|
168
|
+
* Higher threshold values require closer matches.
|
|
169
|
+
*
|
|
170
|
+
* @param query - Search query (will match approximate spellings)
|
|
171
|
+
* @param threshold - Similarity threshold from 0.0 (very lenient) to 1.0 (exact match). Default: 0.7
|
|
172
|
+
* @param tags - Optional array of tags to filter results (lowercase)
|
|
173
|
+
* @param minImportance - Optional minimum importance value (0-10)
|
|
174
|
+
* @param maxImportance - Optional maximum importance value (0-10)
|
|
175
|
+
* @returns KnowledgeGraph containing entities with similar names/observations
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
180
|
+
*
|
|
181
|
+
* // Find entities even with typos
|
|
182
|
+
* const results = await manager.fuzzySearch('databse'); // Will match "database"
|
|
183
|
+
*
|
|
184
|
+
* // Adjust threshold for strictness
|
|
185
|
+
* const strict = await manager.fuzzySearch('optmization', 0.9); // Requires very close match
|
|
186
|
+
* const lenient = await manager.fuzzySearch('optmization', 0.6); // More tolerant of differences
|
|
187
|
+
*
|
|
188
|
+
* // Fuzzy search with filters
|
|
189
|
+
* const filtered = await manager.fuzzySearch('secrity', 0.7, ['important'], 7, 10);
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
fuzzySearch(query: string, threshold?: number, tags?: string[], minImportance?: number, maxImportance?: number): Promise<KnowledgeGraph>;
|
|
193
|
+
/**
|
|
194
|
+
* Get search suggestions for a query.
|
|
195
|
+
*
|
|
196
|
+
* @param query - Search query
|
|
197
|
+
* @param maxSuggestions - Maximum suggestions to return
|
|
198
|
+
* @returns Array of suggested terms
|
|
199
|
+
*/
|
|
200
|
+
getSearchSuggestions(query: string, maxSuggestions?: number): Promise<string[]>;
|
|
201
|
+
/**
|
|
202
|
+
* Save a search query for later reuse.
|
|
203
|
+
*
|
|
204
|
+
* Saved searches store query parameters and can be re-executed later.
|
|
205
|
+
* The system tracks usage count and last used timestamp automatically.
|
|
206
|
+
*
|
|
207
|
+
* @param search - Search parameters (name, query, and optional filters)
|
|
208
|
+
* @returns Newly created SavedSearch object with metadata
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
213
|
+
*
|
|
214
|
+
* // Save a simple search
|
|
215
|
+
* const saved = await manager.saveSearch({
|
|
216
|
+
* name: 'High Priority Bugs',
|
|
217
|
+
* query: 'bug',
|
|
218
|
+
* tags: ['critical'],
|
|
219
|
+
* minImportance: 8
|
|
220
|
+
* });
|
|
221
|
+
*
|
|
222
|
+
* // Save a complex search
|
|
223
|
+
* await manager.saveSearch({
|
|
224
|
+
* name: 'Recent Frontend Work',
|
|
225
|
+
* query: 'component OR hook',
|
|
226
|
+
* tags: ['frontend', 'react'],
|
|
227
|
+
* searchType: 'boolean'
|
|
228
|
+
* });
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
saveSearch(search: Omit<SavedSearch, 'createdAt' | 'useCount' | 'lastUsed'>): Promise<SavedSearch>;
|
|
232
|
+
/**
|
|
233
|
+
* List all saved searches.
|
|
234
|
+
*
|
|
235
|
+
* @returns Array of saved searches
|
|
236
|
+
*/
|
|
237
|
+
listSavedSearches(): Promise<SavedSearch[]>;
|
|
238
|
+
/**
|
|
239
|
+
* Get a saved search by name.
|
|
240
|
+
*
|
|
241
|
+
* @param name - Search name
|
|
242
|
+
* @returns Saved search or null
|
|
243
|
+
*/
|
|
244
|
+
getSavedSearch(name: string): Promise<SavedSearch | null>;
|
|
245
|
+
/**
|
|
246
|
+
* Execute a saved search by name.
|
|
247
|
+
*
|
|
248
|
+
* Runs a previously saved search with its stored parameters.
|
|
249
|
+
* Automatically updates the search's useCount and lastUsed timestamp.
|
|
250
|
+
*
|
|
251
|
+
* @param name - The unique name of the saved search to execute
|
|
252
|
+
* @returns KnowledgeGraph containing the search results
|
|
253
|
+
* @throws Error if saved search not found
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
258
|
+
*
|
|
259
|
+
* // Execute a saved search
|
|
260
|
+
* const results = await manager.executeSavedSearch('High Priority Bugs');
|
|
261
|
+
* console.log(`Found ${results.entities.length} high priority bugs`);
|
|
262
|
+
*
|
|
263
|
+
* // Handle missing saved search
|
|
264
|
+
* try {
|
|
265
|
+
* await manager.executeSavedSearch('NonExistent');
|
|
266
|
+
* } catch (error) {
|
|
267
|
+
* console.error('Search not found');
|
|
268
|
+
* }
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
executeSavedSearch(name: string): Promise<KnowledgeGraph>;
|
|
272
|
+
/**
|
|
273
|
+
* Delete a saved search.
|
|
274
|
+
*
|
|
275
|
+
* @param name - Search name
|
|
276
|
+
* @returns True if deleted
|
|
277
|
+
*/
|
|
278
|
+
deleteSavedSearch(name: string): Promise<boolean>;
|
|
279
|
+
/**
|
|
280
|
+
* Update a saved search.
|
|
281
|
+
*
|
|
282
|
+
* @param name - Search name
|
|
283
|
+
* @param updates - Fields to update
|
|
284
|
+
* @returns Updated saved search
|
|
285
|
+
*/
|
|
286
|
+
updateSavedSearch(name: string, updates: Partial<Omit<SavedSearch, 'name' | 'createdAt' | 'useCount' | 'lastUsed'>>): Promise<SavedSearch>;
|
|
287
|
+
/**
|
|
288
|
+
* Phase 10 Sprint 4: Automatically select and execute the best search method.
|
|
289
|
+
*
|
|
290
|
+
* Analyzes the query and graph size to determine the optimal search method,
|
|
291
|
+
* then executes it and returns both the results and the selection reasoning.
|
|
292
|
+
*
|
|
293
|
+
* @param query - The search query
|
|
294
|
+
* @param limit - Maximum number of results (default: 10)
|
|
295
|
+
* @returns AutoSearchResult with selected method, results, and estimates
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```typescript
|
|
299
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
300
|
+
*
|
|
301
|
+
* // Let the system choose the best search method
|
|
302
|
+
* const result = await manager.autoSearch('software engineer skills');
|
|
303
|
+
*
|
|
304
|
+
* console.log(`Used ${result.selectedMethod} because: ${result.selectionReason}`);
|
|
305
|
+
* console.log(`Found ${result.results.length} results in ${result.executionTimeMs}ms`);
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
autoSearch(query: string, limit?: number): Promise<AutoSearchResult>;
|
|
309
|
+
/**
|
|
310
|
+
* Phase 10 Sprint 4: Get cost estimates for all search methods.
|
|
311
|
+
*
|
|
312
|
+
* Useful for clients that want to display cost information or
|
|
313
|
+
* make their own method selection decisions.
|
|
314
|
+
*
|
|
315
|
+
* @param query - The search query
|
|
316
|
+
* @returns Array of cost estimates for all methods
|
|
317
|
+
*/
|
|
318
|
+
getSearchCostEstimates(query: string): Promise<import('../types/index.js').QueryCostEstimate[]>;
|
|
319
|
+
/**
|
|
320
|
+
* Phase 10 Sprint 4: Get the query cost estimator instance.
|
|
321
|
+
*
|
|
322
|
+
* @returns The QueryCostEstimator instance
|
|
323
|
+
*/
|
|
324
|
+
getQueryEstimator(): QueryCostEstimator;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=SearchManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchManager.d.ts","sourceRoot":"","sources":["../../src/search/SearchManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAU,MAAM,mBAAmB,CAAC;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAO5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,eAAe,CAAgB;IACvC,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,kBAAkB,CAAqB;IAC/C,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,cAAc,CAAqB;gBAE/B,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM;IAahE;;;;;OAKG;IACH,cAAc,IAAI,IAAI;IAMtB;;OAEG;IACH,eAAe,IAAI,IAAI;IAIvB;;OAEG;IACH,iBAAiB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ic, ranked, boolean, fuzzy).
|
|
5
|
+
* Focused on search operations only (Phase 4: Consolidate God Objects).
|
|
5
6
|
*
|
|
6
7
|
* @module search/SearchManager
|
|
7
8
|
*/
|
|
@@ -11,8 +12,11 @@ import { BooleanSearch } from './BooleanSearch.js';
|
|
|
11
12
|
import { FuzzySearch } from './FuzzySearch.js';
|
|
12
13
|
import { SearchSuggestions } from './SearchSuggestions.js';
|
|
13
14
|
import { SavedSearchManager } from './SavedSearchManager.js';
|
|
15
|
+
import { QueryCostEstimator } from './QueryCostEstimator.js';
|
|
14
16
|
/**
|
|
15
17
|
* Unified search manager providing access to all search types.
|
|
18
|
+
*
|
|
19
|
+
* Phase 4 Sprint 5: Manages search caches across all search types.
|
|
16
20
|
*/
|
|
17
21
|
export class SearchManager {
|
|
18
22
|
basicSearch;
|
|
@@ -21,13 +25,47 @@ export class SearchManager {
|
|
|
21
25
|
fuzzySearcher;
|
|
22
26
|
searchSuggestions;
|
|
23
27
|
savedSearchManager;
|
|
28
|
+
storage;
|
|
29
|
+
queryEstimator;
|
|
24
30
|
constructor(storage, savedSearchesFilePath) {
|
|
31
|
+
this.storage = storage;
|
|
25
32
|
this.basicSearch = new BasicSearch(storage);
|
|
26
33
|
this.rankedSearch = new RankedSearch(storage);
|
|
27
34
|
this.booleanSearcher = new BooleanSearch(storage);
|
|
28
35
|
this.fuzzySearcher = new FuzzySearch(storage);
|
|
29
36
|
this.searchSuggestions = new SearchSuggestions(storage);
|
|
30
37
|
this.savedSearchManager = new SavedSearchManager(savedSearchesFilePath, this.basicSearch);
|
|
38
|
+
this.queryEstimator = new QueryCostEstimator();
|
|
39
|
+
}
|
|
40
|
+
// ==================== Cache Management (Phase 4 Sprint 5) ====================
|
|
41
|
+
/**
|
|
42
|
+
* Phase 4 Sprint 5: Clear all search caches.
|
|
43
|
+
*
|
|
44
|
+
* Clears caches in all search types: fuzzy, boolean, and ranked token cache.
|
|
45
|
+
* Call this when the graph has been modified to ensure fresh results.
|
|
46
|
+
*/
|
|
47
|
+
clearAllCaches() {
|
|
48
|
+
this.fuzzySearcher.clearCache();
|
|
49
|
+
this.booleanSearcher.clearCache();
|
|
50
|
+
this.rankedSearch.clearTokenCache();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Phase 4 Sprint 5: Clear fuzzy search cache.
|
|
54
|
+
*/
|
|
55
|
+
clearFuzzyCache() {
|
|
56
|
+
this.fuzzySearcher.clearCache();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Phase 4 Sprint 5: Clear boolean search cache.
|
|
60
|
+
*/
|
|
61
|
+
clearBooleanCache() {
|
|
62
|
+
this.booleanSearcher.clearCache();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Phase 4 Sprint 5: Clear ranked search token cache.
|
|
66
|
+
*/
|
|
67
|
+
clearRankedCache() {
|
|
68
|
+
this.rankedSearch.clearTokenCache();
|
|
31
69
|
}
|
|
32
70
|
// ==================== Basic Search ====================
|
|
33
71
|
/**
|
|
@@ -302,4 +340,114 @@ export class SearchManager {
|
|
|
302
340
|
async updateSavedSearch(name, updates) {
|
|
303
341
|
return this.savedSearchManager.updateSavedSearch(name, updates);
|
|
304
342
|
}
|
|
343
|
+
// ==================== Phase 10 Sprint 4: Automatic Search ====================
|
|
344
|
+
/**
|
|
345
|
+
* Phase 10 Sprint 4: Automatically select and execute the best search method.
|
|
346
|
+
*
|
|
347
|
+
* Analyzes the query and graph size to determine the optimal search method,
|
|
348
|
+
* then executes it and returns both the results and the selection reasoning.
|
|
349
|
+
*
|
|
350
|
+
* @param query - The search query
|
|
351
|
+
* @param limit - Maximum number of results (default: 10)
|
|
352
|
+
* @returns AutoSearchResult with selected method, results, and estimates
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* const manager = new SearchManager(storage, savedSearchesPath);
|
|
357
|
+
*
|
|
358
|
+
* // Let the system choose the best search method
|
|
359
|
+
* const result = await manager.autoSearch('software engineer skills');
|
|
360
|
+
*
|
|
361
|
+
* console.log(`Used ${result.selectedMethod} because: ${result.selectionReason}`);
|
|
362
|
+
* console.log(`Found ${result.results.length} results in ${result.executionTimeMs}ms`);
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
async autoSearch(query, limit = 10) {
|
|
366
|
+
const startTime = Date.now();
|
|
367
|
+
// Get entity count from graph
|
|
368
|
+
const graph = await this.storage.loadGraph();
|
|
369
|
+
const entityCount = graph.entities.length;
|
|
370
|
+
// Get cost estimates for all methods
|
|
371
|
+
const estimates = this.queryEstimator.estimateAllMethods(query, entityCount);
|
|
372
|
+
// Get the recommended method
|
|
373
|
+
const recommendation = this.queryEstimator.recommendMethod(query, entityCount);
|
|
374
|
+
const selectedMethod = recommendation.method;
|
|
375
|
+
const selectionReason = recommendation.reason;
|
|
376
|
+
// Execute the selected search method
|
|
377
|
+
let results;
|
|
378
|
+
switch (selectedMethod) {
|
|
379
|
+
case 'basic': {
|
|
380
|
+
const basicResult = await this.basicSearch.searchNodes(query);
|
|
381
|
+
results = basicResult.entities.map((e, idx) => ({
|
|
382
|
+
entity: e,
|
|
383
|
+
score: 1.0 - idx * 0.01, // Rank by position
|
|
384
|
+
matchedFields: { name: true, observations: e.observations },
|
|
385
|
+
}));
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
case 'ranked': {
|
|
389
|
+
results = await this.rankedSearch.searchNodesRanked(query, undefined, undefined, undefined, limit);
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
case 'boolean': {
|
|
393
|
+
const booleanResult = await this.booleanSearcher.booleanSearch(query);
|
|
394
|
+
results = booleanResult.entities.map((e, idx) => ({
|
|
395
|
+
entity: e,
|
|
396
|
+
score: 1.0 - idx * 0.01, // Rank by position
|
|
397
|
+
matchedFields: { name: true, observations: e.observations },
|
|
398
|
+
}));
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 'fuzzy': {
|
|
402
|
+
const fuzzyResult = await this.fuzzySearcher.fuzzySearch(query);
|
|
403
|
+
results = fuzzyResult.entities.map((e, idx) => ({
|
|
404
|
+
entity: e,
|
|
405
|
+
score: 1.0 - idx * 0.01, // Rank by position
|
|
406
|
+
matchedFields: { name: true, observations: e.observations },
|
|
407
|
+
}));
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
case 'semantic': {
|
|
411
|
+
// Semantic search not available through SearchManager
|
|
412
|
+
// Fall back to ranked search
|
|
413
|
+
results = await this.rankedSearch.searchNodesRanked(query, undefined, undefined, undefined, limit);
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
default: {
|
|
417
|
+
const _exhaustiveCheck = selectedMethod;
|
|
418
|
+
throw new Error(`Unknown search method: ${_exhaustiveCheck}`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Limit results
|
|
422
|
+
const limitedResults = results.slice(0, limit);
|
|
423
|
+
return {
|
|
424
|
+
selectedMethod,
|
|
425
|
+
selectionReason,
|
|
426
|
+
estimates,
|
|
427
|
+
results: limitedResults,
|
|
428
|
+
executionTimeMs: Date.now() - startTime,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Phase 10 Sprint 4: Get cost estimates for all search methods.
|
|
433
|
+
*
|
|
434
|
+
* Useful for clients that want to display cost information or
|
|
435
|
+
* make their own method selection decisions.
|
|
436
|
+
*
|
|
437
|
+
* @param query - The search query
|
|
438
|
+
* @returns Array of cost estimates for all methods
|
|
439
|
+
*/
|
|
440
|
+
async getSearchCostEstimates(query) {
|
|
441
|
+
const graph = await this.storage.loadGraph();
|
|
442
|
+
const entityCount = graph.entities.length;
|
|
443
|
+
return this.queryEstimator.estimateAllMethods(query, entityCount);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Phase 10 Sprint 4: Get the query cost estimator instance.
|
|
447
|
+
*
|
|
448
|
+
* @returns The QueryCostEstimator instance
|
|
449
|
+
*/
|
|
450
|
+
getQueryEstimator() {
|
|
451
|
+
return this.queryEstimator;
|
|
452
|
+
}
|
|
305
453
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Suggestions
|
|
3
|
+
*
|
|
4
|
+
* Provides "did you mean?" suggestions using Levenshtein distance.
|
|
5
|
+
*
|
|
6
|
+
* @module search/SearchSuggestions
|
|
7
|
+
*/
|
|
8
|
+
import type { GraphStorage } from '../core/GraphStorage.js';
|
|
9
|
+
/**
|
|
10
|
+
* Generates search suggestions based on entity names and types.
|
|
11
|
+
*/
|
|
12
|
+
export declare class SearchSuggestions {
|
|
13
|
+
private storage;
|
|
14
|
+
constructor(storage: GraphStorage);
|
|
15
|
+
/**
|
|
16
|
+
* Get "did you mean?" suggestions for a query.
|
|
17
|
+
*
|
|
18
|
+
* Returns similar entity names and types that might be what the user intended.
|
|
19
|
+
* Excludes exact matches (similarity < 1.0) and very dissimilar strings (similarity > 0.5).
|
|
20
|
+
*
|
|
21
|
+
* @param query - The search query
|
|
22
|
+
* @param maxSuggestions - Maximum number of suggestions to return (default 5)
|
|
23
|
+
* @returns Array of suggested entity/type names sorted by similarity
|
|
24
|
+
*/
|
|
25
|
+
getSearchSuggestions(query: string, maxSuggestions?: number): Promise<string[]>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=SearchSuggestions.d.ts.map
|