kabasshouse commited on
Commit
de683ae
·
verified ·
1 Parent(s): 00b7953

Upload schema.sql with huggingface_hub

Browse files
Files changed (1) hide show
  1. schema.sql +159 -0
schema.sql ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ -- Epstein Analysis Server -- SQLite Schema
2
+ -- Separate from the OCR provenance DB (epstein_audit.db)
3
+
4
+ PRAGMA journal_mode = WAL;
5
+ PRAGMA foreign_keys = ON;
6
+
7
+ -- Core: one row per JSON file
8
+ CREATE TABLE IF NOT EXISTS documents (
9
+ id INTEGER PRIMARY KEY,
10
+ file_key TEXT UNIQUE NOT NULL,
11
+ dataset TEXT NOT NULL,
12
+ full_text TEXT,
13
+ document_type TEXT,
14
+ date TEXT,
15
+ is_photo BOOLEAN DEFAULT 0,
16
+ has_handwriting BOOLEAN,
17
+ has_stamps BOOLEAN,
18
+ ocr_source TEXT,
19
+ additional_notes TEXT,
20
+ page_number TEXT,
21
+ document_number TEXT,
22
+ json_path TEXT NOT NULL,
23
+ char_count INTEGER,
24
+ created_at TEXT DEFAULT (datetime('now'))
25
+ );
26
+
27
+ -- Text chunks for RAG
28
+ CREATE TABLE IF NOT EXISTS chunks (
29
+ id INTEGER PRIMARY KEY,
30
+ document_id INTEGER NOT NULL REFERENCES documents(id),
31
+ chunk_index INTEGER NOT NULL,
32
+ content TEXT NOT NULL,
33
+ token_count INTEGER,
34
+ char_start INTEGER,
35
+ char_end INTEGER,
36
+ UNIQUE(document_id, chunk_index)
37
+ );
38
+
39
+ -- Chunk embeddings (Phase 2)
40
+ CREATE TABLE IF NOT EXISTS chunk_embeddings (
41
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
42
+ chunk_id INTEGER UNIQUE NOT NULL REFERENCES chunks(id) ON DELETE CASCADE,
43
+ document_id INTEGER NOT NULL REFERENCES documents(id) ON DELETE CASCADE,
44
+ embedding BLOB NOT NULL,
45
+ embedding_dim INTEGER DEFAULT 768,
46
+ model TEXT DEFAULT 'gemini-embedding-001',
47
+ source_text_hash TEXT,
48
+ created_at TEXT DEFAULT (datetime('now'))
49
+ );
50
+
51
+ -- Summary embeddings (Phase 2)
52
+ CREATE TABLE IF NOT EXISTS summary_embeddings (
53
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
54
+ document_id INTEGER UNIQUE NOT NULL REFERENCES documents(id),
55
+ summary_text TEXT NOT NULL,
56
+ embedding BLOB NOT NULL,
57
+ embedding_dim INTEGER DEFAULT 768,
58
+ model TEXT DEFAULT 'gemini-embedding-001',
59
+ created_at TEXT DEFAULT (datetime('now'))
60
+ );
61
+
62
+ -- Entities from our JSON files
63
+ CREATE TABLE IF NOT EXISTS entities (
64
+ id INTEGER PRIMARY KEY,
65
+ document_id INTEGER NOT NULL REFERENCES documents(id),
66
+ entity_type TEXT NOT NULL,
67
+ value TEXT NOT NULL,
68
+ normalized_value TEXT
69
+ );
70
+
71
+ -- From release/persons_registry.json
72
+ CREATE TABLE IF NOT EXISTS persons (
73
+ id INTEGER PRIMARY KEY,
74
+ canonical_name TEXT UNIQUE NOT NULL,
75
+ slug TEXT,
76
+ category TEXT,
77
+ aliases TEXT,
78
+ search_terms TEXT,
79
+ sources TEXT,
80
+ notes TEXT
81
+ );
82
+
83
+ -- From release/knowledge_graph_entities.json
84
+ CREATE TABLE IF NOT EXISTS kg_entities (
85
+ id INTEGER PRIMARY KEY,
86
+ name TEXT UNIQUE NOT NULL COLLATE NOCASE,
87
+ entity_type TEXT,
88
+ description TEXT,
89
+ metadata TEXT
90
+ );
91
+
92
+ -- From release/knowledge_graph_relationships.json
93
+ CREATE TABLE IF NOT EXISTS kg_relationships (
94
+ id INTEGER PRIMARY KEY,
95
+ source_id INTEGER REFERENCES kg_entities(id),
96
+ target_id INTEGER REFERENCES kg_entities(id),
97
+ relationship_type TEXT NOT NULL,
98
+ weight REAL DEFAULT 1.0,
99
+ evidence TEXT,
100
+ metadata TEXT
101
+ );
102
+
103
+ -- Indexes: documents
104
+ CREATE INDEX IF NOT EXISTS idx_documents_dataset ON documents(dataset);
105
+ CREATE INDEX IF NOT EXISTS idx_documents_type ON documents(document_type);
106
+ CREATE INDEX IF NOT EXISTS idx_documents_is_photo ON documents(is_photo);
107
+ CREATE INDEX IF NOT EXISTS idx_documents_date ON documents(date);
108
+ CREATE INDEX IF NOT EXISTS idx_documents_ocr_source ON documents(ocr_source);
109
+ CREATE INDEX IF NOT EXISTS idx_documents_file_key ON documents(file_key);
110
+
111
+ -- Indexes: entities
112
+ CREATE INDEX IF NOT EXISTS idx_entities_document ON entities(document_id);
113
+ CREATE INDEX IF NOT EXISTS idx_entities_type ON entities(entity_type);
114
+ CREATE INDEX IF NOT EXISTS idx_entities_value ON entities(value);
115
+ CREATE INDEX IF NOT EXISTS idx_entities_type_value ON entities(entity_type, value);
116
+ CREATE INDEX IF NOT EXISTS idx_entities_normalized ON entities(normalized_value);
117
+
118
+ -- Indexes: chunks
119
+ CREATE INDEX IF NOT EXISTS idx_chunks_document ON chunks(document_id);
120
+
121
+ -- Indexes: chunk_embeddings
122
+ CREATE INDEX IF NOT EXISTS idx_ce_chunk_id ON chunk_embeddings(chunk_id);
123
+ CREATE INDEX IF NOT EXISTS idx_ce_document_id ON chunk_embeddings(document_id);
124
+ CREATE INDEX IF NOT EXISTS idx_ce_created_at ON chunk_embeddings(created_at);
125
+ CREATE INDEX IF NOT EXISTS idx_ce_source_text_hash ON chunk_embeddings(source_text_hash);
126
+
127
+ -- Indexes: summary_embeddings
128
+ CREATE INDEX IF NOT EXISTS idx_se_document_id ON summary_embeddings(document_id);
129
+ CREATE INDEX IF NOT EXISTS idx_se_created_at ON summary_embeddings(created_at);
130
+
131
+ -- Indexes: persons
132
+ CREATE INDEX IF NOT EXISTS idx_persons_category ON persons(category);
133
+ CREATE INDEX IF NOT EXISTS idx_persons_slug ON persons(slug);
134
+
135
+ -- Recovered redacted text (from community analysis)
136
+ CREATE TABLE IF NOT EXISTS recovered_redactions (
137
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
138
+ document_id INTEGER,
139
+ file_key TEXT NOT NULL,
140
+ page_number INTEGER NOT NULL,
141
+ num_fragments INTEGER,
142
+ reconstructed_text TEXT,
143
+ document_type TEXT,
144
+ interest_score REAL,
145
+ names_found TEXT,
146
+ dataset_source TEXT,
147
+ FOREIGN KEY (document_id) REFERENCES documents(id)
148
+ );
149
+
150
+ -- Indexes: recovered_redactions
151
+ CREATE INDEX IF NOT EXISTS idx_recovered_redactions_file_key ON recovered_redactions(file_key);
152
+ CREATE INDEX IF NOT EXISTS idx_recovered_redactions_document_id ON recovered_redactions(document_id);
153
+ CREATE INDEX IF NOT EXISTS idx_recovered_redactions_interest_score ON recovered_redactions(interest_score DESC);
154
+
155
+ -- Indexes: knowledge graph
156
+ CREATE INDEX IF NOT EXISTS idx_kg_entities_type ON kg_entities(entity_type);
157
+ CREATE INDEX IF NOT EXISTS idx_kg_relationships_source ON kg_relationships(source_id);
158
+ CREATE INDEX IF NOT EXISTS idx_kg_relationships_target ON kg_relationships(target_id);
159
+ CREATE INDEX IF NOT EXISTS idx_kg_relationships_type ON kg_relationships(relationship_type);