Jokica17's picture
Added backend `app` module and core engine logic:
cd20a25
raw
history blame
612 Bytes
from fastapi import FastAPI, Query, HTTPException
app = FastAPI()
@app.get("/search")
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}