The Hugging Face reranker provider gives you access to thousands of reranking models available on the Hugging Face Hub. This includes popular models like BAAI’s BGE rerankers and other state-of-the-art cross-encoder models.
The TypeScript OSS SDK (mem0ai/oss) runs this reranker locally with Transformers.js, the same cross-encoder path as sentence_transformer, just a different default model. It executes ONNX weights, so the default is the ONNX mirror Xenova/bge-reranker-base. Point model at any ONNX-exported reranker on the Hub (a raw BAAI/bge-reranker-* PyTorch checkpoint will not load in this runtime).
pnpm add @huggingface/transformers
import { Memory } from "mem0ai/oss";const memory = new Memory({ reranker: { provider: "huggingface", config: { // model: "Xenova/bge-reranker-base", // default (ONNX) device: "cpu", // "cpu" | "wasm" | "webgpu" maxLength: 512, // max tokens per query-document pair normalize: true, // sigmoid-normalize logits to [0, 1] (default) topK: 5, }, },});const results = await memory.search("What are the user's interests?", { filters: { userId: "alice" }, rerank: true,});
batchSize and showProgressBar are accepted for parity with the Python SDK but are no-ops in the TypeScript runtime. trust_remote_code and model_kwargs are Python-only.
from mem0 import Memorym = Memory.from_config(config)# Add some memoriesm.add("I love hiking in the mountains", user_id="alice")m.add("Pizza is my favorite food", user_id="alice")m.add("I enjoy reading science fiction books", user_id="alice")# Search with rerankingresults = m.search( "What outdoor activities do I enjoy?", user_id="alice", rerank=True)for result in results["results"]: print(f"Memory: {result['memory']}") print(f"Score: {result['score']:.3f}")
# Process multiple queries efficientlyqueries = [ "What are my hobbies?", "What food do I like?", "What books interest me?"]results = []for query in queries: result = m.search(query, filters={"user_id": "alice"}, rerank=True) results.append(result)