Skip to main content

What is the add operation

add is the first step of the lower-level pipeline. It ingests text, files and URLs into a dataset and stores them, ready for cognify. remember runs it for you.

What happens under the hood

Streams input, computes a content hash, deduplicates, and persists the data plus metadata. Accepts text, file paths, and HTTP(S) URLs (fetched and routed by MIME type). URL fetches refuse private, loopback, link-local, carrier-grade NAT (100.64.0.0/10), reserved (0.0.0.0/8, 240.0.0.0/4, 198.18.0.0/15, all of 192.0.0.0/24), documentation, broadcast, multicast and unspecified addresses, IPv6 addresses outside global unicast (2000::/3) or in 2001::/23 or 6to4 (2002::/16), and IPv4-mapped IPv6 forms, using the same address table as repository clones. A URL input also needs ALLOW_HTTP_REQUESTS open (allowed when unset outside an HTTP server), checked before anything is written; a pipeline never given AddPipeline::with_repo_sources refuses URL inputs. The address check applies to IP-literal URLs, to hostnames that resolve only to such addresses, and to every redirect hop. A blocked URL fails at once with an invalid-URL error and is not retried. HTTP_PROXY / HTTPS_PROXY / ALL_PROXY (and NO_PROXY) are honoured; when a proxy is used, the proxy resolves the target hostname, so only IP-literal targets are checked. data rows are dataset-scoped: a new row gets a random uuid4 id, and re-adding content dedups only within the same dataset, owner and tenant (by content hash), so the same content in two datasets is two rows, and a re-add after delete gets a new id. Dataset ids stay deterministic (UUID5 of name, owner and tenant). Upgrading runs a migration that splits a row shared by several datasets into one row per dataset (the copies record the original id as legacy_id, and the bindings’ data records gain dataset_id and legacy_id); stop every writer before upgrading.

Loaders

