bigtool-ts 0.1.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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +641 -0
- package/dist/adapters/agent-protocol.d.ts +149 -0
- package/dist/adapters/agent-protocol.d.ts.map +1 -0
- package/dist/adapters/agent-protocol.js +133 -0
- package/dist/adapters/agent-protocol.js.map +1 -0
- package/dist/adapters/index.d.ts +39 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +42 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/inngest.d.ts +234 -0
- package/dist/adapters/inngest.d.ts.map +1 -0
- package/dist/adapters/inngest.js +276 -0
- package/dist/adapters/inngest.js.map +1 -0
- package/dist/adapters/mastra.d.ts +201 -0
- package/dist/adapters/mastra.d.ts.map +1 -0
- package/dist/adapters/mastra.js +250 -0
- package/dist/adapters/mastra.js.map +1 -0
- package/dist/adapters/types.d.ts +42 -0
- package/dist/adapters/types.d.ts.map +1 -0
- package/dist/adapters/types.js +6 -0
- package/dist/adapters/types.js.map +1 -0
- package/dist/adapters/vercel-ai.d.ts +176 -0
- package/dist/adapters/vercel-ai.d.ts.map +1 -0
- package/dist/adapters/vercel-ai.js +244 -0
- package/dist/adapters/vercel-ai.js.map +1 -0
- package/dist/catalog/index.d.ts +177 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +244 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/graph/agent.d.ts +214 -0
- package/dist/graph/agent.d.ts.map +1 -0
- package/dist/graph/agent.js +196 -0
- package/dist/graph/agent.js.map +1 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/nodes.d.ts +100 -0
- package/dist/graph/nodes.d.ts.map +1 -0
- package/dist/graph/nodes.js +190 -0
- package/dist/graph/nodes.js.map +1 -0
- package/dist/graph/search-tool.d.ts +34 -0
- package/dist/graph/search-tool.d.ts.map +1 -0
- package/dist/graph/search-tool.js +54 -0
- package/dist/graph/search-tool.js.map +1 -0
- package/dist/graph/state.d.ts +26 -0
- package/dist/graph/state.d.ts.map +1 -0
- package/dist/graph/state.js +29 -0
- package/dist/graph/state.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/loader/index.d.ts +172 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/index.js +179 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/loader.d.ts +114 -0
- package/dist/loader/loader.d.ts.map +1 -0
- package/dist/loader/loader.js +185 -0
- package/dist/loader/loader.js.map +1 -0
- package/dist/search/cache.d.ts +76 -0
- package/dist/search/cache.d.ts.map +1 -0
- package/dist/search/cache.js +135 -0
- package/dist/search/cache.js.map +1 -0
- package/dist/search/index.d.ts +63 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +122 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/normalize.d.ts +104 -0
- package/dist/search/normalize.d.ts.map +1 -0
- package/dist/search/normalize.js +211 -0
- package/dist/search/normalize.js.map +1 -0
- package/dist/search/orama.d.ts +256 -0
- package/dist/search/orama.d.ts.map +1 -0
- package/dist/search/orama.js +511 -0
- package/dist/search/orama.js.map +1 -0
- package/dist/search/types.d.ts +96 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search/types.js +8 -0
- package/dist/search/types.js.map +1 -0
- package/dist/sources/dynamic.d.ts +200 -0
- package/dist/sources/dynamic.d.ts.map +1 -0
- package/dist/sources/dynamic.js +194 -0
- package/dist/sources/dynamic.js.map +1 -0
- package/dist/sources/index.d.ts +11 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +14 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/local.d.ts +128 -0
- package/dist/sources/local.d.ts.map +1 -0
- package/dist/sources/local.js +155 -0
- package/dist/sources/local.js.map +1 -0
- package/dist/sources/mcp.d.ts +438 -0
- package/dist/sources/mcp.d.ts.map +1 -0
- package/dist/sources/mcp.js +438 -0
- package/dist/sources/mcp.js.map +1 -0
- package/dist/sources/types.d.ts +16 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +7 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/sources/with-metadata.d.ts +7 -0
- package/dist/sources/with-metadata.d.ts.map +1 -0
- package/dist/sources/with-metadata.js +7 -0
- package/dist/sources/with-metadata.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +700 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +97 -0
- package/dist/types.js.map +1 -0
- package/package.json +118 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding Cache Implementations
|
|
3
|
+
*
|
|
4
|
+
* Caches computed embeddings to avoid expensive recomputation.
|
|
5
|
+
* Embeddings are relatively stable - tool descriptions don't change often.
|
|
6
|
+
*/
|
|
7
|
+
import type { EmbeddingCache } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Simple in-memory cache using a Map.
|
|
10
|
+
* Good for development and single-process deployments.
|
|
11
|
+
* Cache is lost on process restart.
|
|
12
|
+
*/
|
|
13
|
+
export declare class MemoryCache implements EmbeddingCache {
|
|
14
|
+
private cache;
|
|
15
|
+
constructor();
|
|
16
|
+
get(toolId: string): Promise<number[] | null>;
|
|
17
|
+
set(toolId: string, embedding: number[]): Promise<void>;
|
|
18
|
+
invalidate(toolId: string): Promise<void>;
|
|
19
|
+
clear(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current size of the cache
|
|
22
|
+
*/
|
|
23
|
+
get size(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a tool ID exists in cache
|
|
26
|
+
*/
|
|
27
|
+
has(toolId: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Get all cached tool IDs
|
|
30
|
+
*/
|
|
31
|
+
keys(): string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* LRU (Least Recently Used) cache with configurable max size.
|
|
35
|
+
* Automatically evicts oldest entries when capacity is reached.
|
|
36
|
+
*/
|
|
37
|
+
export declare class LRUCache implements EmbeddingCache {
|
|
38
|
+
private cache;
|
|
39
|
+
private readonly maxSize;
|
|
40
|
+
constructor(maxSize?: number);
|
|
41
|
+
get(toolId: string): Promise<number[] | null>;
|
|
42
|
+
set(toolId: string, embedding: number[]): Promise<void>;
|
|
43
|
+
invalidate(toolId: string): Promise<void>;
|
|
44
|
+
clear(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current size of the cache
|
|
47
|
+
*/
|
|
48
|
+
get size(): number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for Redis cache
|
|
52
|
+
*/
|
|
53
|
+
export interface RedisCacheConfig {
|
|
54
|
+
/** Redis connection URL */
|
|
55
|
+
url: string;
|
|
56
|
+
/** Key prefix for namespacing (default: "bigtool:embeddings:") */
|
|
57
|
+
prefix?: string;
|
|
58
|
+
/** TTL in seconds (default: no expiry) */
|
|
59
|
+
ttl?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Redis-based cache for production deployments.
|
|
63
|
+
*
|
|
64
|
+
* NOTE: This is a stub implementation. To use Redis caching,
|
|
65
|
+
* install the `redis` package and implement the actual Redis client.
|
|
66
|
+
*/
|
|
67
|
+
export declare class RedisCache implements EmbeddingCache {
|
|
68
|
+
private readonly config;
|
|
69
|
+
private memoryFallback;
|
|
70
|
+
constructor(config: RedisCacheConfig);
|
|
71
|
+
get(toolId: string): Promise<number[] | null>;
|
|
72
|
+
set(toolId: string, embedding: number[]): Promise<void>;
|
|
73
|
+
invalidate(toolId: string): Promise<void>;
|
|
74
|
+
clear(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/search/cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAMjD;;;;GAIG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD,OAAO,CAAC,KAAK,CAAwB;;IAM/B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAK7C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,IAAI,IAAI,MAAM,EAAE;CAGjB;AAMD;;;GAGG;AACH,qBAAa,QAAS,YAAW,cAAc;IAC7C,OAAO,CAAC,KAAK,CAAwB;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,GAAE,MAAa;IAK5B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAW7C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAevD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF;AAMD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IACpD,OAAO,CAAC,cAAc,CAAc;gBAExB,MAAM,EAAE,gBAAgB;IAa9B,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;IAI7C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Embedding Cache Implementations
|
|
3
|
+
*
|
|
4
|
+
* Caches computed embeddings to avoid expensive recomputation.
|
|
5
|
+
* Embeddings are relatively stable - tool descriptions don't change often.
|
|
6
|
+
*/
|
|
7
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
8
|
+
// Memory Cache - In-memory Map-based cache
|
|
9
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
10
|
+
/**
|
|
11
|
+
* Simple in-memory cache using a Map.
|
|
12
|
+
* Good for development and single-process deployments.
|
|
13
|
+
* Cache is lost on process restart.
|
|
14
|
+
*/
|
|
15
|
+
export class MemoryCache {
|
|
16
|
+
cache;
|
|
17
|
+
constructor() {
|
|
18
|
+
this.cache = new Map();
|
|
19
|
+
}
|
|
20
|
+
async get(toolId) {
|
|
21
|
+
const embedding = this.cache.get(toolId);
|
|
22
|
+
return embedding ?? null;
|
|
23
|
+
}
|
|
24
|
+
async set(toolId, embedding) {
|
|
25
|
+
this.cache.set(toolId, embedding);
|
|
26
|
+
}
|
|
27
|
+
async invalidate(toolId) {
|
|
28
|
+
this.cache.delete(toolId);
|
|
29
|
+
}
|
|
30
|
+
async clear() {
|
|
31
|
+
this.cache.clear();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the current size of the cache
|
|
35
|
+
*/
|
|
36
|
+
get size() {
|
|
37
|
+
return this.cache.size;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a tool ID exists in cache
|
|
41
|
+
*/
|
|
42
|
+
has(toolId) {
|
|
43
|
+
return this.cache.has(toolId);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get all cached tool IDs
|
|
47
|
+
*/
|
|
48
|
+
keys() {
|
|
49
|
+
return Array.from(this.cache.keys());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
53
|
+
// LRU Cache - Memory cache with size limit
|
|
54
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
55
|
+
/**
|
|
56
|
+
* LRU (Least Recently Used) cache with configurable max size.
|
|
57
|
+
* Automatically evicts oldest entries when capacity is reached.
|
|
58
|
+
*/
|
|
59
|
+
export class LRUCache {
|
|
60
|
+
cache;
|
|
61
|
+
maxSize;
|
|
62
|
+
constructor(maxSize = 1000) {
|
|
63
|
+
this.cache = new Map();
|
|
64
|
+
this.maxSize = maxSize;
|
|
65
|
+
}
|
|
66
|
+
async get(toolId) {
|
|
67
|
+
const embedding = this.cache.get(toolId);
|
|
68
|
+
if (embedding !== undefined) {
|
|
69
|
+
// Move to end (most recently used)
|
|
70
|
+
this.cache.delete(toolId);
|
|
71
|
+
this.cache.set(toolId, embedding);
|
|
72
|
+
return embedding;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
async set(toolId, embedding) {
|
|
77
|
+
// If key exists, delete it first to update position
|
|
78
|
+
if (this.cache.has(toolId)) {
|
|
79
|
+
this.cache.delete(toolId);
|
|
80
|
+
}
|
|
81
|
+
// Evict oldest entries if at capacity
|
|
82
|
+
while (this.cache.size >= this.maxSize) {
|
|
83
|
+
const oldest = this.cache.keys().next().value;
|
|
84
|
+
if (oldest !== undefined) {
|
|
85
|
+
this.cache.delete(oldest);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.cache.set(toolId, embedding);
|
|
89
|
+
}
|
|
90
|
+
async invalidate(toolId) {
|
|
91
|
+
this.cache.delete(toolId);
|
|
92
|
+
}
|
|
93
|
+
async clear() {
|
|
94
|
+
this.cache.clear();
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the current size of the cache
|
|
98
|
+
*/
|
|
99
|
+
get size() {
|
|
100
|
+
return this.cache.size;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Redis-based cache for production deployments.
|
|
105
|
+
*
|
|
106
|
+
* NOTE: This is a stub implementation. To use Redis caching,
|
|
107
|
+
* install the `redis` package and implement the actual Redis client.
|
|
108
|
+
*/
|
|
109
|
+
export class RedisCache {
|
|
110
|
+
config;
|
|
111
|
+
memoryFallback;
|
|
112
|
+
constructor(config) {
|
|
113
|
+
this.config = {
|
|
114
|
+
url: config.url,
|
|
115
|
+
prefix: config.prefix ?? "bigtool:embeddings:",
|
|
116
|
+
ttl: config.ttl ?? 0,
|
|
117
|
+
};
|
|
118
|
+
// Use memory fallback until Redis is actually implemented
|
|
119
|
+
this.memoryFallback = new MemoryCache();
|
|
120
|
+
console.warn("[RedisCache] Using memory fallback. Install 'redis' package and implement client for production use.");
|
|
121
|
+
}
|
|
122
|
+
async get(toolId) {
|
|
123
|
+
return this.memoryFallback.get(toolId);
|
|
124
|
+
}
|
|
125
|
+
async set(toolId, embedding) {
|
|
126
|
+
return this.memoryFallback.set(toolId, embedding);
|
|
127
|
+
}
|
|
128
|
+
async invalidate(toolId) {
|
|
129
|
+
return this.memoryFallback.invalidate(toolId);
|
|
130
|
+
}
|
|
131
|
+
async clear() {
|
|
132
|
+
return this.memoryFallback.clear();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/search/cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,8EAA8E;AAC9E,2CAA2C;AAC3C,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACd,KAAK,CAAwB;IAErC;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAc;QACtB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,SAAS,IAAI,IAAI,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAc,EAAE,SAAmB;QAC3C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc;QAC7B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,MAAc;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CA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QACT,OAAO,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { SearchIndex, SearchOptions, SearchResult, ToolMetadata } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for Orama-based search
|
|
4
|
+
*/
|
|
5
|
+
export interface OramaSearchConfig {
|
|
6
|
+
/** Search mode */
|
|
7
|
+
mode: 'bm25' | 'vector' | 'hybrid';
|
|
8
|
+
/** Embeddings provider (required for vector/hybrid modes) */
|
|
9
|
+
embeddings?: unknown;
|
|
10
|
+
/** Field boosting for BM25/hybrid */
|
|
11
|
+
boost?: {
|
|
12
|
+
name?: number;
|
|
13
|
+
description?: number;
|
|
14
|
+
keywords?: number;
|
|
15
|
+
categories?: number;
|
|
16
|
+
};
|
|
17
|
+
/** Weights for hybrid mode */
|
|
18
|
+
weights?: {
|
|
19
|
+
bm25?: number;
|
|
20
|
+
vector?: number;
|
|
21
|
+
};
|
|
22
|
+
/** Embedding cache */
|
|
23
|
+
cache?: unknown;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Default search implementation using @orama/orama for BM25 search.
|
|
27
|
+
*
|
|
28
|
+
* Supports three modes:
|
|
29
|
+
* - 'bm25': Fast text search (default, no API keys needed)
|
|
30
|
+
* - 'vector': Semantic search using embeddings
|
|
31
|
+
* - 'hybrid': Combination of BM25 and vector search
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // BM25 mode (default)
|
|
36
|
+
* const search = new OramaSearch();
|
|
37
|
+
*
|
|
38
|
+
* // Vector mode
|
|
39
|
+
* const search = new OramaSearch({
|
|
40
|
+
* mode: 'vector',
|
|
41
|
+
* embeddings: new OpenAIEmbeddings(),
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Hybrid mode
|
|
45
|
+
* const search = new OramaSearch({
|
|
46
|
+
* mode: 'hybrid',
|
|
47
|
+
* embeddings: new OpenAIEmbeddings(),
|
|
48
|
+
* weights: { bm25: 0.5, vector: 0.5 },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class OramaSearch implements SearchIndex {
|
|
53
|
+
private config;
|
|
54
|
+
private tools;
|
|
55
|
+
private initialized;
|
|
56
|
+
constructor(config?: Partial<OramaSearchConfig>);
|
|
57
|
+
index(tools: ToolMetadata[]): Promise<void>;
|
|
58
|
+
search(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
59
|
+
reindex(): Promise<void>;
|
|
60
|
+
/** Get current configuration */
|
|
61
|
+
getConfig(): OramaSearchConfig;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE1F;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kBAAkB;IAClB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAEnC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,qCAAqC;IACrC,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IAEF,8BAA8B;IAC9B,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,sBAAsB;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAY,YAAW,WAAW;IAC7C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAuB7C,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY3C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IA0D3E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B,gCAAgC;IAChC,SAAS,IAAI,iBAAiB;CAG/B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default search implementation using @orama/orama for BM25 search.
|
|
3
|
+
*
|
|
4
|
+
* Supports three modes:
|
|
5
|
+
* - 'bm25': Fast text search (default, no API keys needed)
|
|
6
|
+
* - 'vector': Semantic search using embeddings
|
|
7
|
+
* - 'hybrid': Combination of BM25 and vector search
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // BM25 mode (default)
|
|
12
|
+
* const search = new OramaSearch();
|
|
13
|
+
*
|
|
14
|
+
* // Vector mode
|
|
15
|
+
* const search = new OramaSearch({
|
|
16
|
+
* mode: 'vector',
|
|
17
|
+
* embeddings: new OpenAIEmbeddings(),
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Hybrid mode
|
|
21
|
+
* const search = new OramaSearch({
|
|
22
|
+
* mode: 'hybrid',
|
|
23
|
+
* embeddings: new OpenAIEmbeddings(),
|
|
24
|
+
* weights: { bm25: 0.5, vector: 0.5 },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export class OramaSearch {
|
|
29
|
+
config;
|
|
30
|
+
tools = [];
|
|
31
|
+
initialized = false;
|
|
32
|
+
constructor(config = {}) {
|
|
33
|
+
this.config = {
|
|
34
|
+
mode: config.mode ?? 'bm25',
|
|
35
|
+
embeddings: config.embeddings,
|
|
36
|
+
boost: config.boost ?? {
|
|
37
|
+
name: 2,
|
|
38
|
+
keywords: 1.5,
|
|
39
|
+
description: 1,
|
|
40
|
+
categories: 1,
|
|
41
|
+
},
|
|
42
|
+
weights: config.weights ?? {
|
|
43
|
+
bm25: 0.5,
|
|
44
|
+
vector: 0.5,
|
|
45
|
+
},
|
|
46
|
+
cache: config.cache,
|
|
47
|
+
};
|
|
48
|
+
// Validate config
|
|
49
|
+
if ((this.config.mode === 'vector' || this.config.mode === 'hybrid') && !this.config.embeddings) {
|
|
50
|
+
throw new Error(`OramaSearch: 'embeddings' is required for '${this.config.mode}' mode`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async index(tools) {
|
|
54
|
+
this.tools = tools;
|
|
55
|
+
// TODO: Initialize Orama index
|
|
56
|
+
// In a real implementation:
|
|
57
|
+
// 1. Create Orama database with schema
|
|
58
|
+
// 2. Index all tools
|
|
59
|
+
// 3. If vector mode, compute/cache embeddings
|
|
60
|
+
this.initialized = true;
|
|
61
|
+
}
|
|
62
|
+
async search(query, options = {}) {
|
|
63
|
+
if (!this.initialized) {
|
|
64
|
+
throw new Error('OramaSearch: Must call index() before searching');
|
|
65
|
+
}
|
|
66
|
+
const limit = options.limit ?? 5;
|
|
67
|
+
const threshold = options.threshold ?? 0;
|
|
68
|
+
// TODO: Implement actual Orama search
|
|
69
|
+
// For now, return a basic text match implementation
|
|
70
|
+
const results = [];
|
|
71
|
+
const queryLower = query.toLowerCase();
|
|
72
|
+
for (const tool of this.tools) {
|
|
73
|
+
let score = 0;
|
|
74
|
+
const matchType = this.config.mode;
|
|
75
|
+
// Simple text matching (placeholder for BM25)
|
|
76
|
+
const searchText = [
|
|
77
|
+
tool.name,
|
|
78
|
+
tool.description,
|
|
79
|
+
...(tool.keywords ?? []),
|
|
80
|
+
...(tool.categories ?? []),
|
|
81
|
+
].join(' ').toLowerCase();
|
|
82
|
+
if (searchText.includes(queryLower)) {
|
|
83
|
+
score = 0.8;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// Partial word match
|
|
87
|
+
const queryWords = queryLower.split(/\s+/);
|
|
88
|
+
const matchCount = queryWords.filter(word => searchText.includes(word)).length;
|
|
89
|
+
score = matchCount / queryWords.length * 0.6;
|
|
90
|
+
}
|
|
91
|
+
// Filter by categories if specified
|
|
92
|
+
if (options.categories && options.categories.length > 0) {
|
|
93
|
+
const toolCategories = new Set(tool.categories ?? []);
|
|
94
|
+
const hasCategory = options.categories.some(c => toolCategories.has(c));
|
|
95
|
+
if (!hasCategory) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (score >= threshold) {
|
|
100
|
+
results.push({
|
|
101
|
+
toolId: tool.id,
|
|
102
|
+
score,
|
|
103
|
+
matchType,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Sort by score descending and limit
|
|
108
|
+
return results
|
|
109
|
+
.sort((a, b) => b.score - a.score)
|
|
110
|
+
.slice(0, limit);
|
|
111
|
+
}
|
|
112
|
+
async reindex() {
|
|
113
|
+
if (this.tools.length > 0) {
|
|
114
|
+
await this.index(this.tools);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Get current configuration */
|
|
118
|
+
getConfig() {
|
|
119
|
+
return { ...this.config };
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAoB;IAC1B,KAAK,GAAmB,EAAE,CAAC;IAC3B,WAAW,GAAG,KAAK,CAA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AAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxE,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,SAAS;gBACX,CAAC;YACH,CAAC;YAED,IAAI,KAAK,IAAI,SAAS,EAAE,CAAC;gBACvB,OAAO,CAAC,IAAI,CAAC;oBACX,MAAM,EAAE,IAAI,CAAC,EAAE;oBACf,KAAK;oBACL,SAAS;iBACV,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,qCAAqC;QACrC,OAAO,OAAO;aACX,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;aACjC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,gCAAgC;IAChC,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Score Normalization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Different search algorithms produce scores in different ranges:
|
|
5
|
+
* - BM25: 0 to ~25+ (unbounded, depends on corpus)
|
|
6
|
+
* - Cosine similarity: -1 to 1 (for vectors)
|
|
7
|
+
* - Orama vector search: 0 to 1 (already normalized)
|
|
8
|
+
*
|
|
9
|
+
* We normalize everything to 0-1 for consistent thresholding.
|
|
10
|
+
*/
|
|
11
|
+
import type { SearchResult } from '../types/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Normalize BM25 scores to 0-1 range.
|
|
14
|
+
*
|
|
15
|
+
* Uses min-max normalization within the result set.
|
|
16
|
+
* If all scores are the same, returns 1.0 for all.
|
|
17
|
+
*
|
|
18
|
+
* @param scores - Array of raw BM25 scores
|
|
19
|
+
* @returns Array of normalized scores (0-1)
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizeBM25Scores(scores: number[]): number[];
|
|
22
|
+
/**
|
|
23
|
+
* Normalize a single BM25 score using a sigmoid function.
|
|
24
|
+
* This is useful when you don't have the full result set.
|
|
25
|
+
*
|
|
26
|
+
* The sigmoid maps scores to (0, 1):
|
|
27
|
+
* - Low scores (~0-2) map to ~0.0-0.5
|
|
28
|
+
* - Medium scores (~2-10) map to ~0.5-0.9
|
|
29
|
+
* - High scores (~10+) map to ~0.9-1.0
|
|
30
|
+
*
|
|
31
|
+
* @param score - Raw BM25 score
|
|
32
|
+
* @param k - Steepness parameter (default: 5)
|
|
33
|
+
* @returns Normalized score (0-1)
|
|
34
|
+
*/
|
|
35
|
+
export declare function normalizeBM25Sigmoid(score: number, k?: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Normalize cosine similarity from [-1, 1] to [0, 1]
|
|
38
|
+
*
|
|
39
|
+
* @param similarity - Cosine similarity value (-1 to 1)
|
|
40
|
+
* @returns Normalized score (0-1)
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeCosineSimilarity(similarity: number): number;
|
|
43
|
+
/**
|
|
44
|
+
* Orama already returns vector scores in 0-1 range (distance-based).
|
|
45
|
+
* This function clamps to ensure valid range.
|
|
46
|
+
*
|
|
47
|
+
* @param score - Orama vector search score
|
|
48
|
+
* @returns Clamped score (0-1)
|
|
49
|
+
*/
|
|
50
|
+
export declare function normalizeOramaVectorScore(score: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Combine BM25 and vector scores using weighted average.
|
|
53
|
+
*
|
|
54
|
+
* @param bm25Score - Normalized BM25 score (0-1)
|
|
55
|
+
* @param vectorScore - Normalized vector score (0-1)
|
|
56
|
+
* @param weights - Weight configuration
|
|
57
|
+
* @returns Combined score (0-1)
|
|
58
|
+
*/
|
|
59
|
+
export declare function combineScores(bm25Score: number, vectorScore: number, weights: {
|
|
60
|
+
bm25: number;
|
|
61
|
+
vector: number;
|
|
62
|
+
}): number;
|
|
63
|
+
/**
|
|
64
|
+
* Reciprocal Rank Fusion (RRF) for combining ranked lists.
|
|
65
|
+
*
|
|
66
|
+
* RRF is a rank-based fusion method that doesn't require score normalization.
|
|
67
|
+
* It's useful when BM25 and vector scores are not directly comparable.
|
|
68
|
+
*
|
|
69
|
+
* Formula: score = sum(1 / (k + rank)) for each list the item appears in
|
|
70
|
+
*
|
|
71
|
+
* @param bm25Rank - Rank in BM25 results (1-indexed, null if not present)
|
|
72
|
+
* @param vectorRank - Rank in vector results (1-indexed, null if not present)
|
|
73
|
+
* @param k - Smoothing constant (default: 60, standard value)
|
|
74
|
+
* @returns RRF score (higher is better)
|
|
75
|
+
*/
|
|
76
|
+
export declare function reciprocalRankFusion(bm25Rank: number | null, vectorRank: number | null, k?: number): number;
|
|
77
|
+
/**
|
|
78
|
+
* Merge BM25 and vector results using weighted combination.
|
|
79
|
+
*
|
|
80
|
+
* Tools that appear in both result sets get combined scores.
|
|
81
|
+
* Tools that appear in only one set get their score weighted by that mode's weight.
|
|
82
|
+
*
|
|
83
|
+
* @param bm25Results - BM25 search results (normalized scores)
|
|
84
|
+
* @param vectorResults - Vector search results (normalized scores)
|
|
85
|
+
* @param weights - Weight configuration for combining
|
|
86
|
+
* @returns Merged and re-ranked results
|
|
87
|
+
*/
|
|
88
|
+
export declare function mergeHybridResults(bm25Results: SearchResult[], vectorResults: SearchResult[], weights: {
|
|
89
|
+
bm25: number;
|
|
90
|
+
vector: number;
|
|
91
|
+
}): SearchResult[];
|
|
92
|
+
/**
|
|
93
|
+
* Merge results using Reciprocal Rank Fusion.
|
|
94
|
+
*
|
|
95
|
+
* This method is rank-based rather than score-based,
|
|
96
|
+
* which can be more robust when score distributions differ significantly.
|
|
97
|
+
*
|
|
98
|
+
* @param bm25Results - BM25 search results (order matters, not scores)
|
|
99
|
+
* @param vectorResults - Vector search results (order matters, not scores)
|
|
100
|
+
* @param k - RRF smoothing constant
|
|
101
|
+
* @returns Merged and re-ranked results
|
|
102
|
+
*/
|
|
103
|
+
export declare function mergeWithRRF(bm25Results: SearchResult[], vectorResults: SearchResult[], k?: number): SearchResult[];
|
|
104
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../src/search/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAOtD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAc9D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,GAAE,MAAU,GAAG,MAAM,CAIzE;AAMD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/D;AAMD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACxC,MAAM,CAGR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,CAAC,GAAE,MAAW,GACb,MAAM,CASR;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,YAAY,EAAE,EAC3B,aAAa,EAAE,YAAY,EAAE,EA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