Skip to content

Add background vector store indexing and proper HTTP 503 handling#75

Open
Sasyamerugu wants to merge 1 commit intosugarlabs:mainfrom
Sasyamerugu:background-vectorstore-indexing
Open

Add background vector store indexing and proper HTTP 503 handling#75
Sasyamerugu wants to merge 1 commit intosugarlabs:mainfrom
Sasyamerugu:background-vectorstore-indexing

Conversation

@Sasyamerugu
Copy link

Previously the vector store was built during server startup using agent.setup_vectorstore(settings.DOC_PATHS). This blocks the API startup when documents are large and prevents the server from serving requests until indexing is finished.

This change moves vector store construction into a background thread, allowing the API to start immediately while indexing runs asynchronously.

The /ask endpoint now checks whether the retriever has been initialized. If the vector store is still building, the endpoint returns HTTP 503 (Service Unavailable) indicating the service is temporarily unavailable.

Other endpoints such as /ask-llm and /ask-llm-prompted are unaffected, as they do not depend on the vector store and can serve requests normally while indexing is in progress.

Additionally, a bug was fixed where HTTPException responses (such as 503) were accidentally converted to HTTP 500 because they were caught by a generic exception handler. The handler now re-raises HTTPException to preserve the correct response status.

… initialization

Previously the vector store was built during server startup using
agent.setup_vectorstore(settings.DOC_PATHS). This blocks the API
startup when documents are large and prevents the server from serving
requests until indexing is finished.

This change moves vector store construction into a background thread,
allowing the API to start immediately while indexing runs asynchronously.

The /ask endpoint now checks whether the retriever has been initialized.
If the vector store is still building, the endpoint returns HTTP 503
(Service Unavailable) indicating the service is temporarily unavailable.

Other endpoints such as /ask-llm and /ask-llm-prompted are unaffected,
as they do not depend on the vector store and can serve requests
normally while indexing is in progress.

Additionally, a bug was fixed where HTTPException responses (such as
503) were accidentally converted to HTTP 500 because they were caught
by a generic exception handler. The handler now re-raises HTTPException
to preserve the correct response status.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant