c889a57b6b
Test Suites / Build CI Environment (push) Has been cancelled
Test Suites / Basic Tests (push) Has been cancelled
Test Suites / End-to-End Tests (push) Has been cancelled
Test Suites / CLI Tests (push) Has been cancelled
Test Suites / Slow End-to-End Tests (push) Has been cancelled
Test Suites / Graph Database Tests (push) Has been cancelled
Test Suites / Vector DB Tests (push) Has been cancelled
Test Suites / Temporal Graph Test (push) Has been cancelled
Test Suites / Search Test on Different DBs (push) Has been cancelled
Test Suites / Example Tests (push) Has been cancelled
Test Suites / Notebook Tests (push) Has been cancelled
Test Suites / OS and Python Tests Ubuntu (push) Has been cancelled
Test Suites / OS and Python Tests Extended (push) Has been cancelled
Test Suites / LLM Test Suite (push) Has been cancelled
Test Suites / S3 File Storage Test (push) Has been cancelled
Test Suites / Run Integration Tests (push) Has been cancelled
Test Suites / MCP Tests (push) Has been cancelled
Test Suites / Docker Compose Test (push) Has been cancelled
Test Suites / Docker CI test (push) Has been cancelled
Test Suites / Relational DB Migration Tests (push) Has been cancelled
Test Suites / Distributed Cognee Test (push) Has been cancelled
Test Suites / DB Examples Tests (push) Has been cancelled
Test Suites / Test Completion Status (push) Has been cancelled
Test Suites / Claude Code Review (push) Has been cancelled
Test Suites / basic checks (push) Has been cancelled
build | Build and Push Cognee MCP Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
build | Build and Push Docker Image to dockerhub / docker-build-and-push (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.11) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Core Functionality (3.12) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (kuzu, kuzu) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges with Different Graph Databases (neo4j, neo4j) (push) Has been cancelled
Weighted Edges Tests / Test Weighted Edges Examples (push) Has been cancelled
Weighted Edges Tests / Code Quality for Weighted Edges (push) Has been cancelled
82 lines
3.0 KiB
Python
82 lines
3.0 KiB
Python
"""Command-line interface: argument definitions and default resolution.
|
|
|
|
Kept separate so analyze.py reads as pure orchestration.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from corpus import DEFAULT_MAX_CHUNK_SIZE
|
|
|
|
DESCRIPTION = "Estimate the token cost of cognee memory vs. full-context prompting."
|
|
|
|
|
|
def parse_args() -> argparse.Namespace:
|
|
parser = _build_parser()
|
|
args = parser.parse_args()
|
|
_resolve_llm_models(args, parser)
|
|
_require_corpus_tokens_with_text(args, parser)
|
|
return args
|
|
|
|
|
|
def _build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(description=DESCRIPTION)
|
|
|
|
source = parser.add_mutually_exclusive_group(required=True)
|
|
source.add_argument("--file", help="text file to chunk")
|
|
source.add_argument("--dir", help="directory of .txt files to pool and chunk")
|
|
source.add_argument("--text", help="a single representative chunk")
|
|
|
|
parser.add_argument("--samples", type=int, default=3, help="chunks to measure")
|
|
parser.add_argument("--seed", type=int, default=42)
|
|
parser.add_argument("--max-chunk-size", type=int, default=DEFAULT_MAX_CHUNK_SIZE)
|
|
parser.add_argument(
|
|
"--llm-models",
|
|
type=_comma_list,
|
|
default=None,
|
|
help="comma list; default = the model cognee is configured with in .env",
|
|
)
|
|
parser.add_argument("--reduction-factors", type=_comma_factors, default=[1, 2, 7, 10])
|
|
parser.add_argument(
|
|
"--corpus-tokens",
|
|
type=int,
|
|
default=None,
|
|
help="corpus size; defaults to the input's token count. Required with --text.",
|
|
)
|
|
parser.add_argument("--retrieved-context", type=int, default=1118)
|
|
parser.add_argument("--query-overhead", type=int, default=32)
|
|
parser.add_argument("--out", type=Path, default=Path("token_usage_report.json"))
|
|
parser.add_argument("--plot", action="store_true")
|
|
parser.add_argument("--plot-dir", type=Path, default=Path("."))
|
|
return parser
|
|
|
|
|
|
def _comma_list(value: str) -> list[str]:
|
|
return [item.strip() for item in value.split(",") if item.strip()]
|
|
|
|
|
|
def _comma_factors(value: str) -> list[float]:
|
|
factors = [float(item) for item in _comma_list(value)]
|
|
return [int(factor) if factor.is_integer() else factor for factor in factors]
|
|
|
|
|
|
def _resolve_llm_models(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
|
"""Default to the single llm_model cognee is configured with in .env."""
|
|
if args.llm_models:
|
|
return
|
|
from cognee.infrastructure.llm.config import get_llm_config
|
|
|
|
configured = get_llm_config().llm_model
|
|
if not configured:
|
|
parser.error("no --llm-models given and no LLM_MODEL configured in .env")
|
|
args.llm_models = [configured]
|
|
|
|
|
|
def _require_corpus_tokens_with_text(
|
|
args: argparse.Namespace, parser: argparse.ArgumentParser
|
|
) -> None:
|
|
if args.text is not None and args.corpus_tokens is None:
|
|
parser.error("--corpus-tokens is required with --text (a lone chunk is not a corpus)")
|