Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(ui): keep semantic search offered while the encoder switches

Josh Corbett6a9dbbbb94d0
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
index c6e9c608de..a6c7aa609a 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.test.ts
@@ -21,6 +21,7 @@ import {
deleteGalleryBoard,
deleteGalleryImages,
downloadGalleryArchive,
+ fetchImageIndexAvailability,
getGalleryImageByName,
getGalleryImagesByNames,
getGalleryVideoMetadata,
@@ -911,3 +912,33 @@ describe('gallery uploads', () => {
expect(new URLSearchParams(url.split('?')[1]).has('board_id')).toBe(false);
});
});
+
+describe('fetchImageIndexAvailability', () => {
+ beforeEach(() => {
+ mocks.apiFetchJson.mockReset();
+ });
+
+ it.each([
+ [
+ { enabled: true, projection: { state: 'ready' } },
+ { modelName: null, state: 'ready' },
+ ],
+ [
+ { enabled: false, model_name: 'clip', projection: { state: 'model_missing' } },
+ { modelName: 'clip', state: 'model_missing' },
+ ],
+ // A draining replacement must keep search offered and polled, not read as indexing turned off.
+ [
+ { enabled: false, model_name: null, projection: { state: 'computing' } },
+ { modelName: null, state: 'switching' },
+ ],
+ [
+ { enabled: false, model_name: null, projection: { state: 'disabled' } },
+ { modelName: null, state: 'disabled' },
+ ],
+ ])('reads %o as %o', async (body, availability) => {
+ mocks.apiFetchJson.mockResolvedValue(body);
+
+ await expect(fetchImageIndexAvailability(new AbortController().signal)).resolves.toEqual(availability);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
index 540645f66b..f1bd5d043f 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/backend.ts
@@ -838,7 +838,8 @@ export const searchGallerySemantic = async (
};
export interface ImageIndexAvailability {
- state: 'disabled' | 'model_missing' | 'ready';
+ /** `switching`: an installed replacement model starts once the retired one's work drains. */
+ state: 'disabled' | 'model_missing' | 'switching' | 'ready';
/** The configured embedding model's name; set only while it is missing. */
modelName: string | null;
}
@@ -846,11 +847,12 @@ export interface ImageIndexAvailability {
interface ImageIndexStatusBody {
enabled: boolean;
model_name?: string | null;
+ projection?: { state?: string };
}
/**
* Search requires indexed embeddings and their model, not map projection. model_name distinguishes a missing
- * configured model from a disabled index.
+ * configured model from a disabled index; an inactive index whose projection is computing is switching models.
*/
export const fetchImageIndexAvailability = async (signal: AbortSignal): Promise<ImageIndexAvailability> => {
const body = await apiFetchJson<ImageIndexStatusBody>('/api/v1/image_map/status', { signal });
@@ -858,10 +860,11 @@ export const fetchImageIndexAvailability = async (signal: AbortSignal): Promise<
if (body.enabled) {
return { modelName: null, state: 'ready' };
}
+ if (body.model_name) {
+ return { modelName: body.model_name, state: 'model_missing' };
+ }
- return body.model_name
- ? { modelName: body.model_name, state: 'model_missing' }
- : { modelName: null, state: 'disabled' };
+ return { modelName: null, state: body.projection?.state === 'computing' ? 'switching' : 'disabled' };
};
/** Kind-qualified refs retain relevance order for page hydration, range selection, and deletion neighbors. */
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts b/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
index b55cda06b1..432af33931 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/queries.test.ts
@@ -504,6 +504,9 @@ describe('imageIndexAvailabilityOptions', () => {
expect(pollFor({ data: { modelName: 'clip', state: 'model_missing' }, status: 'success' })).toBe(
IMAGE_INDEX_UNAVAILABLE_POLL_MS
);
+ expect(pollFor({ data: { modelName: null, state: 'switching' }, status: 'success' })).toBe(
+ IMAGE_INDEX_UNAVAILABLE_POLL_MS
+ );
expect(pollFor({ status: 'error' })).toBe(IMAGE_INDEX_UNAVAILABLE_POLL_MS);
expect(pollFor({ data: { modelName: null, state: 'ready' }, status: 'success' })).toBe(false);
expect(pollFor({ data: { modelName: null, state: 'disabled' }, status: 'success' })).toBe(false);
diff --git a/invokeai/frontend/webv2/src/features/gallery/data/queries.ts b/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
index 9d24f64951..aea400d7b3 100644
--- a/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
+++ b/invokeai/frontend/webv2/src/features/gallery/data/queries.ts
@@ -346,7 +346,9 @@ export const imageIndexAvailabilityOptions = () => {
},
queryKey: galleryKeys.imageIndexAvailability(owner),
refetchInterval: (query) =>
- query.state.status === 'error' || query.state.data?.state === 'model_missing'
+ query.state.status === 'error' ||
+ query.state.data?.state === 'model_missing' ||
+ query.state.data?.state === 'switching'
? IMAGE_INDEX_UNAVAILABLE_POLL_MS
: false,
staleTime: IMAGE_INDEX_STALE_MS,