diff --git a/.changeset/funny-mice-fail.md b/.changeset/funny-mice-fail.md new file mode 100644 index 0000000000000000000000000000000000000000..6055262e92c6741e1b79c4e4431e89d0cf0e2a29 --- /dev/null +++ b/.changeset/funny-mice-fail.md @@ -0,0 +1,6 @@ +--- +"llamaindex": minor +"docs": patch +--- + +chore: add qdrant readme diff --git a/apps/docs/docs/modules/documents_and_nodes.md b/apps/docs/docs/modules/documents_and_nodes.md index 443d1c983c852509b7a473f0ff17f9f55640ff05..d4a36ca6c28a947de076edf59ae74423ae47ff0b 100644 --- a/apps/docs/docs/modules/documents_and_nodes.md +++ b/apps/docs/docs/modules/documents_and_nodes.md @@ -1,5 +1,5 @@ --- -sidebar_position: 0 +sidebar_position: 1 --- # Documents and Nodes diff --git a/apps/docs/docs/modules/llm.md b/apps/docs/docs/modules/llm.md index fe53292a4c3209d25a3632809f783d60bc4e5485..6de5f42254f41ab5cbb5af3606f82b4354a5281e 100644 --- a/apps/docs/docs/modules/llm.md +++ b/apps/docs/docs/modules/llm.md @@ -1,5 +1,5 @@ --- -sidebar_position: 0 +sidebar_position: 1 --- # LLM diff --git a/apps/docs/docs/modules/vectorStores/_category_.yml b/apps/docs/docs/modules/vectorStores/_category_.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac980e1f1000f1f829d094501c9d796379a6833d --- /dev/null +++ b/apps/docs/docs/modules/vectorStores/_category_.yml @@ -0,0 +1,2 @@ +label: "Vector Stores" +position: 0 diff --git a/apps/docs/docs/modules/vectorStores/qdrant.md b/apps/docs/docs/modules/vectorStores/qdrant.md new file mode 100644 index 0000000000000000000000000000000000000000..6c86aaa6a215a1a28206e4f6852167243dbd4525 --- /dev/null +++ b/apps/docs/docs/modules/vectorStores/qdrant.md @@ -0,0 +1,88 @@ +# Qdrant Vector Store + +To run this example, you need to have a Qdrant instance running. You can run it with Docker: + +```bash +docker pull qdrant/qdrant +docker run -p 6333:6333 qdrant/qdrant +``` + +## Importing the modules + +```ts +import fs from "node:fs/promises"; +import { Document, VectorStoreIndex, QdrantVectorStore } from "llamaindex"; +``` + +## Load the documents + +```ts +const path = "node_modules/llamaindex/examples/abramov.txt"; +const essay = await fs.readFile(path, "utf-8"); +``` + +## Setup Qdrant + +```ts +const vectorStore = new QdrantVectorStore({ + url: "http://localhost:6333", + port: 6333, +}); +``` + +## Setup the index + +```ts +const document = new Document({ text: essay, id_: path }); + +const index = await VectorStoreIndex.fromDocuments([document], { + vectorStore, +}); +``` + +## Query the index + +```ts +const queryEngine = index.asQueryEngine(); + +const response = await queryEngine.query({ + query: "What did the author do in college?", +}); + +// Output response +console.log(response.toString()); +``` + +## Full code + +```ts +import fs from "node:fs/promises"; +import { Document, VectorStoreIndex, QdrantVectorStore } from "llamaindex"; + +async function main() { + const path = "node_modules/llamaindex/examples/abramov.txt"; + const essay = await fs.readFile(path, "utf-8"); + + const vectorStore = new QdrantVectorStore({ + url: "http://localhost:6333", + port: 6333, + }); + + const document = new Document({ text: essay, id_: path }); + + const index = await VectorStoreIndex.fromDocuments([document], { + vectorStore, + }); + + const queryEngine = index.asQueryEngine(); + + const response = await queryEngine.query({ + query: "What did the author do in college?", + }); + + // Output response + console.log(response.toString()); +} + +main().catch(console.error); +``` diff --git a/packages/core/src/storage/vectorStore/QdrantVectorStore.ts b/packages/core/src/storage/vectorStore/QdrantVectorStore.ts index d5764c5625ed242c64fc18c6a40c55d6469e0093..1e8afe1d6bdcafe284309db4a783bb9a2a9097df 100644 --- a/packages/core/src/storage/vectorStore/QdrantVectorStore.ts +++ b/packages/core/src/storage/vectorStore/QdrantVectorStore.ts @@ -54,11 +54,9 @@ export class QdrantVectorStore implements VectorStore { apiKey, batchSize, }: QdrantParams) { - if (!client && (!url || !apiKey)) { - if (!url || !apiKey || !collectionName) { - throw new Error( - "QdrantVectorStore requires url, apiKey and collectionName", - ); + if (!client && !url) { + if (!url || !collectionName) { + throw new Error("QdrantVectorStore requires url and collectionName"); } }