forked from innovacion/searchbox
The fastmcp server code is now an optional dependency that can be installed with the "mcp" extra. Core vector search functionality is available without the MCP server dependency.
32 lines
876 B
Python
32 lines
876 B
Python
import json
|
|
|
|
from fastembed import TextEmbedding
|
|
from fastmcp import Client
|
|
from mcp.types import TextContent
|
|
|
|
|
|
async def test_call_tool(embedding_model: TextEmbedding, run_mcp: str):
|
|
input = "Quien es el mas guapo?"
|
|
collection = "dummy_collection"
|
|
|
|
embedding: list[float] = list(embedding_model.embed(input))[0].tolist()
|
|
|
|
client = Client(run_mcp)
|
|
|
|
async with client:
|
|
name = "semantic_search"
|
|
body = {"embedding": embedding, "collection": collection}
|
|
result = await client.call_tool(name, body)
|
|
|
|
content_block = result.content[0]
|
|
|
|
assert isinstance(content_block, TextContent)
|
|
|
|
deserialized_result = json.loads(content_block.text)
|
|
|
|
top_result = deserialized_result[0]
|
|
|
|
assert top_result["chunk_id"] == "0"
|
|
assert top_result["score"] > 0.7
|
|
assert top_result["payload"] == {"text": "Rick es el mas guapo"}
|