diff --git a/examples/astradb/README.md b/examples/astradb/README.md index ebbd21e24b9bbb749d2d4724eb69bc39e4ece7df..72dde55f019ffeaa730f170ebca75d0db3cbaf12 100644 --- a/examples/astradb/README.md +++ b/examples/astradb/README.md @@ -19,7 +19,7 @@ Here are two sample scripts which work well with the sample data in the Astra Po - `OPENAI_API_KEY`: Your OpenAI key 2. `cd` Into the `examples` directory -3. run `pnpm i` +3. run `npm i` ## Load the data diff --git a/examples/astradb/load.ts b/examples/astradb/load.ts index ece5d867895adf5d918007f497dd454999efb610..8e62d3180aa8ef16ecac3029663d26daa04ed0cd 100644 --- a/examples/astradb/load.ts +++ b/examples/astradb/load.ts @@ -1,7 +1,9 @@ -import { VectorStoreIndex } from "../../packages/core/src/indices/vectorStore/VectorStoreIndex"; -import { PapaCSVReader } from "../../packages/core/src/readers/CSVReader"; -import { storageContextFromDefaults } from "../../packages/core/src/storage"; -import { AstraDBVectorStore } from "../../packages/core/src/storage/vectorStore/AstraDBVectorStore"; +import { + AstraDBVectorStore, + PapaCSVReader, + storageContextFromDefaults, + VectorStoreIndex, +} from "llamaindex"; const collectionName = "movie_reviews"; diff --git a/examples/astradb/query.ts b/examples/astradb/query.ts index b9c08982eece9c9ce893f529fd7916d024f5a3e0..1ed39033d646e8cf287f5c7a0c4c69298f234ac5 100644 --- a/examples/astradb/query.ts +++ b/examples/astradb/query.ts @@ -1,8 +1,10 @@ -import { serviceContextFromDefaults } from "../../packages/core/src/ServiceContext"; -import { VectorStoreIndex } from "../../packages/core/src/indices/vectorStore/VectorStoreIndex"; -import { AstraDBVectorStore } from "../../packages/core/src/storage/vectorStore/AstraDBVectorStore"; +import { + AstraDBVectorStore, + serviceContextFromDefaults, + VectorStoreIndex, +} from "llamaindex"; -const collectionName = "movie_reviews"; +const collectionName = "movie_reviews_2"; async function main() { try { diff --git a/packages/core/src/storage/index.ts b/packages/core/src/storage/index.ts index 96f8743be6e564594ba4c1d662d536d8f33a6edc..0621dc172af3c73b528f23c0f9a104976bdda7df 100644 --- a/packages/core/src/storage/index.ts +++ b/packages/core/src/storage/index.ts @@ -7,6 +7,7 @@ export { SimpleIndexStore } from "./indexStore/SimpleIndexStore"; export * from "./indexStore/types"; export { SimpleKVStore } from "./kvStore/SimpleKVStore"; export * from "./kvStore/types"; +export { AstraDBVectorStore } from "./vectorStore/AstraDBVectorStore"; export { MongoDBAtlasVectorSearch } from "./vectorStore/MongoDBAtlasVectorStore"; export { SimpleVectorStore } from "./vectorStore/SimpleVectorStore"; export * from "./vectorStore/types"; diff --git a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts index 04cb8c26f253ca8df40553424a71c3653c0d6346..37019ad0ae1c7210bcef07fb7b4d9a34c310d1bb 100644 --- a/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts +++ b/packages/core/src/storage/vectorStore/AstraDBVectorStore.ts @@ -13,11 +13,16 @@ export class AstraDBVectorStore implements VectorStore { astraDBClient: AstraDB; collection: Collection | undefined; - constructor() { - const token = process.env.ASTRA_DB_APPLICATION_TOKEN; - const dbId = process.env.ASTRA_DB_ID; - const region = process.env.ASTRA_DB_REGION; - const keyspace = process.env.ASTRA_DB_NAMESPACE; + constructor(params?: { + token: string; + dbId: string; + region: string; + keyspace: string; + }) { + const token = params?.token ?? process.env.ASTRA_DB_APPLICATION_TOKEN; + const dbId = params?.dbId ?? process.env.ASTRA_DB_ID; + const region = params?.region ?? process.env.ASTRA_DB_REGION; + const keyspace = params?.keyspace ?? process.env.ASTRA_DB_NAMESPACE; if (!dbId) { throw new Error("Must specify ASTRA_DB_ID via env variable.");