Source Model¶
Stores immutable source content from which facts are extracted.
Class: FactDb::Models::Source¶
source = FactDb::Models::Source.new(
content: "Document content...",
kind: "email",
captured_at: Time.current
)
Attributes¶
| Attribute | Type | Description |
|---|---|---|
id |
Integer | Primary key |
content_hash |
String | SHA256 hash for deduplication |
kind |
String | Kind (email, document, etc.) |
content |
Text | Original unmodified text content |
title |
String | Optional title |
source_uri |
String | Original location |
metadata |
Hash | Additional metadata (JSONB) |
embedding |
Vector | Semantic search vector |
captured_at |
DateTime | When content was captured |
created_at |
DateTime | Record creation time |
Associations¶
Callbacks¶
Instance Methods¶
compute_hash¶
Computes SHA256 hash of content for deduplication.
generate_embedding¶
Generates embedding vector using configured generator.
Class Methods¶
find_or_create_by_text¶
Find existing source by hash or create new.
Example:
source = Source.find_or_create_by_text(
"Document text",
kind: "document",
captured_at: Time.current
)
Scopes¶
by_kind¶
Filter by content kind.
captured_between¶
Filter by capture date range.
search_text¶
Full-text search.
Usage Examples¶
Create Source¶
source = Source.create!(
content: "Important document...",
kind: "document",
title: "Q4 Report",
source_uri: "https://example.com/report.pdf",
captured_at: Time.current,
metadata: {
author: "Jane Smith",
department: "Finance"
}
)