@tryhamster/gerbil 1.0.0-rc.11 → 1.0.0-rc.12
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 +28 -1
- package/dist/browser/index.d.ts +98 -1
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +311 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/cli.mjs +7 -7
- package/dist/cli.mjs.map +1 -1
- package/dist/frameworks/express.d.mts +1 -1
- package/dist/frameworks/express.mjs +1 -1
- package/dist/frameworks/fastify.d.mts +1 -1
- package/dist/frameworks/fastify.mjs +1 -1
- package/dist/frameworks/hono.d.mts +1 -1
- package/dist/frameworks/hono.mjs +1 -1
- package/dist/frameworks/next.d.mts +2 -2
- package/dist/frameworks/next.mjs +1 -1
- package/dist/frameworks/react.d.mts +1 -1
- package/dist/frameworks/react.d.mts.map +1 -1
- package/dist/frameworks/trpc.d.mts +1 -1
- package/dist/frameworks/trpc.mjs +1 -1
- package/dist/{gerbil-DoDGHe6Z.mjs → gerbil-BcWjCGtM.mjs} +83 -1
- package/dist/{gerbil-DoDGHe6Z.mjs.map → gerbil-BcWjCGtM.mjs.map} +1 -1
- package/dist/gerbil-CBQkuQ9i.mjs +4 -0
- package/dist/{gerbil-qOTe1nl2.d.mts → gerbil-E12cYLNi.d.mts} +51 -2
- package/dist/gerbil-E12cYLNi.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/ai-sdk.d.mts +57 -3
- package/dist/integrations/ai-sdk.d.mts.map +1 -1
- package/dist/integrations/ai-sdk.mjs +88 -2
- package/dist/integrations/ai-sdk.mjs.map +1 -1
- package/dist/integrations/langchain.d.mts +1 -1
- package/dist/integrations/langchain.mjs +1 -1
- package/dist/integrations/llamaindex.d.mts +1 -1
- package/dist/integrations/llamaindex.mjs +1 -1
- package/dist/integrations/mcp.d.mts +2 -2
- package/dist/integrations/mcp.mjs +4 -4
- package/dist/{mcp-kzDDWIoS.mjs → mcp-DXqxF7ri.mjs} +3 -3
- package/dist/{mcp-kzDDWIoS.mjs.map → mcp-DXqxF7ri.mjs.map} +1 -1
- package/dist/{one-liner-DxnNs_JK.mjs → one-liner-UtQX47IT.mjs} +2 -2
- package/dist/{one-liner-DxnNs_JK.mjs.map → one-liner-UtQX47IT.mjs.map} +1 -1
- package/dist/{repl-DGUw4fCc.mjs → repl-FjIaBVFD.mjs} +3 -3
- package/dist/skills/index.d.mts +6 -6
- package/dist/skills/index.d.mts.map +1 -1
- package/dist/skills/index.mjs +3 -3
- package/dist/{skills-DulrOPeP.mjs → skills-BmlseBpJ.mjs} +2 -2
- package/dist/{skills-DulrOPeP.mjs.map → skills-BmlseBpJ.mjs.map} +1 -1
- package/dist/{types-CiTc7ez3.d.mts → types-Bgb_89Bh.d.mts} +20 -2
- package/dist/types-Bgb_89Bh.d.mts.map +1 -0
- package/docs/ai-sdk.md +38 -1
- package/docs/browser.md +69 -0
- package/docs/embeddings.md +311 -0
- package/package.json +1 -1
- package/dist/gerbil-DJGqq7BX.mjs +0 -4
- package/dist/gerbil-qOTe1nl2.d.mts.map +0 -1
- package/dist/types-CiTc7ez3.d.mts.map +0 -1
package/dist/frameworks/hono.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as GerbilConfig } from "../types-
|
|
2
|
-
import { t as Gerbil } from "../gerbil-
|
|
1
|
+
import { c as GerbilConfig } from "../types-Bgb_89Bh.mjs";
|
|
2
|
+
import { t as Gerbil } from "../gerbil-E12cYLNi.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/frameworks/next.d.ts
|
|
5
5
|
|
package/dist/frameworks/next.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.mts","names":[],"sources":["../../src/frameworks/react.ts"],"sourcesContent":[],"mappings":";;;;AA+N2B,UA1MV,gBAAA,SAAyB,YA0Mf,CAAA;EAAc;EAEhC,QAAA,CAAA,EAAA,MAAA;EAAK;EAIE,WAAO,CAAA,EAAA,
|
|
1
|
+
{"version":3,"file":"react.d.mts","names":[],"sources":["../../src/frameworks/react.ts"],"sourcesContent":[],"mappings":";;;;AA+N2B,UA1MV,gBAAA,SAAyB,YA0Mf,CAAA;EAAc;EAEhC,QAAA,CAAA,EAAA,MAAA;EAAK;EAIE,WAAO,CAAA,EAAA,OAAU;;KAxMrB,eAAA;;uCAE2B,oBAAoB,QAAQ;;qCAG9B,oBAAoB;;;;SAMhD;;;;UAMC;;;;;;;iBASM,SAAA,WAAmB,mBAAwB;;;;KAuJ/C,OAAA;;;;UAKK,cAAA,SAAuB;;oBAEpB;;;;KAMR,aAAA;YACA;;;qBAGS,KAAA,CAAM,cAAc;;SAEhC;;;iBAIO,OAAA,WAAiB,iBAAsB"}
|
package/dist/frameworks/trpc.mjs
CHANGED
|
@@ -1156,6 +1156,88 @@ The JSON must conform to this schema: ${JSON.stringify(zodToJsonSchema(schema))}
|
|
|
1156
1156
|
return results;
|
|
1157
1157
|
}
|
|
1158
1158
|
/**
|
|
1159
|
+
* Compute cosine similarity between two vectors
|
|
1160
|
+
*
|
|
1161
|
+
* @example
|
|
1162
|
+
* ```ts
|
|
1163
|
+
* const sim = g.cosineSimilarity([1, 0, 0], [1, 0, 0]); // 1.0
|
|
1164
|
+
* const sim2 = g.cosineSimilarity([1, 0, 0], [0, 1, 0]); // 0.0
|
|
1165
|
+
* ```
|
|
1166
|
+
*/
|
|
1167
|
+
cosineSimilarity(a, b) {
|
|
1168
|
+
if (a.length !== b.length) throw new Error(`Vector dimensions must match: ${a.length} vs ${b.length}`);
|
|
1169
|
+
let dotProduct = 0;
|
|
1170
|
+
let normA = 0;
|
|
1171
|
+
let normB = 0;
|
|
1172
|
+
for (let i = 0; i < a.length; i++) {
|
|
1173
|
+
dotProduct += a[i] * b[i];
|
|
1174
|
+
normA += a[i] * a[i];
|
|
1175
|
+
normB += b[i] * b[i];
|
|
1176
|
+
}
|
|
1177
|
+
const magnitude = Math.sqrt(normA) * Math.sqrt(normB);
|
|
1178
|
+
if (magnitude === 0) return 0;
|
|
1179
|
+
return dotProduct / magnitude;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Compare similarity between two texts
|
|
1183
|
+
*
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```ts
|
|
1186
|
+
* const result = await g.similarity("Hello world", "Hi there");
|
|
1187
|
+
* console.log(result.score); // 0.85
|
|
1188
|
+
* ```
|
|
1189
|
+
*/
|
|
1190
|
+
async similarity(textA, textB, options = {}) {
|
|
1191
|
+
const startTime = performance.now();
|
|
1192
|
+
const [embedA, embedB] = await Promise.all([this.embed(textA, options), this.embed(textB, options)]);
|
|
1193
|
+
return {
|
|
1194
|
+
score: this.cosineSimilarity(embedA.vector, embedB.vector),
|
|
1195
|
+
textA,
|
|
1196
|
+
textB,
|
|
1197
|
+
totalTime: performance.now() - startTime
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Semantic search - find most similar texts from a corpus
|
|
1202
|
+
*
|
|
1203
|
+
* @example
|
|
1204
|
+
* ```ts
|
|
1205
|
+
* const results = await g.search("capital of France", [
|
|
1206
|
+
* "Paris is beautiful",
|
|
1207
|
+
* "London is in England",
|
|
1208
|
+
* "Dogs are pets"
|
|
1209
|
+
* ]);
|
|
1210
|
+
* // [{ text: "Paris is beautiful", score: 0.89, index: 0 }, ...]
|
|
1211
|
+
* ```
|
|
1212
|
+
*/
|
|
1213
|
+
async search(query, corpus, options = {}) {
|
|
1214
|
+
const { topK = corpus.length, ...embedOptions } = options;
|
|
1215
|
+
const queryEmbedding = await this.embed(query, embedOptions);
|
|
1216
|
+
return (await this.embedBatch(corpus, embedOptions)).map((doc, index) => ({
|
|
1217
|
+
text: doc.text,
|
|
1218
|
+
score: this.cosineSimilarity(queryEmbedding.vector, doc.vector),
|
|
1219
|
+
index
|
|
1220
|
+
})).sort((a, b) => b.score - a.score).slice(0, topK);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Find the nearest text to an embedding vector
|
|
1224
|
+
*
|
|
1225
|
+
* @example
|
|
1226
|
+
* ```ts
|
|
1227
|
+
* const embedding = (await g.embed("dog")).vector;
|
|
1228
|
+
* const match = await g.findNearest(embedding, ["cat", "car", "tree"]);
|
|
1229
|
+
* // { text: "cat", score: 0.85, index: 0 }
|
|
1230
|
+
* ```
|
|
1231
|
+
*/
|
|
1232
|
+
async findNearest(embedding, candidates, options = {}) {
|
|
1233
|
+
const { topK = candidates.length, ...embedOptions } = options;
|
|
1234
|
+
return (await this.embedBatch(candidates, embedOptions)).map((doc, index) => ({
|
|
1235
|
+
text: doc.text,
|
|
1236
|
+
score: this.cosineSimilarity(embedding, doc.vector),
|
|
1237
|
+
index
|
|
1238
|
+
})).sort((a, b) => b.score - a.score).slice(0, topK);
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1159
1241
|
* Get session stats
|
|
1160
1242
|
*/
|
|
1161
1243
|
getStats() {
|
|
@@ -1628,4 +1710,4 @@ The JSON must conform to this schema: ${JSON.stringify(zodToJsonSchema(schema))}
|
|
|
1628
1710
|
|
|
1629
1711
|
//#endregion
|
|
1630
1712
|
export { ResponseCache as a, getGlobalCache as c, resolveModel as i, BUILTIN_MODELS as n, clearGlobalCache as o, listBuiltinModels as r, configureGlobalCache as s, Gerbil as t };
|
|
1631
|
-
//# sourceMappingURL=gerbil-
|
|
1713
|
+
//# sourceMappingURL=gerbil-BcWjCGtM.mjs.map
|