Spaces:
Sleeping
Sleeping
File size: 1,301 Bytes
8a525cb 562ae95 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# Ingest script
# File: scripts/ingest.py
import yaml
import sys
from orchestrator.client import MCPClient
def main():
"""
Ingest papers for a given query into Chroma vector store via MCP.
Usage: python ingest.py "your search query"
"""
if len(sys.argv) < 2:
print("Usage: python ingest.py <query>")
sys.exit(1)
query = sys.argv[1]
cfg = yaml.safe_load(open("config.yaml"))
web = MCPClient(cfg['mcp_servers']['web_search'])
pubmed = MCPClient(cfg['mcp_servers']['pubmed'])
chroma = MCPClient(cfg['mcp_servers']['chroma'])
print(f"Ingesting papers for query: {query}")
results = []
try:
results += web.call("web_search.search", {"q": query})
except Exception as e:
print("Web search failed:", e)
try:
results += pubmed.call("metatool.query", {"source": "PubMed", "q": query})
except Exception as e:
print("PubMed search failed:", e)
for paper in results:
paper_id = paper.get('id')
text = paper.get('abstract', '')
meta = {"title": paper.get('title'), "authors": ",".join(paper.get('authors', []))}
chroma.call("chroma.insert", {"id": paper_id, "text": text, "metadata": meta})
print("Ingestion complete!")
if __name__ == "__main__":
main() |