ruvnet/ruflo · error
embedBatch() expects an array of strings
Error message
embedBatch() expects an array of strings
What it means
RvfEmbeddingService.embedBatch() generates embeddings for a list of texts and refuses to run unless the argument is an array. The guard fires before any embedding work or cache lookups, so nothing is partially processed. It exists because the method immediately iterates `texts` in a for-of loop and caches per string, which would misbehave on a bare string or undefined.
Source
Thrown at v3/@claude-flow/embeddings/src/rvf-embedding-service.ts:214
// Store in caches
this.cache.set(text, normalized);
if (this.persistentCache) {
await this.persistentCache.set(text, normalized);
}
const latencyMs = performance.now() - startTime;
this.emitEvent({ type: 'embed_complete', text, latencyMs });
return { embedding: normalized, latencyMs };
}
/**
* Generate embeddings for multiple text strings.
*/
async embedBatch(texts: string[]): Promise<BatchEmbeddingResult> {
if (!Array.isArray(texts)) {
throw new Error('embedBatch() expects an array of strings');
}
this.emitEvent({ type: 'batch_start', count: texts.length });
const startTime = performance.now();
const embeddings: Float32Array[] = [];
let cacheHits = 0;
for (const text of texts) {
const cached = this.cache.get(text);
if (cached) {
embeddings.push(cached);
cacheHits++;
this.emitEvent({ type: 'cache_hit', text });
continue;
}
// Check persistent cacheView on GitHub (pinned to fa13ee4ad6)
Solutions
- Pass an array of strings: `await service.embedBatch(['hello world'])`
- For a single text, call the single-item API `embed(text)` instead
- Coerce iterables first: `embedBatch(Array.from(set))`
- Split pre-joined strings yourself: `embedBatch(csv.split(','))`
Example fix
// before const result = await service.embedBatch(longText); // after const result = await service.embedBatch([longText]); // or for one document: const single = await service.embed(longText);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!Array.isArray(texts)) {
texts = [texts]; // or throw your own clearer error
}
if (texts.some((t) => typeof t !== 'string')) {
throw new TypeError('texts must contain only strings');
} Type guard
const isStringArray = (v: unknown): v is string[] => Array.isArray(v) && v.every((t) => typeof t === 'string');
Prevention
- Type the parameter as string[] in your own wrappers so the compiler catches it
- Wrap single strings in brackets when migrating from embed() to embedBatch()
- Convert iterables with Array.from() before passing them
When it happens
Trigger: Calling `embedBatch('some text')` with a single string instead of an array; passing `undefined` because an optional variable was never set; passing a Set, Map values iterator, or generator instead of a real array (Array.isArray is false for iterables).
Common situations: Migrating code from the single-string `embed()` API to `embedBatch()` and forgetting to wrap the text in brackets; passing a CSV string like 'a,b,c' expecting it to be split; defaulting a parameter to undefined when the caller omits it.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Rating must be integer 1-5
- Can only resume paused agent
- signAttributionArtifact: privateKey must be 32 bytes (got ${
- browser/eval: script must not be empty
- Invalid target format: ${target}. Use agent:<id> or human:<i
AI-assisted analysis of ruvnet/ruflo@fa13ee4ad6 (2026-08-18).
Data as JSON: /api/errors/14baee2092c4d365.
Report an issue: GitHub.