Skip to content

[BUG] getEmbeddings() has no fallback when local model and API are both unavailable #142

Description

@Beyood

Description

getEmbeddings() in dist/lib/embeddings.js attempts to load a local ONNX embedding model first, then falls back to an API-based embedding endpoint. If both are unavailable (e.g., no internet access to download the model, API key not configured, or the API doesn't support embeddings), the function throws an error and succ remember / succ search operations fail entirely.

For users in restricted network environments (e.g., China where HuggingFace is blocked, or air-gapped systems), there is no graceful degradation path.

Impact

  • succ remember fails silently or with cryptic errors
  • Core memory/search functionality becomes unavailable
  • The only workaround is manually patching node_modules

Environment

  • SUCC version: 1.5.42
  • Network: HuggingFace blocked; no compatible embedding API endpoint available

Suggested Fix

Add a hash-based fallback embedding in getEmbeddings() at dist/lib/embeddings.js:

export async function getEmbeddings(texts) {
    let result;
    // try local mode
    result = await getLocalEmbeddings(texts).catch(() => null);
    if (result) return result;
    // try api mode
    result = await getApiEmbeddings(texts).catch(() => null);
    if (result) return result;
    // Fallback: hash-based embedding
    return texts.map(t => {
        const hash = createHash('sha256').update(t).digest();
        const vec = new Float32Array(384);
        for (let i = 0; i < 384; i++) {
            vec[i] = (hash[i % 32] - 128) / 256;
        }
        return vec;
    });
}

This ensures the core memory operations always work, even without semantic similarity. The hash-based vectors won't provide meaningful similarity search, but CRUD operations succeed without errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions