servers.main

servers.main

This module provides functionality for creating a start a restAPI service which allows a user to call the search methods of different VectorStore objects, from an api-endpoint.

These functions interact with the ClassifAI PackageIndexer modules VectorStore objects, such that their embed and search methods are exposed on restAPI endpoints, in a FastAPI restAPI service started with these functions.

Functions

Name Description
get_router Create and return a FastAPI router with search endpoints.
get_server Create and return a FastAPI server with search endpoints.
make_endpoints Create and register the different endpoints to your app.
run_server Create and run a FastAPI server with search endpoints.

get_router

servers.main.get_router(vector_stores, endpoint_names)

Create and return a FastAPI router with search endpoints.

Parameters

Name Type Description Default
vector_stores list[VectorStore] A list of vector store objects, each responsible for handling embedding and search operations for a specific endpoint. required
endpoint_names list[str] A list of endpoint names corresponding to the vector stores. required

Returns

Name Type Description
APIRouter APIRouter Router with intialized search endpoints

Raises

Name Type Description
DataValidationError If the input parameters are invalid.
ConfigurationError If a vector store is missing required methods.

get_server

servers.main.get_server(vector_stores, endpoint_names)

Create and return a FastAPI server with search endpoints.

Parameters

Name Type Description Default
vector_stores list[VectorStore] A list of vector store objects, each responsible for handling embedding and search operations for a specific endpoint. required
endpoint_names list[str] A list of endpoint names corresponding to the vector stores. required

Returns

Name Type Description
FastAPI FastAPI Server with intialized search endpoints

make_endpoints

servers.main.make_endpoints(router, vector_stores_dict)

Create and register the different endpoints to your app.

Parameters

Name Type Description Default
router APIRouter | FastAPI The FastAPI application instance. required
vector_stores_dict dict[str, VectorStore] The name of the endpoint to be created. required

run_server

servers.main.run_server(vector_stores, endpoint_names, port=8000)

Create and run a FastAPI server with search endpoints.

Parameters

Name Type Description Default
vector_stores list[VectorStore] A list of vector store objects, each responsible for handling embedding and search operations for a specific endpoint. required
endpoint_names list[str] A list of endpoint names corresponding to the vector stores. required
port int [optional] The port on which the API server will run. Defaults to 8000. 8000