Updated default embedder
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/ai-utils",
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.2",
|
||||
"description": "AI Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -10,6 +10,8 @@ export type AbortablePromise<T> = Promise<T> & {
|
||||
export type AiOptions = {
|
||||
/** Path to models */
|
||||
path?: string;
|
||||
/** Embedding model */
|
||||
embedder?: string; // all-MiniLM-L6-v2, bge-small-en-v1.5, bge-large-en-v1.5
|
||||
/** Large language models, first is default */
|
||||
llm?: Omit<LLMRequest, 'model'> & {
|
||||
models: {[model: string]: AnthropicConfig | OllamaConfig | OpenAiConfig};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { pipeline } from '@xenova/transformers';
|
||||
import { parentPort } from 'worker_threads';
|
||||
|
||||
let model: any;
|
||||
let embedder: any;
|
||||
|
||||
parentPort?.on('message', async ({ id, text }) => {
|
||||
if(!model) model = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');
|
||||
const output = await model(text, { pooling: 'mean', normalize: true });
|
||||
parentPort?.on('message', async ({ id, text, model }) => {
|
||||
if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model);
|
||||
const output = await embedder(text, { pooling: 'mean', normalize: true });
|
||||
const embedding = Array.from(output.data);
|
||||
parentPort?.postMessage({ id, embedding });
|
||||
});
|
||||
|
||||
@@ -271,7 +271,7 @@ class LLM {
|
||||
return new Promise((resolve, reject) => {
|
||||
const id = this.embedId++;
|
||||
this.embedQueue.set(id, { resolve, reject });
|
||||
this.embedWorker?.postMessage({ id, text });
|
||||
this.embedWorker?.postMessage({ id, text, model: this.ai.options?.embedder || 'bge-small-en-v1.5' });
|
||||
});
|
||||
};
|
||||
const chunks = this.chunk(target, maxTokens, overlapTokens);
|
||||
|
||||
Reference in New Issue
Block a user