Skip to main content

cognee.config

Static class for configuring Cognee’s runtime settings. Setters change the settings for the current process only (unless set(..., persist=True) also writes the value to .env), and they last until overridden. Graph and vector engines are cached per set of connection settings, so an engine requested after a change uses the new values. When backend access control (ENABLE_BACKEND_ACCESS_CONTROL, on by default) gives a dataset its own databases, that dataset’s stored connection details are used instead of the global graph and vector settings. Use cognee.config.set(...) for supported runtime-safe settings inside a Python process. Cognee can also be configured through .env or process environment variables before import. Use those for process-level settings such as auth, logging, cache backend, storage backend, telemetry, API server settings, and deployment credentials. For the full environment variable reference and precedence rules, see Setup Configuration.

Configuration Types

set_llm_config() keys must match the internal attribute names on LLMConfig. The exact internal attributes name are displayed in the table below.
Other graph providers are accepted only after you register them with use_graph_adapter.
Community adapters such as qdrant and chromadb must be installed and registered with use_vector_adapter first.set_graph_database_provider() and set_vector_db_provider() accept any string. An unknown provider name raises OSError only when the graph or vector engine is created, not when the setter is called.
The set_*_config(dict) setters convert string values such as "true" or "4" to the field’s declared bool, int, or float type, and raise InvalidConfigAttributeError for an unknown key. set_embedding_dimensions() (also used for the embedding_dimensions key of set_embedding_config()) requires a positive integer and raises ValueError otherwise.

Reading configuration

get(key) returns the current value of any key set() accepts, and get_all() returns all of them as a dict. Both mask secret values (llm_api_key, embedding_api_key, vector_db_key) by default, keeping only the first three and last four characters as a hint (values of eight characters or fewer are masked entirely); pass reveal_secrets=True to get the raw value. get() raises InvalidConfigAttributeError for an unrecognized key.

Persisting a value to .env

set() normally only updates the in-process configuration. Pass persist=True to also write the resolved value into the .env file this process loaded, so it is picked up by the next process that resolves the same file. That target may be a file pinned with COGNEE_ENV_FILE or a .env found in a parent directory — see How .env Is Loaded. Only when no .env was resolved does it fall back to .env in the current working directory, creating it if missing. This is what cognee-cli config set does. When persisting, set() returns a dict describing where the value was written:
Without persist=True, set() returns None and changes nothing on disk.
Persisting a secret writes it in plaintext to the .env this process loaded, which may sit in a parent directory rather than the one you are running from. Check the returned path (or the resolved-.env line in the startup log) to see where it landed, keep that file out of version control, and restrict its permissions.
cognee.config.set(key, value) is not a free-form setter. Use it for supported runtime-safe settings such as LLMs, embeddings, graph/vector databases, chunking, model overrides, and root directories. Use .env, shell variables, deployment variables, or pre-import os.environ for process-level settings such as auth, logging, cache backend, storage backend, API server settings, telemetry, and cloud credentials.

All Configuration Methods