{"record":{"id":"6a52df279eeeaf7e","repo":"LykosAI/StabilityMatrix","slug":"index-is-not-loaded","errorCode":null,"errorMessage":"Index is not loaded","messagePattern":"Index is not loaded","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Models/TagCompletion/CompletionProvider.cs","lineNumber":381,"sourceCode":"        var availableTypes = new[]\n        {\n            (PromptExtraNetworkType.Lora, \"lora\"),\n            (PromptExtraNetworkType.LyCORIS, \"lyco\"),\n            (PromptExtraNetworkType.Embedding, \"embedding\"),\n        };\n\n        return availableTypes\n            .Where(type =>\n                type.Item1.GetStringValue().StartsWith(searchTerm, StringComparison.OrdinalIgnoreCase)\n            )\n            .Select(type => new ModelTypeCompletionData(type.Item2, type.Item1));\n    }\n\n    private IEnumerable<ICompletionData> GetCompletionTags(string searchTerm, int itemsCount, bool suggest)\n    {\n        if (searcher is null)\n        {\n            throw new InvalidOperationException(\"Index is not loaded\");\n        }\n\n        var timer = Stopwatch.StartNew();\n\n        var searchOptions = new SearchOptions\n        {\n            Term = searchTerm,\n            MaxItemCount = itemsCount,\n            SuggestWhenFoundStartsWith = suggest,\n        };\n\n        var result = searcher.Search(searchOptions);\n\n        // No results\n        if (result.ResultType == TrieNodeSearchResultType.NotFound)\n        {\n            Logger.Trace(\"No results for {Term}\", searchTerm);\n            return Array.Empty<ICompletionData>();","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Models/TagCompletion/CompletionProvider.cs#L363-L399","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the tag index is loaded (await the provider's LoadIndex/InitializeAsync) before requesting completions.","Verify the tag data file (e.g. tag CSV) exists and re-download if missing.","Check the provider's IsLoaded/ searcher state in code and return no completions until ready.","Enable the tag-completion option and let the background load finish before using the editor's completion UI."],"exampleFix":"// before\nvar completions = provider.GetCompletions(\"1gir\", 10);\n// after\nif (!provider.IsIndexLoaded)\n    await provider.LoadIndexAsync(tagsFilePath);\nvar completions = provider.GetCompletions(\"1gir\", 10);","handlingStrategy":"validation","validationCode":"if (!tagCompletionProvider.IsLoaded /* or searcher null */)\n    await tagCompletionProvider.LoadIndexAsync(tagsCsvPath);","typeGuard":"bool IndexReady(CompletionProvider p) => p.IsLoaded;","tryCatchPattern":"try { return provider.GetCompletions(term, count); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Index is not loaded\")\n{ return Enumerable.Empty<ICompletionData>(); } // degrade gracefully until index loads","preventionTips":["Load the tag index at app startup (or on first completion request) and await it.","Ship/download the tag data file with verification; retry load on failure.","Disable or gray out autocomplete UI until the provider reports the index as loaded."],"tags":["autocomplete","index","initialization"],"backgroundTag":"invalid-state-transition","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}