mem0ai/mem0 · error
LLMReranker requires an LLM instance; RerankerFactory should
Error message
LLMReranker requires an LLM instance; RerankerFactory should always provide one for the llm_reranker provider.
What it means
Thrown by the LLMReranker constructor when it is instantiated without an LLM instance. The llm_reranker provider scores documents by prompting the configured LLM, so RerankerFactory is responsible for passing the memory instance's LLM as the second constructor argument. Seeing this error means the factory/reranker wiring was broken — it is effectively an internal invariant, not a user configuration error.
Source
Thrown at mem0-ts/src/oss/src/rerankers/llm.ts:24
Score the relevance on a scale from 0.0 to 1.0, where:
- 1.0 = Perfectly relevant and directly answers the query
- 0.8-0.9 = Highly relevant with good information
- 0.6-0.7 = Moderately relevant with some useful information
- 0.4-0.5 = Slightly relevant with limited useful information
- 0.0-0.3 = Not relevant or no useful information
Respond with only a single numerical score between 0.0 and 1.0. Do not include any explanation or additional text.`;
const MAX_INPUT_LEN = 4000;
export class LLMReranker implements Reranker {
private llm: LLM;
private topK?: number;
constructor(config: RerankerConfig, llm: LLM) {
if (!llm) {
throw new Error(
"LLMReranker requires an LLM instance; RerankerFactory should always provide one for the llm_reranker provider.",
);
}
this.llm = llm;
this.topK = config.topK;
}
async rerank(
query: string,
documents: string[],
topK?: number,
): Promise<RerankResult[]> {
if (documents.length === 0) return [];
const scored = await Promise.all(
documents.map(async (document, index) => {
try {
const rerankScore = await this.score(query, document);View on GitHub (pinned to 001c235229)
Solutions
- Let RerankerFactory construct the reranker via the Memory config (reranker: { provider: 'llm_reranker', config: { model: ... } }) so the LLM is injected
- If constructing directly, pass the LLM: new LLMReranker(config, memoryLLM)
- Update mem0ai to a matching version so factory and reranker signatures agree
Example fix
// before
const reranker = new LLMReranker({ topK: 5 }); // no LLM
// after
const reranker = new LLMReranker({ topK: 5 }, memoryLLM); Defensive patterns
Strategy: validation
Validate before calling
if (!llm) throw new Error('llm_reranker requires a configured LLM instance');
const reranker = new LLMReranker(config, llm); Type guard
const isLLM = (x: unknown): x is { generateResponse: (...a: unknown[]) => Promise<unknown> } =>
x != null && typeof (x as { generateResponse?: unknown }).generateResponse === 'function'; Prevention
- Always construct rerankers through RerankerFactory / the Memory config so the LLM is injected
- Keep mem0ai package versions aligned so factory and constructor signatures match
When it happens
Trigger: RerankerFactory.create('llm_reranker', config) being called without an LLM (e.g. an older mem0-ts version whose factory does not forward the LLM, or custom code instantiating LLMReranker directly with new LLMReranker(config) and omitting the llm argument).
Common situations: Using a custom or outdated RerankerFactory; writing a custom reranker integration that bypasses the factory; upgrading only part of the monorepo so the factory and reranker signatures disagree.
Related errors
- Unknown LLM provider: ${providerId}
- memory_id is required for update
- AWS Bedrock LLM failed: ${message}
- Azure OpenAI requires both API key and endpoint
- DeepSeek API key is required
AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15).
Data as JSON: /api/errors/4d4d0020c39169b6.
Report an issue: GitHub.