Skip to content

Model indexes: OnIndexBuildFailure(Skip | Throw) and a public RebuildIndexAsync(name) #190

Open

Description

@CaffeinatedCoder

Since #175, a model-declared index (HasIndex / HasVectorIndex / HasSpatialIndex) added over existing documents is filled when the context opens. If a document can't be indexed (a vector dimension mismatch, or, with #176, a unique index over duplicates), the open throws and nothing is saved. Every later open fails the same way until the data is fixed or the index is removed from OnModelCreating, so the app can't recover without a code change.

Proposal (direction agreed in #175):

  • OnIndexBuildFailure(IndexBuildFailure.Skip | IndexBuildFailure.Throw), per index on the ModelBuilder or as a context-wide default. Throw is today's behaviour and the default. Skip builds the index from the documents that can be indexed. It needs a way to report what was left out (a log/metrics event or a list of ids), and a rule for what happens when such a document is later updated.
  • A public DocumentCollection.RebuildIndexAsync(string name, CancellationToken ct = default) that rebuilds one index from the documents through the swap-after-commit path from fix(vacuum): rebuild typed-collection indexes into fresh trees (#167) #170 (CreateUnregisteredCopy / ReplaceIndex). After fixing the data, an app can rebuild without a full VacuumAsync(RebuildIndexes = true).

Open questions: should Skip cover unique-constraint violations as well as values that can't be indexed? And should later writes to a skipped document fail, or be skipped too?

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

    Type

    No type

    Projects

    • Status
      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions