Getting Started
EMBD is a fast, cross-platform library for embedding text.
Installation
npm install embd
Usage
Session
A session is a single instance of a model used for inference.
A SessionManager is used to spawn an instance of any one of following the available models:
enum AvailableModels {
BAAI_SMALL_EN_v1_5, // 30MB
}
⚠️
Don't see the model you need? Send us an email!
The SessionManager has a single method, loadModel
, which returns a promise that resolves to a Result type (opens in a new tab).
class SessionManager {
async loadModel(
selectedModel: AvailableModels,
onLoaded: (result: any) => void,
onProgress: (progress: number) => void
): Promise<Result<InferenceSession, Error>>;
}
💡
Before calling any methods, you must call await initialize()
to ensure the
WASM module is loaded.
Worked example
import {
initialize,
SesssionManager,
AvailableModels,
} from "embd";
async function main() {
await initialize();
const session = await new SessionManager().loadModel(
AvailableModels.BAAI_SMALL_EN_v1_5,
() => {
console.log("Model loaded successfully");
},
(p: number) => {
console.log(`Loading: ${p}%`);
}
);
// Do something with the session
}
Check out the code for our demo page (opens in a new tab).