Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, Query, HTTPException | |
app = FastAPI() | |
def search(query: str, n: int = Query(5, ge=1, le=10)): | |
""" | |
Endpoint for querying the search engine. | |
Args: | |
query (str): The search query. | |
n (int): Number of results to return (default: 5). | |
Returns: | |
dict: Query results. | |
""" | |
search_engine = app.state.search_engine | |
if not search_engine: | |
raise HTTPException(status_code=500, detail="Search engine not initialized.") | |
results = search_engine.most_similar(query, n) | |
return {"query": query, "results": results} | |