Skip to content

Source replacement retires relations backed by manual evidence with the same source ID #30

Closed

Description

@PRADDZY

Replacing a source retires relations supported by manually added evidence when the manual evidence has the same source_id. The relation then disappears from current lookups, although its history remains stored.

docs/inserting.md says: "Evidence added by hand always counts."

Reproduced on main at 8124bee74334e9a5555afa52ce2d05ffc93b89d4, using Python 3.13, Kuzu, and a deterministic extractor. No LLM is involved.

Install the checkout with python -m pip install -e '.[kuzu]', then run:

import asyncio
import tempfile

from selfgraph import Extraction, KuzuStore, SelfGraph


class EmptyExtractor:
    async def extract(self, document):
        return Extraction()


async def main():
    with tempfile.TemporaryDirectory() as tmp:
        store = KuzuStore(tmp + "/graph", buffer_pool_size=128 * 1024 * 1024)
        async with SelfGraph(store=store, extractor=EmptyExtractor()) as graph:
            ann = await graph.entities.create("Ann", "Person")
            acme = await graph.entities.create("Acme", "Company")
            rel = await graph.relations.create(
                ann.id, "WORKS_AT", acme.id, evidence=[{"source_id": "hr"}]
            )
            print("before:", await graph.relations.get(rel.id) is not None)
            result = await graph.insert.text(
                "The updated source contains no employment fact.",
                source_id="hr",
                replace_source=True,
            )
            print("after:", await graph.relations.get(rel.id) is not None)
            print("retired:", result.source_diff.retired)
            print("warnings:", [warning.code for warning in result.warnings])


asyncio.run(main())

Actual output:

before: True
after: False
retired: ['relation:a4b698967fceb2c72cc81f83']
warnings: ['fact_retired_by_source']

Expected: the relation stays current and source_diff.retired is empty. A manual assertion should not be withdrawn just because a document with the same source ID is ingested or replaced.

The Python and TypeScript implementations encode manual evidence as <source_id>:manual, but replace_source only accepts the incoming generated version for evidence sharing the replaced source ID. The same predicate appears in both SDKs:

I can send a small fix in both SDKs, with regressions for manual-only and mixed manual/generated support, while preserving generated-only retirement and removal of replaced passages. Please approve this issue if that approach fits.

Activity

  1. PRADDZY commented on Nov 15, 2026

    @PRADDZY
    ContributorAuthor

    The mirrored fix is ready at 583f4d5.

    Both new regressions fail before the fix in each SDK. With the fix, Kuzu checks pass:

    • Python: 354 passed, 19 skipped.
    • TypeScript: 236 passed, 13 skipped, including Python conformance.
    • Ruff check/format, TypeScript lint, typecheck and build pass.

    The four-file patch only adds the manual-evidence guard and mirrored regressions. Generated-only retirement, certification, and replacement of other supporting sources keep their existing behavior. The mixed-support test also checks that replaced passages stay hidden from current retrieval but remain available historically.

    I am holding the PR until this issue is approved, per CONTRIBUTING.md.

  2. added
    Hackathon
    on Nov 15, 2026
  3. arrry-hydraDB commented on Nov 15, 2026

    @arrry-hydraDB
    Collaborator

    /approved

    Reproduced on 0.2.1, go ahead.

  4. added
    approved-for-pr
    on Nov 15, 2026
  5. github-actions commented on Nov 15, 2026

    @github-actions

    Approved by @arrry-hydraDB. @PRADDZY or an assignee of this issue can now open a PR that links it with Closes #30 (max 3 open PRs at a time).

  6. arrry-hydraDB commented on Nov 20, 2026

    @arrry-hydraDB
    Collaborator

    @IronicRayquaza assigned you, continuing in #276.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Hackathonapproved-for-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions