Skip to content

Fix compatibility with the previous versions #15

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

Merged
merged 1 commit into from
Mar 5, 2025
Merged
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
5 changes: 5 additions & 0 deletions src/mcp_server_qdrant/embeddings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ async def embed_documents(self, documents: List[str]) -> List[List[float]]:
async def embed_query(self, query: str) -> List[float]:
"""Embed a query into a vector."""
pass

@abstractmethod
def get_vector_name(self) -> str:
"""Get the name of the vector for the Qdrant collection."""
pass
8 changes: 8 additions & 0 deletions src/mcp_server_qdrant/embeddings/fastembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ async def embed_query(self, query: str) -> List[float]:
None, lambda: list(self.embedding_model.query_embed([query]))
)
return embeddings[0].tolist()

def get_vector_name(self) -> str:
"""
Return the name of the vector for the Qdrant collection.
Important: This is compatible with the FastEmbed logic used before 0.6.0.
"""
model_name = self.embedding_model.model_name.split("/")[-1].lower()
return f"fast-{model_name}"
21 changes: 14 additions & 7 deletions src/mcp_server_qdrant/qdrant.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from typing import Optional

from qdrant_client import AsyncQdrantClient, models
Expand Down Expand Up @@ -40,12 +41,16 @@ async def _ensure_collection_exists(self):
sample_vector = await self._embedding_provider.embed_query("sample text")
vector_size = len(sample_vector)

# Use the vector name as defined in the embedding provider
vector_name = self._embedding_provider.get_vector_name()
await self._client.create_collection(
collection_name=self._collection_name,
vectors_config=models.VectorParams(
size=vector_size,
distance=models.Distance.COSINE,
),
vectors_config={
vector_name: models.VectorParams(
size=vector_size,
distance=models.Distance.COSINE,
)
},
)

async def store_memory(self, information: str):
Expand All @@ -59,12 +64,13 @@ async def store_memory(self, information: str):
embeddings = await self._embedding_provider.embed_documents([information])

# Add to Qdrant
vector_name = self._embedding_provider.get_vector_name()
await self._client.upsert(
collection_name=self._collection_name,
points=[
models.PointStruct(
id=hash(information), # Simple hash as ID
vector=embeddings[0],
id=uuid.uuid4().hex,
vector={vector_name: embeddings[0]},
payload={"document": information},
)
],
Expand All @@ -82,11 +88,12 @@ async def find_memories(self, query: str) -> list[str]:

# Embed the query
query_vector = await self._embedding_provider.embed_query(query)
vector_name = self._embedding_provider.get_vector_name()

# Search in Qdrant
search_results = await self._client.search(
collection_name=self._collection_name,
query_vector=query_vector,
query_vector=models.NamedVector(name=vector_name, vector=query_vector),
limit=10,
)

Expand Down
28 changes: 27 additions & 1 deletion src/mcp_server_qdrant/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import importlib.metadata
from typing import Optional

import click
Expand All @@ -11,6 +12,15 @@
from .qdrant import QdrantConnector


def get_package_version() -> str:
"""Get the package version using importlib.metadata."""
try:
return importlib.metadata.version("mcp-server-qdrant")
except importlib.metadata.PackageNotFoundError:
# Fall back to a default version if package is not installed
return "0.0.0"


def serve(
qdrant_url: Optional[str],
qdrant_api_key: Optional[str],
Expand Down Expand Up @@ -140,6 +150,13 @@ async def handle_tool_call(
required=True,
help="Collection name",
)
@click.option(
"--fastembed-model-name",
envvar="FASTEMBED_MODEL_NAME",
required=False,
help="FastEmbed model name",
default="sentence-transformers/all-MiniLM-L6-v2",
)
@click.option(
"--embedding-provider",
envvar="EMBEDDING_PROVIDER",
Expand All @@ -165,6 +182,7 @@ def main(
qdrant_url: Optional[str],
qdrant_api_key: str,
collection_name: Optional[str],
fastembed_model_name: Optional[str],
embedding_provider: str,
embedding_model: str,
qdrant_local_path: Optional[str],
Expand All @@ -175,6 +193,14 @@ def main(
"Exactly one of qdrant-url or qdrant-local-path must be provided"
)

# Warn if fastembed_model_name is provided, as this is going to be deprecated
if fastembed_model_name:
click.echo(
"Warning: --fastembed-model-name parameter is deprecated and will be removed in a future version. "
"Please use --embedding-provider and --embedding-model instead",
err=True,
)

async def _run():
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
server = serve(
Expand All @@ -190,7 +216,7 @@ async def _run():
write_stream,
InitializationOptions(
server_name="qdrant",
server_version="0.5.1",
server_version=get_package_version(),
capabilities=server.get_capabilities(
notification_options=NotificationOptions(),
experimental_capabilities={},
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.