From 2305c0916e009aac862f9cc5eabad0c51dbb05e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=81ukawski?= Date: Fri, 13 Dec 2024 17:16:00 +0100 Subject: [PATCH 1/2] Add another parameter to allow using local Qdrant mode --- src/mcp_server_qdrant/qdrant.py | 8 +++++--- src/mcp_server_qdrant/server.py | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/mcp_server_qdrant/qdrant.py b/src/mcp_server_qdrant/qdrant.py index b848045..5a9cc23 100644 --- a/src/mcp_server_qdrant/qdrant.py +++ b/src/mcp_server_qdrant/qdrant.py @@ -9,23 +9,25 @@ class QdrantConnector: :param qdrant_api_key: The API key to use for the Qdrant server. :param collection_name: The name of the collection to use. :param fastembed_model_name: The name of the FastEmbed model to use. + :param qdrant_local_path: The path to the storage directory for the Qdrant client, if local mode is used. """ def __init__( self, - qdrant_url: str, + qdrant_url: Optional[str], qdrant_api_key: Optional[str], collection_name: str, fastembed_model_name: str, + qdrant_local_path: Optional[str] = None, ): - self._qdrant_url = qdrant_url.rstrip("/") + self._qdrant_url = qdrant_url.rstrip("/") if qdrant_url else None self._qdrant_api_key = qdrant_api_key self._collection_name = collection_name self._fastembed_model_name = fastembed_model_name # For the time being, FastEmbed models are the only supported ones. # A list of all available models can be found here: # https://qdrant.github.io/fastembed/examples/Supported_Models/ - self._client = AsyncQdrantClient(qdrant_url, api_key=qdrant_api_key) + self._client = AsyncQdrantClient(location=qdrant_url, api_key=qdrant_api_key, path=qdrant_local_path) self._client.set_model(fastembed_model_name) async def store_memory(self, information: str): diff --git a/src/mcp_server_qdrant/server.py b/src/mcp_server_qdrant/server.py index fb8478a..897b77a 100644 --- a/src/mcp_server_qdrant/server.py +++ b/src/mcp_server_qdrant/server.py @@ -12,10 +12,11 @@ from .qdrant import QdrantConnector def serve( - qdrant_url: str, + qdrant_url: Optional[str], qdrant_api_key: Optional[str], collection_name: str, fastembed_model_name: str, + qdrant_local_path: Optional[str] = None, ) -> Server: """ Instantiate the server and configure tools to store and find memories in Qdrant. @@ -23,11 +24,12 @@ def serve( :param qdrant_api_key: The API key to use for the Qdrant server. :param collection_name: The name of the collection to use. :param fastembed_model_name: The name of the FastEmbed model to use. + :param qdrant_local_path: The path to the storage directory for the Qdrant client, if local mode is used. """ server = Server("qdrant") qdrant = QdrantConnector( - qdrant_url, qdrant_api_key, collection_name, fastembed_model_name + qdrant_url, qdrant_api_key, collection_name, fastembed_model_name, qdrant_local_path ) @server.list_tools() @@ -112,7 +114,7 @@ def serve( @click.option( "--qdrant-url", envvar="QDRANT_URL", - required=True, + required=False, help="Qdrant URL", ) @click.option( @@ -134,12 +136,23 @@ def serve( help="FastEmbed model name", default="sentence-transformers/all-MiniLM-L6-v2", ) +@click.option( + "--qdrant-local-path", + envvar="QDRANT_LOCAL_PATH", + required=False, + help="Qdrant local path", +) def main( - qdrant_url: str, + qdrant_url: Optional[str], qdrant_api_key: str, collection_name: Optional[str], fastembed_model_name: str, + qdrant_local_path: Optional[str], ): + # XOR of url and local path, since we accept only one of them + if not (bool(qdrant_url) ^ bool(qdrant_local_path)): + raise ValueError("Exactly one of qdrant-url or qdrant-local-path must be provided") + async def _run(): async with mcp.server.stdio.stdio_server() as (read_stream, write_stream): server = serve( @@ -147,6 +160,7 @@ def main( qdrant_api_key, collection_name, fastembed_model_name, + qdrant_local_path, ) await server.run( read_stream, From a620d011b099c72889a0dd11fde12eae61f60f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20=C5=81ukawski?= Date: Fri, 13 Dec 2024 17:41:47 +0100 Subject: [PATCH 2/2] Update README to include the new variable for local path --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d81c2a9..0d5626e 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,13 @@ by passing the `--fastembed-model-name` argument to the server. The configuration of the server can be also done using environment variables: -- `QDRANT_URL`: URL of the Qdrant server +- `QDRANT_URL`: URL of the Qdrant server, e.g. `http://localhost:6333` - `QDRANT_API_KEY`: API key for the Qdrant server - `COLLECTION_NAME`: Name of the collection to use - `FASTEMBED_MODEL_NAME`: Name of the FastEmbed model to use +- `QDRANT_LOCAL_PATH`: Path to the local Qdrant database + +You cannot provide `QDRANT_URL` and `QDRANT_LOCAL_PATH` at the same time. ## License