Back to all posts
memori-js

Embedding Architecture Refactor

1 min read

Embedding Architecture Refactor


Date: December 10, 2024 Topic: Core Architecture

Overview

We significantly refactored the Memori class to decouple it from a hard dependency on Google's GenAI for embeddings. This allows memori-js to be agnostic to the embedding provider, paving the way for OpenAI, HuggingFace, or local embedding models.

Key Changes

1. New Interface: EmbeddingProvider

We introduced a standard interface in src/core/types.ts that any embedding service must implement:

export interface EmbeddingProvider {
  embed(text: string): Promise<number[]>;
}

2. Configuration Updates

The Memori constructor now accepts two new optional parameters:

  • embedding: An instance of a class implementing EmbeddingProvider.

  • embeddingDimension: The size of the vector (defaulting to 768 for Google's models).

Impact

Developers can now bring their own "brain" to Memori. If you want to use a local ONNX model or a different API, you simply implement the adapter and pass it in.

const memori = new Memori({
  embedding: new LocalEmbedding(),
  embeddingDimension: 384,
});