Skip to main content
A minimal guide to pre-organizing a folder before it reaches your graph. Presort scans a directory without touching the files on disk, reports what is junk, duplicated, versioned, personal, or already in cognee, and then ingests the groups you approve — one dataset per group.

Before You Start

  • Complete Quickstart to understand basic operations
  • Ensure you have LLM Providers configured — the analyze phase is deterministic, but the apply phase runs cognify
  • Read Datasets — presort ingests each proposed group into its own dataset
  • Set PRESORT_FOLDER to the folder you want to scan, or let the script use ~/Downloads
  • Name that folder as a permitted scan root before running the script — the defaults are the working directory, the temp directory, and cognee’s own storage, so a folder under $HOME is always outside them: export COGNEE_ALLOWED_LOCAL_FILE_ROOTS="$HOME/Downloads". See Presort scan roots

Code in Action

The complete runnable script is on GitHub: examples/guides/presort_downloads.py.

What Just Happened

Step 1: Scan the Folder

dry_run="presort" turns remember() into an analyzer: it walks the folder, reads samples of the files, and returns a PresortReport instead of ingesting anything. Nothing on disk is moved, renamed, or deleted. The report is also saved to <SYSTEM_ROOT_DIRECTORY>/presort/<scan_id>.presort.json, so the analyze result survives a failed apply — report.report_path holds the exact location, or None when SYSTEM_ROOT_DIRECTORY is unset or on S3 and the report was not persisted.

Step 2: Review the Report

report.summary() is the at-a-glance view: file and junk counts, exact-duplicate clusters with the bytes they waste, version candidates, potential personal data, and a cognee_status breakdown of how many files are new, staged, or already cognified. report.groups holds the proposal itself — each group carries the dataset_name it would land in and the files it would take there.

Step 3: Set the Apply Decisions

The report is editable, and the apply phase reads these three fields off it. exclude_pii defaults to False, so setting it is what actually changes the run — it drops files with potential personal data. skip_duplicates is already on by default; it is spelled out to keep the decision visible. apply_groups narrows the run to the groups you name — here every group except code projects, which belong in a code graph rather than a document dataset.

Step 4: Apply the Report and Recall

Passing the report back to remember() runs the second phase: each approved group goes through the normal add → cognify chain into its own dataset, and you get back a {dataset_name: result} mapping. Ingestion is incremental, so re-running the script after adding a few files only processes what is new. From there the folder is ordinary cognee memory — recall() takes the dataset names as its scope.

Advanced Usage

The analyze phase needs no LLM or embedding configuration: junk filtering, duplicate detection, version candidates, and folder-based grouping are all deterministic. Pass use_llm=True to remember(folder, dry_run="presort", use_llm=True) for LLM content classification, deeper PII detection, and semantic grouping.The apply phase runs cognify and does need a configured LLM. Without one, presort degrades rather than fails: the deterministic scan still runs, use_llm is downgraded, and apply stages files with add() only — each reported as a warning on the report.
Every file’s name is checked for personal-data keywords such as passport or payslip. Text files also get a content scan: presort reads a sample of up to max_sample_bytes (64 KiB by default) and matches it against patterns for emails, phone numbers, IBANs, SSN-like numbers, card numbers, and API keys. Findings are potential personal data, since patterns can miss things or match things that aren’t PII. The samples stored in the report are always redacted.Presort scans the content of text files saved as UTF-8, and of UTF-16 or UTF-32 files that start with a byte-order mark (BOM). Windows editors write a BOM when they save as “Unicode”. Presort decodes these files with the encoding the BOM names, and the use_llm=True content classification and PII review read them the same way. UTF-16 or UTF-32 files without a BOM are treated as binary, so presort checks only their filename. To get their content scanned, re-save them as UTF-8 or with a BOM.
When you trust the defaults, remember(FOLDER, dry_run="presort", auto_apply=True) collapses both phases into one call instead of the two this guide makes — see auto_apply for what comes back.
cognee-cli remember <folder> --presort runs the same two phases from the shell, with --allow-root in place of the environment variable. The commands and their apply-time flags are in the CLI reference.

Datasets

How the datasets presort proposes organize documents, permissions, and processing.

remember()

Every option the two presort phases accept, including the apply overrides.