Implementation:7onez Cti expert KB Add Fact Add Edge
| Knowledge Sources | |
|---|---|
| Domains | OSINT, Knowledge_Base |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Concrete tool for adding attributed facts and deduped edges to the knowledge base, provided by the cti-expert KB module.
Description
The add_fact and add_edge methods on the KB class in knowledge_base.py are the two primitive write operations of the knowledge base. add_fact is idempotent on (attribute, value, source, collector) — re-ingesting the same fact updates observed_at but never duplicates. Conflicts (same attribute, different value, different source) are kept as separate facts. add_edge is idempotent on the full edge key (src_type, src, rel, dst_type, dst, source, collector) and ensures both endpoints exist as entities. An optional attrs dict merges extra data-level fields onto the edge (e.g. a hosted_on edge's hosting window) without affecting the dedup key.
Usage
Import this when you need to:
- Write attributed facts to the KB from a custom adapter.
- Write attributed, deduped edges between entities.
- Preserve conflicting facts (same attribute, different value, different source).
- Attach extra data-level fields to edges (hosting windows, certificate details).
Code Reference
Source Location
- Repository: cti-expert
- File: intel_engine/tools/kb/knowledge_base.py
- Lines: L85-107 (add_fact), L114-135 (add_edge)
Signature
def add_fact(self, etype, value, attribute, fvalue, source, collector,
observed_at, confidence, evidence_ref=None):
"""Attributed atomic fact. Idempotent on (attribute, value, source, collector).
Conflicts (same attribute, DIFFERENT value, different source) are kept as
separate facts — the store never silently overwrites a disagreement."""
def add_edge(self, src_type, src, rel, dst_type, dst, source, collector,
observed_at, confidence, evidence_ref=None, attrs=None):
"""Attributed, deduped relationship. Ensures both endpoints exist as entities.
`attrs` merges extra data-level fields onto the edge without affecting the
dedup key."""
Import
from knowledge_base import KB
kb = KB(kb_root)
kb.add_fact(...)
kb.add_edge(...)
I/O Contract
Inputs (add_fact)
| Name | Type | Required | Description |
|---|---|---|---|
| etype | str | Yes | Entity type (domain/ip/email/indicator) |
| value | str | Yes | Entity value |
| attribute | str | Yes | Fact attribute name |
| fvalue | any | Yes | Fact value |
| source | str | Yes | Data source (API/page) |
| collector | str | Yes | Collector tool name |
| observed_at | str | Yes | ISO timestamp |
| confidence | str | Yes | Collection confidence level |
| evidence_ref | str | No | Link to evidence capture |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | None | Updates entity JSON file + in-memory state |
Usage Examples
Add a Registrant Fact
from knowledge_base import KB
kb = KB("intel_engine/knowledge")
kb.add_fact(
etype="domain", value="example.com",
attribute="registrant_email", fvalue="registrant@example.com",
source="whoisxml", collector="whois_enrich",
observed_at="2026-10-28T14:00:00Z",
confidence="high",
evidence_ref="cases/CASE-0001/raw/example.com.json",
)
Add an Attribution Edge
kb.add_edge(
src_type="domain", src="example.com",
rel="registered_by",
dst_type="email", dst="registrant@example.com",
source="whoisxml", collector="whois_enrich",
observed_at="2026-10-28T14:00:00Z",
confidence="high",
attrs={"display": "Registrant Name"}, # extra data, not in dedup key
)