Files are routed to a loader by their sniffed content type: the data row stores the sniffed original_extension / original_mime_type (a local .html file keeps its path’s), non-UTF-8 bytes routed to the text loader (for example a PNG named .txt) fail the add, and a file no loader claims (for example a .zip) fails with NoLoaderForFile instead of falling back to the text loader. AddParams::preferred_loaders is now honoured: its loader names (text_loader, pypdf_loader, image_loader, …) are tried in order before the default priority, and a name that is not registered is skipped. Images and audio are accepted: the image loader (vision LLM) and audio loader (Whisper, when the LLM provider has a transcriber) run at add, which stores the description or transcript and keeps the raw file in original_data_location. When the provider transcribes but its transcriber cannot be built (no API key, say), an audio add fails with audio needs a transcriber, which could not be built: … instead of an unsupported-type error. Re-adding the same audio into the same dataset reuses the stored transcript while it is still in storage (even with no transcriber configured any more), so sequential re-adds transcribe once. An add into another dataset, or over a row holding raw audio (as a URL add stores it), uses the transcript already stored for that file (see below); only a missing transcript is transcribed again. Two concurrent adds of the same new file can still both transcribe it. A fetched HTML page (URL add) is stored raw and read by text_loader; a local .html file is still text-extracted at add time. text_loader decodes strict UTF-8, keeps a BOM, and turns \r\n and a lone \r into \n. A CRLF text file keeps the content_hash of its original bytes, so re-adding it reuses its row, while its stored text_<hash>.txt, raw_content_hash, chunk text and chunk ids use LF. The CSV loader and the HTML loader’s plain-text fallback do not translate, but their stored text is a .txt file that cognify reads back through text_loader, so a \r\n kept in it (a quoted CSV cell, say) is chunked as \n, and a re-cognify changes those chunks and their embeddings. ExtractTextChunksPipeline translates stored text the same way before chunking. A loader’s stored text is reused and never overwritten, so CRLF text stored by an earlier version keeps being used, with its old raw_content_hash, by every new add of the same bytes in any dataset until every row that uses it is deleted (cognify still chunks it with LF). To store such files with LF, delete those rows and add the files again. Routing skips loaders that are not registered, in the default order as well as in preferred_loaders: a registry without the code loader reads a .py file with the text loader instead of failing with UnsupportedDocumentType. A file only an unregistered loader claims (an image without the image loader) still fails, naming that loader. Every file or URL add writes external_metadata {"_cognee": {"source_uri": <url or file:// URI>}} merged over the item’s own metadata, except a file under the directory a host names with AddPipeline::with_upload_root (its spooled client uploads), which records no source_uri unless the item’s metadata sets one. Pipeline: cognee-ingestion (AddPipeline).

Code files and repositories

A source file of one of enola’s languages (.c, .cpp, .cs, .go, .java, .js, .jsx, .kt, .php, .py, .rb, .rs, .scala, .swift, .ts, .tsx, … — loaders::code::SUPPORTED_CODE_EXTENSIONS) is claimed by its name, before the text loader, by code_loader (cognee_ingestion::loaders::code, registered as "code" in LoaderRegistry::default_registry). Its text is decoded as strict UTF-8 with universal newlines (\r\n and a lone \r become \n) and stored as code_<content_hash>.<ext lowercased> instead of text_<content_hash>.txt; loader_engine is code_loader, and the row’s system_metadata is stamped {"source": "code"} unless the item carries its own stamp. cognify reads the stamp to send the item down the per-file CODE route, which needs the enola binary: the file’s text is no longer chunked or embedded. This is a breaking change: such files used to be read by the text loader. preferred_loaders = ["text_loader"] keeps the old plain-text reading. A code-project directory is added as one repo manifest item plus its documents (see Adding a directory); its code files are covered by the manifest and never added one by one, so code_loader does not see them. add of a GitHub/GitLab repository URL (a repository root, or any http(s) URL ending in .git) shallow-clones it under code_graph.clones_dir (default ~/.cognee/repos) and resolves it like a local code project: one code-repo item, recording the credential-free URL as system_metadata.repo_url, plus the repository’s documents. AddParams::branch (bindings add option branch) clones another branch than the remote’s default, into a directory of its own; every branch of a URL shares the dataset’s one row, so adding the URL on another branch replaces that row’s code graph. Clones follow the ALLOW_HTTP_REQUESTS gate and need git on PATH; a host that wires no repo sources (AddPipeline::with_repo_sources) refuses every URL input, remote repositories included. See cognee-ingestion’s resolve_repo.

File storage

Stored files are named by content hash under data_root_directory: extracted text as text_<hash>.txt (a code file’s as code_<hash>.<ext>), a fetched page as text_<hash>.html, other fetched content as fetched_<hash>.<ext>, and an upload (DataInput::Binary) as it arrived, as <hash>/<file name>, which the row’s original_data_location points at as a file:// URI. The upload’s file name is the part of its name after the last / or \; an add fails with IngestionError::InvalidUploadName when that is empty, . or .., holds a NUL byte or is longer than 255 bytes. Rows from older builds that say binary://<name> are corrected when the same upload is added again. A stored file is shared by every row that points at it. Delete removes it, with an emptied <hash>/ folder, only once no row points at it any more, and a re-add that moves a row on to another file (say, the same upload under a new name) removes the file it left the same way. Fetched content is rewritten in place on a re-add (write, then rename), while a loader’s text keeps the first version stored: a later add of the same file, in any dataset, reuses it instead of running the loader (a transcription or image description) again. A path that would leave the storage root is refused. While an add runs, the files it stored are claimed, so a concurrent delete in another dataset keeps them until the add’s rows are saved (within one process). Rows from builds before this change point at random ab/cd/ folders; they keep working as they are. This is a breaking change for code that calls LocalStorage directly: store, store_stream_dyn and create_writer now write at the relative path they are given and return it, overwriting a file already there, and fail with StorageError::InvalidPath for a path outside the storage root.

Adding a directory

A directory path is resolved before anything is stored. A directory whose root carries a project marker (pyproject.toml, go.mod, package.json, Cargo.toml, .git, …) is a code project: it is added as one repo manifest item (a small JSON document naming the repository and its source files, stamped system_metadata.source = "code_repo") plus its document files (README.md, PDFs, images, …), each added on its own. A document file is one whose extension a registered built-in loader reads (LoaderRegistry::document_extensions() of the add’s registry): a file only an unregistered loader could read (a PDF in a build without a PDF loader, an image without an LLM), a video file, or a file only a custom loader reads is skipped instead of added and then failed. Hidden files, build directories (node_modules, target, …), binaries, audio and video, symlinks and Git LFS pointers are skipped; hidden and build directories are not walked, and an unreadable subdirectory or file is skipped with a warning. Without a usable LLM the documents are left out too: their routes need one, the code graph does not. Any other directory is added file by file. See cognee-ingestion’s code_repo. The manifest’s data id is pinned to (user, dataset, repository path), so re-adding a repository refreshes its one row instead of adding a row per version. A changed repository’s row takes the new content and loses its cognify marker, so the next cognify reloads its code graph; an unchanged re-add keeps the marker. cognee add on the CLI now resolves the LLM configuration on every add, not only for a directory, and fails without storing anything when it cannot be resolved (for example a misspelled LLM_PROVIDER) rather than treating it as “no LLM” and dropping a code project’s documents.

Cognify

The next pipeline step

Loaders & Chunkers

How files are read

Datasets

Where added data lives