servers.main
servers.main
Utilities for building and running the ClassifAI REST API.
This module provides functions for creating FastAPI applications and routers that expose VectorStore embedding and search functionality as REST API endpoints.
It also contains helpers for validating configuration and starting the API server.
Classes
| Name | Description |
|---|---|
| LogLevel | Valid levels of logs. |
LogLevel
servers.main.LogLevel()Valid levels of logs.
Functions
| Name | Description |
|---|---|
| get_router | Create and return a FastAPI APIRouter with search endpoints. |
| get_server | Create and return a FastAPI server with search endpoints. |
| is_valid_log_level | Check if str is valid log level. |
| 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 APIRouter with search endpoints.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| vector_stores | list[VectorStore] | A list of VectorStore objects, each responsible for handling embedding and search operations for a specific endpoint. | required |
| endpoint_names | list[str] | Endpoint names corresponding to the vector stores. | required |
Returns
| Name | Type | Description |
|---|---|---|
| APIRouter | fastapi.APIRouter: Router with initialized search endpoints. |
Raises
| Name | Type | Description |
|---|---|---|
| DataValidationError | If the input parameters are invalid. | |
| ConfigurationError | If one or more vector stores are invalid. |
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 VectorStore objects, each responsible for handling embedding and search operations for a specific endpoint. | required |
| endpoint_names | list[str] | Endpoint names corresponding to the VectorStore instances to expose. | required |
Returns
| Name | Type | Description |
|---|---|---|
| FastAPI | fastapi.FastAPI: A FastAPI server with initialized search endpoints. |
is_valid_log_level
servers.main.is_valid_log_level(value)Check if str is valid log level.
make_endpoints
servers.main.make_endpoints(main_router, vector_stores_dict)Create and register the different endpoints to your app.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| main_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,
host_ip='127.0.0.1',
log_level='warning',
demo_mode=False,
)Create and run a FastAPI server with search endpoints.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| vector_stores | list[VectorStore] | A list of VectorStore objects, each responsible for handling embedding and search operations for a specific endpoint. | required |
| endpoint_names | list[str] | Endpoint names corresponding to the VectorStore instances to expose. | required |
| port | int | The port on which the API server runs. Defaults to 8000. | 8000 |
| host_ip | str | The IP address on which the API server listens. Defaults to “127.0.0.1”. Note that “127.0.0.1” only accepts connections from the local machine. Use “0.0.0.0” to allow external connections. | '127.0.0.1' |
| log_level | str | The logging level for the Uvicorn server. Supported values are “critical”, “error”, “warning”, “info”, and “debug”. | 'warning' |
| demo_mode | bool | Whether to display demo server information in the OpenAPI documentation. | False |
Raises
| Name | Type | Description |
|---|---|---|
| DataValidationError | If the input parameters are invalid, for example if the port value is out of bounds. |