Skip to content
Snippets Groups Projects
Commit 20395098 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by Marcus Schiesser
Browse files

fix: bugs with persisting and loading image vector stores

parent 420f2dde
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ export class ClipEmbedding extends MultiModalEmbedding {
const loadedImage = await readImage(image);
const imageInputs = await (await this.getProcessor())(loadedImage);
const { image_embeds } = await (await this.getVisionModel())(imageInputs);
return image_embeds.data;
return Array.from(image_embeds.data);
}
async getTextEmbedding(text: string): Promise<number[]> {
......
......@@ -66,7 +66,8 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
this.indexStore = init.indexStore;
this.vectorStore = init.vectorStore ?? init.storageContext.vectorStore;
this.embedModel = init.serviceContext.embedModel;
this.imageVectorStore = init.imageVectorStore;
this.imageVectorStore =
init.imageVectorStore ?? init.storageContext.imageVectorStore;
if (this.imageVectorStore) {
this.imageEmbedModel = new ClipEmbedding();
}
......@@ -219,6 +220,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
static async fromVectorStore(
vectorStore: VectorStore,
serviceContext: ServiceContext,
imageVectorStore?: VectorStore,
) {
if (!vectorStore.storesText) {
throw new Error(
......@@ -226,7 +228,10 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
);
}
const storageContext = await storageContextFromDefaults({ vectorStore });
const storageContext = await storageContextFromDefaults({
vectorStore,
imageVectorStore,
});
const index = await this.init({
nodes: [],
......
......@@ -11,12 +11,14 @@ export interface StorageContext {
docStore: BaseDocumentStore;
indexStore: BaseIndexStore;
vectorStore: VectorStore;
imageVectorStore?: VectorStore;
}
type BuilderParams = {
docStore?: BaseDocumentStore;
indexStore?: BaseIndexStore;
vectorStore?: VectorStore;
imageVectorStore?: VectorStore;
persistDir?: string;
fs?: GenericFileSystem;
};
......@@ -25,6 +27,7 @@ export async function storageContextFromDefaults({
docStore,
indexStore,
vectorStore,
imageVectorStore,
persistDir,
fs,
}: BuilderParams): Promise<StorageContext> {
......@@ -51,5 +54,6 @@ export async function storageContextFromDefaults({
docStore,
indexStore,
vectorStore,
imageVectorStore,
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment