Skip to content

feat: Qdrant vector store support #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions docs/core-components/vector-store.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/beyondllm/vectordb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .chroma import ChromaVectorDb
from .pinecone import PineconeVectorDb
from .weaviate import WeaviateVectorDb
from .redis import RedisVectorDb
from .redis import RedisVectorDb
from .qdrant import QdrantVectorDb
86 changes: 86 additions & 0 deletions src/beyondllm/vectordb/qdrant.py
Original file line number Diff line number Diff line change
@@ -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()