forked from innovacion/searchbox
Initial commit
This commit is contained in:
4
src/qdrant_mcp/__init__.py
Normal file
4
src/qdrant_mcp/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .main import mcp
|
||||
|
||||
def run():
|
||||
mcp.run(transport="sse")
|
||||
7
src/qdrant_mcp/config.py
Normal file
7
src/qdrant_mcp/config.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from pydantic import Field
|
||||
from vault_settings import VaultSettings
|
||||
|
||||
|
||||
class Settings(VaultSettings):
|
||||
url: str = Field(...)
|
||||
api_key: str | None = None
|
||||
35
src/qdrant_mcp/engine.py
Normal file
35
src/qdrant_mcp/engine.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from collections.abc import Sequence
|
||||
from typing import Any
|
||||
|
||||
from qdrant_client import AsyncQdrantClient, models
|
||||
|
||||
from .config import Settings
|
||||
from .models import SearchRow
|
||||
|
||||
|
||||
class QdrantEngine:
|
||||
def __init__(self) -> None:
|
||||
self.settings = Settings()
|
||||
self.client = AsyncQdrantClient(
|
||||
url=self.settings.url, api_key=self.settings.api_key
|
||||
)
|
||||
|
||||
async def semantic_search(
|
||||
self,
|
||||
embedding: Sequence[float] | models.NamedVector,
|
||||
collection: str,
|
||||
limit: int = 10,
|
||||
conditions: Any | None = None,
|
||||
threshold: float | None = None,
|
||||
) -> list[SearchRow]:
|
||||
points = await self.client.search(
|
||||
collection_name=collection,
|
||||
query_vector=embedding,
|
||||
query_filter=conditions,
|
||||
limit=limit,
|
||||
with_payload=True,
|
||||
with_vectors=False,
|
||||
score_threshold=threshold,
|
||||
)
|
||||
|
||||
return [SearchRow(chunk_id=str(point.id), score=point.score, payload=point.payload) for point in points if point.payload is not None]
|
||||
9
src/qdrant_mcp/main.py
Normal file
9
src/qdrant_mcp/main.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastmcp import FastMCP
|
||||
|
||||
from .engine import QdrantEngine
|
||||
|
||||
mcp = FastMCP("Qdrant MCP")
|
||||
|
||||
engine = QdrantEngine()
|
||||
|
||||
_ = mcp.tool(engine.semantic_search)
|
||||
7
src/qdrant_mcp/models.py
Normal file
7
src/qdrant_mcp/models.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from typing import Any
|
||||
from pydantic import BaseModel
|
||||
|
||||
class SearchRow(BaseModel):
|
||||
chunk_id: str
|
||||
score: float
|
||||
payload: dict[str, Any]
|
||||
Reference in New Issue
Block a user