Compare commits

...

14 Commits

Author SHA1 Message Date
sweep-ai[bot] f24ac4047c Merge main into sweep/fix-vectorstoreindex-creation 2023-10-26 23:04:32 +00:00
sweep-ai[bot] ba38bf32b9 Merge main into sweep/fix-vectorstoreindex-creation 2023-10-26 22:42:55 +00:00
sweep-ai[bot] 8e1ac926c4 Merge main into sweep/fix-vectorstoreindex-creation 2023-10-26 22:06:56 +00:00
sweep-ai[bot] efa3d595eb Merge main into sweep/fix-vectorstoreindex-creation 2023-10-25 23:53:32 +00:00
sweep-ai[bot] 3c1d1ec517 Merge main into sweep/fix-vectorstoreindex-creation 2023-10-25 21:13:10 +00:00
sweep-ai[bot] 52acd1baf6 Merge main into sweep/fix-vectorstoreindex-creation 2023-10-25 19:54:20 +00:00
sweep-ai[bot] a41f010eed Sandbox run packages/core/src/storage/vectorStore/SimpleVectorStore.ts 2023-10-24 07:15:40 +00:00
sweep-ai[bot] 9bf5d6b091 Sandbox run packages/core/src/indices/vectorStore/VectorStoreIndex.ts 2023-10-24 07:14:00 +00:00
sweep-ai[bot] 32a482dcac feat: Updated packages/core/src/indices/vectorStor 2023-10-24 07:13:27 +00:00
sweep-ai[bot] 9c87edf5bf feat: Updated packages/core/src/indices/vectorStor 2023-10-24 07:05:37 +00:00
sweep-ai[bot] 00da69bb60 feat: Updated packages/core/src/indices/vectorStor 2023-10-24 06:53:31 +00:00
sweep-ai[bot] b8e6441209 feat: Updated packages/core/src/storage/vectorStor 2023-10-24 06:51:40 +00:00
sweep-ai[bot] 328e8c6b6e feat: Updated packages/core/src/storage/vectorStor 2023-10-24 06:34:02 +00:00
sweep-ai[bot] 9f8131d57a feat: Updated packages/core/src/indices/vectorStor 2023-10-24 06:32:21 +00:00
3 changed files with 41 additions and 1 deletions
@@ -11,6 +11,7 @@ import {
StorageContext,
storageContextFromDefaults,
} from "../../storage/StorageContext";
import { SimpleVectorStore } from "../../storage/vectorStore/SimpleVectorStore";
import { VectorStore } from "../../storage/vectorStore/types";
import {
BaseIndex,
@@ -219,6 +220,13 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
return index;
}
/**
* Creates a VectorStoreIndex from a VectorStore object.
* The VectorStore object must store text.
* @param vectorStore The VectorStore object to create the VectorStoreIndex from.
* @param serviceContext The ServiceContext to use.
* @returns A new VectorStoreIndex object.
*/
static async fromVectorStore(
vectorStore: VectorStore,
serviceContext: ServiceContext,
@@ -240,6 +248,26 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
return index;
}
/**
* Creates a VectorStoreIndex from a persistence path.
* The persistence path must point to a valid VectorStore object.
* @param persistPath The persistence path to create the VectorStoreIndex from.
* @returns A new VectorStoreIndex object.
*/
static async fromPersistPath(persistPath: string): Promise<VectorStoreIndex> {
const vectorStore = await SimpleVectorStore.fromPersistPath(persistPath);
const serviceContext = serviceContextFromDefaults({});
const storageContext = await storageContextFromDefaults({ vectorStore });
const index = await VectorStoreIndex.init({
nodes: [],
storageContext,
serviceContext,
});
return index;
}
asRetriever(options?: any): VectorIndexRetriever {
return new VectorIndexRetriever({ index: this, ...options });
}
@@ -6,8 +6,8 @@ import {
getTopKMMREmbeddings,
} from "../../Embedding";
import { BaseNode } from "../../Node";
import { GenericFileSystem, exists } from "../FileSystem";
import { DEFAULT_FS, DEFAULT_PERSIST_DIR } from "../constants";
import { exists, GenericFileSystem } from "../FileSystem";
import {
VectorStore,
VectorStoreQuery,
@@ -156,6 +156,17 @@ export class SimpleVectorStore implements VectorStore {
await fs.writeFile(persistPath, JSON.stringify(this.data));
}
async loadFromPersistPath(persistPath: string): Promise<VectorStore> {
const fs = this.fs;
let dirPath = path.dirname(persistPath);
if (!(await exists(fs, dirPath))) {
await fs.mkdir(dirPath);
}
let fileData = await fs.readFile(persistPath);
let dataDict = JSON.parse(fileData.toString());
return SimpleVectorStore.fromDict(dataDict);
}
static async fromPersistPath(
persistPath: string,
fs?: GenericFileSystem,
@@ -68,4 +68,5 @@ export interface VectorStore {
options?: any,
): Promise<VectorStoreQueryResult>;
persist(persistPath: string, fs?: GenericFileSystem): Promise<void>;
loadFromPersistPath(persistPath: string): Promise<VectorStore>;
}