LykosAI/StabilityMatrix · error · InvalidOperationException

Index is not loaded

Error message

Index is not loaded

What it means

GetCompletionTags() performs tag searches through a 'searcher' built when a tag index (e.g. Danbooru tags) is loaded. If the searcher is null the index was never loaded (or loading failed/was cancelled), so the method throws InvalidOperationException('Index is not loaded') rather than returning empty results.

Solutions

  1. Ensure the tag index is loaded (await the provider's LoadIndex/InitializeAsync) before requesting completions.
  2. Verify the tag data file (e.g. tag CSV) exists and re-download if missing.
  3. Check the provider's IsLoaded/ searcher state in code and return no completions until ready.
  4. Enable the tag-completion option and let the background load finish before using the editor's completion UI.

Example fix

// before
var completions = provider.GetCompletions("1gir", 10);
// after
if (!provider.IsIndexLoaded)
    await provider.LoadIndexAsync(tagsFilePath);
var completions = provider.GetCompletions("1gir", 10);
Defensive patterns

Strategy: validation

Validate before calling

if (!tagCompletionProvider.IsLoaded /* or searcher null */)
    await tagCompletionProvider.LoadIndexAsync(tagsCsvPath);

Type guard

bool IndexReady(CompletionProvider p) => p.IsLoaded;

Try / catch

try { return provider.GetCompletions(term, count); }
catch (InvalidOperationException ex) when (ex.Message == "Index is not loaded")
{ return Enumerable.Empty<ICompletionData>(); } // degrade gracefully until index loads

Prevention

When it happens

Trigger: Requesting autocomplete completions before calling the provider's index-loading routine (e.g. LoadIndex with the tag CSV), or after loading was skipped due to a missing tag file or disabled setting.

Common situations: Tag autocomplete enabled but the tags file was never downloaded; first app launch before background index build finished; provider constructed but InitializeAsync never awaited; index load failed silently on a missing/corrupt CSV.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/6a52df279eeeaf7e. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/Models/TagCompletion/CompletionProvider.cs:381

        var availableTypes = new[]
        {
            (PromptExtraNetworkType.Lora, "lora"),
            (PromptExtraNetworkType.LyCORIS, "lyco"),
            (PromptExtraNetworkType.Embedding, "embedding"),
        };

        return availableTypes
            .Where(type =>
                type.Item1.GetStringValue().StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)
            )
            .Select(type => new ModelTypeCompletionData(type.Item2, type.Item1));
    }

    private IEnumerable<ICompletionData> GetCompletionTags(string searchTerm, int itemsCount, bool suggest)
    {
        if (searcher is null)
        {
            throw new InvalidOperationException("Index is not loaded");
        }

        var timer = Stopwatch.StartNew();

        var searchOptions = new SearchOptions
        {
            Term = searchTerm,
            MaxItemCount = itemsCount,
            SuggestWhenFoundStartsWith = suggest,
        };

        var result = searcher.Search(searchOptions);

        // No results
        if (result.ResultType == TrieNodeSearchResultType.NotFound)
        {
            Logger.Trace("No results for {Term}", searchTerm);
            return Array.Empty<ICompletionData>();

View on GitHub (pinned to af93d6ef57)