forked from innovacion/searchbox
Add testing
This commit is contained in:
7
src/vector_search_mcp/__init__.py
Normal file
7
src/vector_search_mcp/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from fastmcp.server.server import Transport
|
||||
|
||||
from .main import mcp
|
||||
|
||||
|
||||
def run(transport: Transport = "sse"):
|
||||
mcp.run(transport=transport)
|
||||
6
src/vector_search_mcp/config.py
Normal file
6
src/vector_search_mcp/config.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from vault_settings import VaultSettings
|
||||
|
||||
|
||||
class Settings(VaultSettings):
|
||||
url: str
|
||||
api_key: str | None = None
|
||||
40
src/vector_search_mcp/engine.py
Normal file
40
src/vector_search_mcp/engine.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from collections.abc import Sequence
|
||||
from typing import Any, final
|
||||
|
||||
from qdrant_client import AsyncQdrantClient, models
|
||||
|
||||
from .config import Settings
|
||||
from .models import SearchRow
|
||||
|
||||
|
||||
@final
|
||||
class QdrantEngine:
|
||||
def __init__(self) -> None:
|
||||
self.settings = Settings() # type: ignore[reportCallIssue]
|
||||
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/vector_search_mcp/main.py
Normal file
9
src/vector_search_mcp/main.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from fastmcp import FastMCP
|
||||
|
||||
from .engine import QdrantEngine
|
||||
|
||||
mcp = FastMCP("Vector Search MCP")
|
||||
|
||||
engine = QdrantEngine()
|
||||
|
||||
_ = mcp.tool(engine.semantic_search)
|
||||
9
src/vector_search_mcp/models.py
Normal file
9
src/vector_search_mcp/models.py
Normal file
@@ -0,0 +1,9 @@
|
||||
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