simplevecdb.config

Environment configuration for SimpleVecDB.

Config

Configuration settings for SimpleVecDB, loaded from environment variables.

Attributes:

Name Type Description
EMBEDDING_MODEL str

The default embedding model repo id or alias.

EMBEDDING_CACHE_DIR str

Directory path for caching embedding models.

EMBEDDING_MODEL_REGISTRY dict[str, str]

Mapping of model aliases to repo ids.

EMBEDDING_MODEL_REGISTRY_LOCKED bool

If True, only allow listed models.

EMBEDDING_BATCH_SIZE int

Optimal batch size for embedding requests.

EMBEDDING_SERVER_MAX_REQUEST_ITEMS int

Max items per embedding request.

EMBEDDING_SERVER_API_KEYS set[str]

Set of valid API keys for the embedding server.

DATABASE_PATH str

Path to the SimpleVecDB database file.

SERVER_HOST str

Host address for the SimpleVecDB server.

SERVER_PORT int

Port number for the SimpleVecDB server.

Source code in src/simplevecdb/config.py
class Config:
    """
    Configuration settings for SimpleVecDB, loaded from environment variables.

    Attributes:
        EMBEDDING_MODEL: The default embedding model repo id or alias.
        EMBEDDING_CACHE_DIR: Directory path for caching embedding models.
        EMBEDDING_MODEL_REGISTRY: Mapping of model aliases to repo ids.
        EMBEDDING_MODEL_REGISTRY_LOCKED: If True, only allow listed models.
        EMBEDDING_BATCH_SIZE: Optimal batch size for embedding requests.
        EMBEDDING_SERVER_MAX_REQUEST_ITEMS: Max items per embedding request.
        EMBEDDING_SERVER_API_KEYS: Set of valid API keys for the embedding server.
        DATABASE_PATH: Path to the SimpleVecDB database file.
        SERVER_HOST: Host address for the SimpleVecDB server.
        SERVER_PORT: Port number for the SimpleVecDB server.
    """

    # Embedding Model
    EMBEDDING_MODEL: str = os.getenv("EMBEDDING_MODEL", "TaylorAI/bge-micro-v2")
    EMBEDDING_CACHE_DIR: str = os.getenv(
        "EMBEDDING_CACHE_DIR", str(Path.home() / ".cache" / "simplevecdb")
    )
    _registry_env = os.getenv("EMBEDDING_MODEL_REGISTRY")
    EMBEDDING_MODEL_REGISTRY: dict[str, str] = _parse_registry(
        _registry_env, EMBEDDING_MODEL
    )
    EMBEDDING_MODEL_REGISTRY_LOCKED: bool = _parse_bool_env(
        os.getenv("EMBEDDING_MODEL_REGISTRY_LOCKED"), True
    )
    # Auto-detect optimal batch size if not explicitly set
    _batch_size_env = os.getenv("EMBEDDING_BATCH_SIZE")
    EMBEDDING_BATCH_SIZE: int = (
        int(_batch_size_env)
        if _batch_size_env is not None
        else get_optimal_batch_size()
    )
    _request_limit_env = os.getenv("EMBEDDING_SERVER_MAX_REQUEST_ITEMS") or os.getenv(
        "EMBEDDING_SERVER_MAX_BATCH"
    )
    EMBEDDING_SERVER_MAX_REQUEST_ITEMS: int = (
        int(_request_limit_env) if _request_limit_env else max(32, EMBEDDING_BATCH_SIZE)
    )
    EMBEDDING_SERVER_API_KEYS: set[str] = _parse_api_keys(
        os.getenv("EMBEDDING_SERVER_API_KEYS")
    )

    # Database
    DATABASE_PATH: str = os.getenv("DATABASE_PATH", ":memory:")

    # Server
    SERVER_HOST: str = os.getenv(
        "SERVER_HOST", "127.0.0.1"
    )  # Localhost only by default
    SERVER_PORT: int = int(os.getenv("SERVER_PORT", "8000"))

    @classmethod
    def from_env(cls) -> "Config":
        """Return the module-level config instance.

        .. note::
            All ``Config`` attributes are evaluated at *class-definition*
            time when this module is first imported. Setting environment
            variables after import and calling ``Config.from_env()`` does
            **not** re-read them — the values you get are whatever the
            environment looked like at first import. Use the module-level
            ``config`` singleton; do not rely on this method to refresh
            values on demand.
        """
        return cls()

from_env() classmethod

Return the module-level config instance.

.. note:: All Config attributes are evaluated at class-definition time when this module is first imported. Setting environment variables after import and calling Config.from_env() does not re-read them — the values you get are whatever the environment looked like at first import. Use the module-level config singleton; do not rely on this method to refresh values on demand.

Source code in src/simplevecdb/config.py
@classmethod
def from_env(cls) -> "Config":
    """Return the module-level config instance.

    .. note::
        All ``Config`` attributes are evaluated at *class-definition*
        time when this module is first imported. Setting environment
        variables after import and calling ``Config.from_env()`` does
        **not** re-read them — the values you get are whatever the
        environment looked like at first import. Use the module-level
        ``config`` singleton; do not rely on this method to refresh
        values on demand.
    """
    return cls()