JackBinary commited on
Commit
ac9f38e
·
verified ·
1 Parent(s): 0e5763f

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +193 -0
README.md ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ language:
4
+ - en
5
+ pretty_name: Danbooru Tag Wiki Vector DB
6
+ size_categories:
7
+ - 1K<n<10K
8
+ task_categories:
9
+ - sentence-similarity
10
+ - feature-extraction
11
+ tags:
12
+ - danbooru
13
+ - anime
14
+ - tags
15
+ - embeddings
16
+ - vector-database
17
+ - sqlite
18
+ - sqlite-vec
19
+ - semantic-search
20
+ - harrier-oss
21
+ - gemma
22
+ ---
23
+
24
+ # Danbooru Tag Wiki Vector DB
25
+
26
+ A single-file SQLite database of [Danbooru](https://danbooru.donmai.us)
27
+ general-category tag wiki pages, with a `sqlite-vec` virtual table holding
28
+ 640-dim embeddings of each cleaned wiki body. Built to enable natural-language
29
+ search over Danbooru's tag vocabulary — give it a phrase like
30
+ *"a girl wearing a sailor uniform"* and get back the tags whose wiki
31
+ descriptions match.
32
+
33
+ Source code (fetcher, embedder, query CLI) lives at
34
+ [github.com/JackBinary/danbooru-db](https://github.com/JackBinary/danbooru-db).
35
+
36
+ ## At a glance
37
+
38
+ | | |
39
+ |---|---|
40
+ | File | `danbooru.db` (single SQLite file, ~36 MB) |
41
+ | Tags | 9,322 general-category tags with `post_count >= 1000` and a valid wiki page |
42
+ | Embedded | 9,287 tags (a few wiki bodies are empty/stub) |
43
+ | Embedding dim | 640 |
44
+ | Embedding model | [`mykor/harrier-oss-v1-270m-GGUF`](https://huggingface.co/mykor/harrier-oss-v1-270m-GGUF) (BF16 at index time) — a GGUF of `microsoft/harrier-oss-v1-270m`, a 270M-param Gemma-embedding model with last-token pooling |
45
+ | Vector storage | [`sqlite-vec`](https://github.com/asg017/sqlite-vec) `vec0` virtual table |
46
+ | Pooling | last-token, L2-normalized |
47
+ | Max input | 248 tokens per wiki body (≈1000 chars) — see *Caveats* |
48
+
49
+ ## Schema
50
+
51
+ Two tables in one SQLite file:
52
+
53
+ ### `tags`
54
+ One row per general-category tag.
55
+
56
+ | column | type | notes |
57
+ |---|---|---|
58
+ | `rowid` | INTEGER PK | joins to `vec_tags.rowid` |
59
+ | `name` | TEXT UNIQUE | e.g. `cat_ears`, `long_hair` |
60
+ | `post_count` | INTEGER | Danbooru post count at fetch time |
61
+ | `tag_id` | INTEGER | Danbooru tag id |
62
+ | `wiki_id` | INTEGER | Danbooru wiki page id |
63
+ | `body_raw` | TEXT | Original dtext source from the wiki |
64
+ | `body_clean` | TEXT | dtext stripped; `See Also` section extracted; everything from the first `Posts` header onward dropped. **This is what was embedded.** |
65
+ | `see_also` | TEXT | JSON array of tag names from the wiki's `See Also` section |
66
+ | `other_names` | TEXT | JSON array of alternate names |
67
+ | `wiki_updated_at` | TEXT | ISO 8601 |
68
+ | `fetched_at` | TEXT | ISO 8601 |
69
+ | `embedded_at` | TEXT | ISO 8601, NULL if not embedded |
70
+
71
+ ### `vec_tags`
72
+ A `sqlite-vec` virtual table:
73
+
74
+ ```sql
75
+ CREATE VIRTUAL TABLE vec_tags USING vec0(embedding float[640]);
76
+ ```
77
+
78
+ Keyed by `rowid` matching `tags.rowid`. Vectors are stored as L2-normalized
79
+ float32, so cosine similarity equals `1 - distance/2` for the L2 distance
80
+ that `sqlite-vec` returns by default.
81
+
82
+ ## Usage
83
+
84
+ You need the `sqlite-vec` extension loaded into your SQLite connection
85
+ (plain SQLite will error on `vec_tags`). In Python:
86
+
87
+ ```python
88
+ import sqlite3, sqlite_vec
89
+ conn = sqlite3.connect("danbooru.db")
90
+ conn.enable_load_extension(True)
91
+ sqlite_vec.load(conn)
92
+ conn.enable_load_extension(False)
93
+
94
+ # Plain metadata query — no extension needed for this one:
95
+ for name, pc in conn.execute(
96
+ "SELECT name, post_count FROM tags ORDER BY post_count DESC LIMIT 5"
97
+ ):
98
+ print(name, pc)
99
+ ```
100
+
101
+ Top 5 tags by post count (sanity check):
102
+ ```
103
+ 1girl 7884730
104
+ solo 6603611
105
+ long_hair 5804917
106
+ breasts 4638498
107
+ looking_at_viewer 4565846
108
+ ```
109
+
110
+ ### Semantic search
111
+
112
+ To do retrieval you need to embed a query with the **same model family** as
113
+ the index. Harrier expects an instruction prefix for queries (not docs):
114
+
115
+ ```
116
+ Instruct: <task>
117
+ Query: <text>
118
+ ```
119
+
120
+ The companion CLI uses Q8_0 at query time against the BF16 index (cosine
121
+ ≈ 0.9997 between BF16 and Q8_0 query vectors, so target ranks against the
122
+ BF16 corpus are unchanged but Q8_0 is ~5× faster to load and run):
123
+
124
+ ```sh
125
+ uv run danbooru-db-query --db danbooru.db "a girl wearing a sailor uniform"
126
+ ```
127
+
128
+ The query is L2-normalized and matched with:
129
+
130
+ ```sql
131
+ SELECT t.name, t.post_count, v.distance, t.body_clean
132
+ FROM vec_tags v
133
+ JOIN tags t ON t.rowid = v.rowid
134
+ WHERE v.embedding MATCH :query_blob AND k = 10
135
+ ORDER BY v.distance;
136
+ ```
137
+
138
+ ## How it was built
139
+
140
+ 1. **Fetch tags** (`danbooru-db-fetch --phase tags`) — paginated tag list
141
+ from Danbooru's API filtered to general category with `post_count >= 1000`.
142
+ 2. **Fetch wikis** (`danbooru-db-fetch --phase wikis`) — wiki page for each
143
+ tag, rate-limited to 1 request/second to be polite. dtext is parsed to
144
+ produce `body_clean` (markup stripped, `See Also` extracted to its own
145
+ column, content from the first `Posts` header onward dropped).
146
+ 3. **Embed** (`danbooru-db-embed`) — `body_clean` truncated to 248 tokens
147
+ and embedded with the BF16 Harrier-OSS GGUF, L2-normalized, written to
148
+ `vec_tags`.
149
+
150
+ ## Caveats
151
+
152
+ - **248-token truncation.** `llama-cpp-python` hard-caps per-sequence context
153
+ at 256 tokens. Wiki bodies are truncated to 248 tokens (≈1000 chars) before
154
+ embedding. Tag definitions at the top of each wiki survive; trailing related-tag
155
+ lists do not. If you want full-document embeddings, re-embed `body_clean` with
156
+ a different runtime.
157
+ - **General-category only.** Character/copyright/artist/meta tags are
158
+ excluded — this is a vocabulary of *visual content* tags.
159
+ - **`post_count >= 1000` floor.** The long tail of rare tags isn't here.
160
+ - **Wiki content is a snapshot.** Fetched May 2026. `post_count` and wiki
161
+ bodies drift over time; rebuild from the source repo to refresh.
162
+ - **Some bodies are empty.** 35 of 9,322 tags have a wiki page but an empty
163
+ `body_clean` after cleanup and are not embedded.
164
+
165
+ ## License
166
+
167
+ The embeddings, schema, and cleaned bodies in this database are derived from
168
+ Danbooru's tag wikis, which are user-contributed content on
169
+ [danbooru.donmai.us](https://danbooru.donmai.us). Original wiki text remains
170
+ the property of its contributors and is subject to Danbooru's terms of use.
171
+ The build pipeline (the GitHub repo) is published under its repository
172
+ license; this dataset card and the SQLite container are released for research
173
+ and personal use. If you redistribute, credit Danbooru and the wiki authors.
174
+
175
+ ## Citation
176
+
177
+ If this dataset is useful in published work, please cite the embedding model
178
+ and the source:
179
+
180
+ ```bibtex
181
+ @misc{harrier-oss-v1-270m,
182
+ title = {Harrier-OSS-v1-270M},
183
+ author = {Microsoft},
184
+ url = {https://huggingface.co/microsoft/harrier-oss-v1-270m},
185
+ }
186
+
187
+ @misc{danbooru-tag-wiki-vector-db,
188
+ title = {Danbooru Tag Wiki Vector DB},
189
+ author = {JackBinary},
190
+ url = {https://github.com/JackBinary/danbooru-db},
191
+ year = {2026},
192
+ }
193
+ ```