Skip to main content
Glama

search_vector_only

Search academic papers using semantic vector similarity to find relevant literature when keyword matching fails. Returns results based on conceptual meaning rather than exact text matches.

Instructions

纯向量搜索

仅使用向量相似度搜索,适合语义相关但关键词不匹配的场景。

Args: query: 搜索查询字符串 k: 返回结果数量,默认 10

Returns: 搜索结果列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
kNo

Implementation Reference

  • The main handler function for the 'search_vector_only' MCP tool, decorated with @mcp.tool(). It generates an embedding for the query, performs vector search using the database, formats results with snippets, distances, and similarities.
    @mcp.tool() def search_vector_only( query: str, k: int = 10, ) -> dict[str, Any]: """纯向量搜索 仅使用向量相似度搜索,适合语义相关但关键词不匹配的场景。 Args: query: 搜索查询字符串 k: 返回结果数量,默认 10 Returns: 搜索结果列表 """ try: # Note: This is synchronous, but for single use it's fine. # Could be asyncified if needed, but hybrid is sufficient. query_embedding = get_embedding(query) results = search_vector(query_embedding, k) formatted_results = [] for r in results: text = r["text"] snippet = text[:200] + "..." if len(text) > 200 else text formatted_results.append({ "chunk_id": r["chunk_id"], "doc_id": r["doc_id"], "page_start": r["page_start"], "page_end": r["page_end"], "snippet": snippet, "distance": r["distance"], "similarity": 1.0 - r["distance"], }) return { "query": query, "k": k, "results": formatted_results, } except Exception as e: return { "error": str(e), "query": query, "k": k, "results": [], }
  • Core helper function that executes the vector similarity search query against the PostgreSQL database using pgvector for cosine distance.
    def search_vector(query_embedding: list[float], limit: int = 50) -> list[dict[str, Any]]: """向量搜索 Args: query_embedding: 查询向量 limit: 返回结果数量 Returns: 搜索结果列表,包含 chunk_id, doc_id, page_start, page_end, text, distance """ # 将 embedding 转换为 pgvector 格式 embedding_str = "[" + ",".join(str(x) for x in query_embedding) + "]" sql = """ SELECT c.chunk_id, c.doc_id, c.page_start, c.page_end, c.text, ce.embedding <=> %s::vector as distance FROM chunks c JOIN chunk_embeddings ce ON c.chunk_id = ce.chunk_id ORDER BY distance ASC LIMIT %s """ return query_all(sql, (embedding_str, limit))
  • Top-level registration call in the main MCP server file that invokes register_search_tools(mcp), thereby registering the 'search_vector_only' tool among others.
    register_search_tools(mcp)
  • Function that defines and registers the search tools, including 'search_vector_only', using @mcp.tool() decorators.
    def register_search_tools(mcp: FastMCP) -> None:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/h-lu/paperlib-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server