lfnovo/open-notebook · warning · ValueError

Source '{input_data.source_id}' not found

Error message

Source '{input_data.source_id}' not found

What it means

ValueError raised inside the source embed command when Source.get(source_id) returns nothing. It is the precondition check at the start of the embed pipeline; caught by the command wrapper and reported as success=False.

Source

Thrown at commands/embedding_commands.py:329

    Flow:
    1. Load Source by ID
    2. DELETE existing source_embedding records for this source
    3. Detect content type from file path or content
    4. Chunk text using appropriate splitter
    5. Generate embeddings for all chunks in batches
    6. Bulk INSERT source_embedding records

    Retry Strategy:
    - Retries up to 5 times for transient failures (network, timeout, etc.)
    - Uses exponential-jitter backoff (1-60s)
    - Does NOT retry permanent failures (ValueError for validation errors)
    """

    async def embed() -> Tuple[Dict[str, Any], str]:
        # 1. Load source
        source = await Source.get(input_data.source_id)
        if not source:
            raise ValueError(f"Source '{input_data.source_id}' not found")

        if not source.full_text or not source.full_text.strip():
            raise ValueError(f"Source '{input_data.source_id}' has no text to embed")

        # 2. DELETE existing embeddings (idempotency)
        logger.debug(f"Deleting existing embeddings for source {input_data.source_id}")
        await repo_query(
            "DELETE source_embedding WHERE source = $source_id",
            {"source_id": ensure_record_id(input_data.source_id)},
        )

        # 3. Detect content type from file path if available
        file_path = source.asset.file_path if source.asset else None
        content_type = detect_content_type(source.full_text, file_path)
        logger.debug(f"Detected content type: {content_type.value}")

        # 4. Chunk text using appropriate splitter
        chunks = chunk_text(source.full_text, content_type=content_type)

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check the source still exists (Sources list / SurrealDB) before resubmitting
  2. If deleted, discard the job — nothing to embed
  3. Keep the worker (make worker-start) running so jobs don't pile up behind deletes
Defensive patterns

Strategy: validation

Validate before calling

source = await Source.get(source_id)
if not source:
    raise KeyError(f'source {source_id} does not exist')

Try / catch

result = await run_command('embed_source', {'source_id': sid})
if not result.output.get('success') and 'not found' in result.output.get('error', ''):
    return  # source deleted while job queued

Prevention

When it happens

Trigger: Submitting the embed_source command (source processing worker) with a source_id that was deleted before the async job ran, or an ID from a different database.

Common situations: User deletes a source while its embedding job is still queued (worker backlog), or the surreal-commands worker is processing stale jobs after a DB reset.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/e191f49773fbc392. Report an issue: GitHub.