Skip to content

Latest commit

 

History

History
79 lines (55 loc) · 2.59 KB

File metadata and controls

79 lines (55 loc) · 2.59 KB

API Documentation

Code Signature

Author: Thor Thor Email: codethor@gmail.com GitHub: https://github.com/codethor0 Project: creativity-exploit-engine

Artifact

Immutable dataclass representing a threat scenario.

Fields:

  • asset: str - Target asset
  • entry_point: str - Attack entry point
  • technique: str - Attack technique
  • constraint: str - Operational constraint

Methods:

  • to_text() -> str - Structured natural language description
  • to_dict() -> dict[str, str] - Serialize to dictionary
  • from_dict(data: dict[str, str]) -> Artifact - Deserialize from dictionary

Validation: All fields must be non-empty strings (after stripping).


BaseEmbedder

Protocol for embedders that convert text to normalized vectors.

Methods:

  • embed(text: str) -> np.ndarray - Embed text into 1D float32 vector with L2 norm 1

SentenceTransformerEmbedder

Embedder using sentence-transformers. Uses all-MiniLM-L6-v2 by default, overridable via CRE_ENGINE_MODEL_NAME environment variable.

Constructor:

  • model_name: str | None - Model name (default from env or all-MiniLM-L6-v2)
  • device: str | None - Device for inference (cuda/cpu, auto-detected if None)

DummyEmbedder

Deterministic embedder for tests. Hash-based, no external model. Produces fixed-size normalized vectors.

Constructor:

  • dim: int - Vector dimension (default 32)

CreativityEngine

Main engine for scoring and searching threat scenarios.

Constructor:

  • embedder: BaseEmbedder - Embedder instance
  • alpha: float - Novelty weight (default 0.5)
  • beta: float - Value weight (default 0.5)
  • gamma: float - Surprise weight (default 0.0)
  • k_neighbors: int - Neighbors for novelty (default 5)
  • max_elements: int - HNSW index capacity (default 10000)
  • hnsw_m: int - HNSW M parameter (default 16)
  • ef_construction: int - HNSW ef_construction (default 200)
  • ef_search: int - HNSW ef_search (default 100)

Methods:

  • add_to_archive(artifact: Artifact) -> None - Add artifact to archive and index
  • compute_novelty(artifact: Artifact) -> float - Novelty score
  • compute_value(artifact: Artifact) -> float - Value heuristic score
  • compute_surprise(artifact: Artifact, generative_model=None) -> float - Surprise (0 if no model)
  • score(artifact: Artifact, generative_model=None) -> dict - Full score dict
  • mutate(artifact: Artifact, mutation_prob=0.4, rng=None) -> Artifact - Combinational mutation
  • search(seed_artifacts, rounds, candidates_per_round, archive_top_k, novelty_threshold=0.1, random_seed=None) -> list[tuple[Artifact, dict]] - Evolutionary search