{"record":{"id":"306af3badd57d5c8","repo":"langchain-ai/langchain","slug":"cleanup-should-be-one-of-incremental-full-s","errorCode":null,"errorMessage":"cleanup should be one of 'incremental', 'full', 'scoped_full' or None. Got {cleanup}.","messagePattern":"cleanup should be one of 'incremental', 'full', 'scoped_full' or None\\. Got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/indexing/api.py","lineNumber":416,"sourceCode":"        ValueError: If cleanup mode is incremental and source_id_key is None.\n        ValueError: If `VectorStore` does not have\n            \"delete\" and \"add_documents\" required methods.\n        ValueError: If source_id_key is not None, but is not a string or callable.\n        TypeError: If `vectorstore` is not a `VectorStore` or a DocumentIndex.\n        AssertionError: If `source_id` is None when cleanup mode is incremental.\n            (should be unreachable code).\n    \"\"\"\n    # Behavior is deprecated, but we keep it for backwards compatibility.\n    # # Warn only once per process.\n    if key_encoder == \"sha1\":\n        _warn_about_sha1()\n\n    if cleanup not in {\"incremental\", \"full\", \"scoped_full\", None}:\n        msg = (\n            f\"cleanup should be one of 'incremental', 'full', 'scoped_full' or None. \"\n            f\"Got {cleanup}.\"\n        )\n        raise ValueError(msg)\n\n    if (cleanup in {\"incremental\", \"scoped_full\"}) and source_id_key is None:\n        msg = (\n            \"Source id key is required when cleanup mode is incremental or scoped_full.\"\n        )\n        raise ValueError(msg)\n\n    destination = vector_store  # Renaming internally for clarity\n\n    # If it's a vectorstore, let's check if it has the required methods.\n    if isinstance(destination, VectorStore):\n        # Check that the Vectorstore has required methods implemented\n        methods = [\"delete\", \"add_documents\"]\n\n        for method in methods:\n            if not hasattr(destination, method):\n                msg = (\n                    f\"Vectorstore {destination} does not have required method {method}\"","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/indexing/api.py#L398-L434","documentation":"Raised in `index()` (langchain_core.indexing.api) when the `cleanup` argument is not one of the supported modes. Cleanup controls how stale documents are removed: 'incremental' and 'scoped_full' need per-source tracking, 'full' compares the entire index, and None disables cleanup. An unrecognized string (or wrong type) is rejected before any indexing work starts.","triggerScenarios":"Calling `index(vs, docs, rm, cleanup=\"upsert\")`, `cleanup=\"Incremental\"` (wrong case), `cleanup=\"all\"`, or passing a non-string like 1/True.","commonSituations":"Config-driven pipelines with free-text cleanup settings; copy from tutorials using older/imagined mode names; case-sensitivity mistakes from env vars.","solutions":["Use exactly one of: \"incremental\", \"full\", \"scoped_full\", or None.","Validate the config value against the allowed set at load time and fail fast with a clear message.","Remember \"full\" is expensive for large stores — prefer \"incremental\" with a source_id_key when possible."],"exampleFix":"# before\nindex(vs, docs, rm, cleanup=\"upsert\")\n\n# after\nindex(vs, docs, rm, cleanup=\"incremental\", source_id_key=\"source\")","handlingStrategy":"validation","validationCode":"VALID = {\"incremental\", \"full\", \"scoped_full\", None}\ncleanup = cleanup if cleanup in VALID else None\nindex(vs, docs, rm, cleanup=cleanup, **( {\"source_id_key\": \"source\"} if cleanup else {} ))","typeGuard":"def is_valid_cleanup(mode) -> bool:\n    return mode in {\"incremental\", \"full\", \"scoped_full\", None}","tryCatchPattern":null,"preventionTips":["Type cleanup as Literal['incremental','full','scoped_full'] | None in your config schema.","Normalize case and strip whitespace on config-sourced cleanup values."],"tags":["indexing","cleanup","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}