Files
wehub-resource-sync 85742ab165
Deploy Documentation / deploy (push) Has been cancelled
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, latest, Python 3.13) (push) Has been cancelled
Dashboard / Chromatic (push) Has been cancelled
CPU Test / Lint - fast (push) Has been cancelled
CPU Test / Lint - next (push) Has been cancelled
CPU Test / Lint - slow (push) Has been cancelled
CPU Test / Lint - JavaScript (push) Has been cancelled
CPU Test / Build documentation (push) Has been cancelled
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Others, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Store, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Weave, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Others, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Store, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Utilities, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (JavaScript) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:44:17 +08:00

53 lines
1.4 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
# type: ignore
import pickle
import faiss
from fastmcp import FastMCP
from sentence_transformers import SentenceTransformer
index = faiss.read_index("data/index_hnsw_faiss_n32e40_tiny.index")
print("Index loaded successfully.")
model = SentenceTransformer("BAAI/bge-large-en-v1.5")
print("Model loaded successfully.")
# with open('/mnt/input/agent_lightning/nq_list.pkl', 'rb') as f:
with open("data/chunks_candidate_tiny.pkl", "rb") as f:
chunks = pickle.load(f)
print("Chunks loaded successfully.")
mcp = FastMCP(name="wiki retrieval mcp")
@mcp.tool(
name="retrieve",
description="retrieve relevant chunks from the wikipedia",
)
def retrieve(query: str) -> list:
"""
Retrieve relevant chunks from the Wikipedia dataset.
Args:
query (str): The query string to search for.
Returns:
list: A list of dictionaries containing the retrieved chunks and their metadata.
"""
top_k = 1 # Number of top results to return
embedding = model.encode([query], normalize_embeddings=True)
D, I = index.search(embedding, top_k)
results = []
for i in range(top_k):
if I[0][i] != -1:
chunk = chunks[I[0][i]]
results.append({"chunk": chunk, "chunk_id": int(I[0][i]), "distance": float(D[0][i])})
return results
if __name__ == "__main__":
mcp.run(transport="sse", host="127.0.0.1", port=8099)