Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,8 @@ dist-ssr
!src/backend/search_engine/index_builder/data/data.md
/src/backend/search_engine/index/bin/
src/backend/search_engine/models/IVFPQ.faiss
src/backend/search_engine/models/ltr_model.pt
src/backend/search_engine/models/neuspell-scrnn-probwordnoise
src/backend/search_engine/ltr/data
src/backend/search_engine/ltr/train/output
memory_log.txt
2 changes: 1 addition & 1 deletion local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ cleanup() {
}

trap cleanup EXIT
wait
wait
16 changes: 13 additions & 3 deletions src/backend/api/v1/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from backend.search_engine.semantic_search.train_vector_index import train_or_load_ivfpq
from backend.search_engine.spell_correction.spell_corrector import get_spell_corrector
from fastapi import FastAPI, HTTPException, Query, status
from fastapi import BackgroundTasks, FastAPI, HTTPException, Query, status
from fastapi.middleware.cors import CORSMiddleware

setup_logging(level=os.getenv("LOG_LEVEL", "INFO"))
Expand Down Expand Up @@ -56,17 +56,27 @@ async def search(
limit: Annotated[
int, Query(ge=1, le=500, description="Maximum number of results")
] = 10,
background_tasks: BackgroundTasks = BackgroundTasks(),
) -> SearchResults:
if app.state.inverted_index is None or app.state.spell_corrector is None:
if (
app.state.inverted_index is None
or app.state.spell_corrector is None
or app.state.embedding_model is None
or app.state.vector_index is None
):
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="Search index or spell corrector not loaded",
detail="One or more models not loaded",
)

try:
qe = QueryEngine(q)
results = qe.search_results(limit)

background_tasks.add_task(
qe.inverted_index.clear_cache
) # clear snippet cache to reduce memory consumption

return results
except InvalidOperatorError as e:
raise HTTPException(
Expand Down
Loading
Loading