diff --git a/docs/core-components/vector-store.md b/docs/core-components/vector-store.md index bd3e652..da7c9e6 100644 --- a/docs/core-components/vector-store.md +++ b/docs/core-components/vector-store.md @@ -80,14 +80,14 @@ vectordb_new_pod = PineconeVectorDb( BeyondLLM currently integrates with Weaviate, a versatile and scalable vector database designed for high-performance similarity search and efficient management of vector embeddings. -#### Parameters for WeaviateVectorDb: +**Parameters:** * **url** : Specifies the URL of your Weaviate cluster. This is essential for connecting to the Weaviate instance where your embeddings will be stored. * **index\_name** : The name of the index within Weaviate where your embeddings will be organized and managed. * **api\_key** : The API key for authenticated access to your Weaviate instance. If not provided, the connection will be unauthenticated. * **additional\_headers** : Additional headers for the Weaviate request in JSON format. This is useful for custom configurations or additional authentication methods. -#### Code Example: +**Code Example:** ```python from beyondllm.vectordb import WeaviateVectorDb @@ -101,6 +101,34 @@ vectordb = WeaviateVectorDb( ) ``` +### 4. Qdrant + +[Qdrant](http://qdrant.tech) is an open-source, high-performance, vector search engine. It provides a production-ready service with a convenient API to store, search, and manage vectors with additional payload and extended filtering support. + +**Parameters:** + +* **collection** : Name of the collection to be used. If the collection doesn't exist, it is created automatically. +* **client** : An instance of [`qdrant_client.QdrantClient`](https://python-client.qdrant.tech/qdrant_client.qdrant_client) for interfacing with the Qdrant server. +* **llamaindex_kwargs** : Additional options to pass when instantiating [`llama_index.vector_stores.qdrant.QdrantVectorStore`](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/qdrant/#llama_index.vector_stores.qdrant.QdrantVectorStore). + +**Code Example:** + +```python +# Install dependencies with: +# $ pip install llama-index-vector-stores-qdrant + +from beyondllm.vectordb import QdrantVectorDb +from qdrant_client import QdrantClient + +vdb = QdrantVectorDb( + collection_name="my-collection-name", + client=QdrantClient(url="http://localhost:6333"), + llamaindex_kwargs={ + "batch_size": 64 + } +) +``` + ### **Integrating with BeyondLLM Retrievers:** VectorDB instances can be used with the auto\_retriever functionality provided by BeyondLLM, by simply passing instance within the auto\_retriever function to enable efficient retrieval from your Vector Store index: diff --git a/src/beyondllm/vectordb/__init__.py b/src/beyondllm/vectordb/__init__.py index fb646d0..8ccef2b 100644 --- a/src/beyondllm/vectordb/__init__.py +++ b/src/beyondllm/vectordb/__init__.py @@ -1,4 +1,5 @@ from .chroma import ChromaVectorDb from .pinecone import PineconeVectorDb from .weaviate import WeaviateVectorDb -from .redis import RedisVectorDb \ No newline at end of file +from .redis import RedisVectorDb +from .qdrant import QdrantVectorDb diff --git a/src/beyondllm/vectordb/qdrant.py b/src/beyondllm/vectordb/qdrant.py new file mode 100644 index 0000000..e18f3ab --- /dev/null +++ b/src/beyondllm/vectordb/qdrant.py @@ -0,0 +1,86 @@ +from typing import Any +from beyondllm.vectordb.base import VectorDbConfig +from dataclasses import dataclass, field +import warnings + +warnings.filterwarnings("ignore") +import subprocess, sys + + +@dataclass +class QdrantVectorDb: + """ + Vector store implementation using Qdrant - https://qdrant.tech/. + REQUIRES the `"llama-index-vector-stores-qdrant"` package. + + >>> from beyondllm.vectordb import QdrantVectorDb + >>> from qdrant_client import QdrantClient + + >>> vdb = QdrantVectorDb( + ... collection_name="my-collection-name", + ... client=QdrantClient(url="http://localhost:6333"), + ... llamaindex_kwargs={ + ... "batch_size": 64 + ... } + ... ) + """ + + client: Any + collection_name: str + llamaindex_kwargs: dict = field(default_factory=dict) + + def __post_init__(self): + try: + from llama_index.vector_stores.qdrant import QdrantVectorStore + + self.client: QdrantVectorStore + + except ImportError: + user_agree = input( + "The feature requires an additional package: llama-index-vector-stores-qdrant. Would you like to install it now? [y/n]: " + ) + if user_agree.lower() == "y": + subprocess.check_call( + [ + sys.executable, + "-m", + "pip", + "install", + "pip install llama-index-vector-stores-qdrant", + ] + ) + from llama_index.vector_stores.qdrant import QdrantVectorStore + else: + raise ImportError( + "The 'llama-index-vector-stores-qdrant' package couldn't be installed." + ) + + self.load() + + def load(self): + from llama_index.vector_stores.qdrant import QdrantVectorStore + + self.client = QdrantVectorStore( + collection_name=self.collection_name, + client=self.client, + **self.llamaindex_kwargs, + ) + return self.client + + def add(self, *args, **kwargs): + return self.client.add(*args, **kwargs) + + def stores_text(self, *args, **kwargs): + return self.client.stores_text(*args, **kwargs) + + def is_embedding_query(self, *args, **kwargs): + return self.client.is_embedding_query(*args, **kwargs) + + def query(self, *args, **kwargs): + return self.client.query(*args, **kwargs) + + @staticmethod + def load_from_kwargs(self, kwargs): + embed_config = VectorDbConfig(**kwargs) + self.config = embed_config + self.load()