You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
"""
|
|
routers/search.py — /search endpoint.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from core.database import get_pool
|
|
from models.requests import SearchRequest
|
|
from models.responses import SearchResponse
|
|
from services.embedder import EmbedService
|
|
from services.retriever import hybrid_search
|
|
from core.settings import Settings
|
|
|
|
router = APIRouter(prefix='/search', tags=['search'])
|
|
|
|
|
|
def _get_settings() -> Settings:
|
|
from main import app_settings
|
|
return app_settings
|
|
|
|
|
|
@router.post('', response_model=SearchResponse)
|
|
async def search(req: SearchRequest, settings: Settings = Depends(_get_settings)):
|
|
pool = await get_pool()
|
|
embedder = EmbedService(settings.ollama_url, settings.embedding_model)
|
|
embedding = await embedder.embed(req.query)
|
|
|
|
async with pool.acquire() as conn:
|
|
results, elapsed = await hybrid_search(
|
|
conn=conn,
|
|
query=req.query,
|
|
embedding=embedding,
|
|
limit=req.limit,
|
|
threshold=req.threshold,
|
|
tags=req.tags,
|
|
)
|
|
|
|
return SearchResponse(results=results, total=len(results), query_time_ms=elapsed)
|