--- license: other language: - en pretty_name: Danbooru Tag Wiki Vector DB size_categories: - 1K= 1000` and a valid wiki page | | Embedded | 9,287 tags (a few wiki bodies are empty/stub) | | Embedding dim | 640 | | 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 | | Vector storage | [`sqlite-vec`](https://github.com/asg017/sqlite-vec) `vec0` virtual table | | Pooling | last-token, L2-normalized | | Max input | 248 tokens per wiki body (≈1000 chars) — see *Caveats* | ## Schema Two tables in one SQLite file: ### `tags` One row per general-category tag. | column | type | notes | |---|---|---| | `rowid` | INTEGER PK | joins to `vec_tags.rowid` | | `name` | TEXT UNIQUE | e.g. `cat_ears`, `long_hair` | | `post_count` | INTEGER | Danbooru post count at fetch time | | `tag_id` | INTEGER | Danbooru tag id | | `wiki_id` | INTEGER | Danbooru wiki page id | | `body_raw` | TEXT | Original dtext source from the wiki | | `body_clean` | TEXT | dtext stripped; `See Also` section extracted; everything from the first `Posts` header onward dropped. **This is what was embedded.** | | `see_also` | TEXT | JSON array of tag names from the wiki's `See Also` section | | `other_names` | TEXT | JSON array of alternate names | | `wiki_updated_at` | TEXT | ISO 8601 | | `fetched_at` | TEXT | ISO 8601 | | `embedded_at` | TEXT | ISO 8601, NULL if not embedded | ### `vec_tags` A `sqlite-vec` virtual table: ```sql CREATE VIRTUAL TABLE vec_tags USING vec0(embedding float[640]); ``` Keyed by `rowid` matching `tags.rowid`. Vectors are stored as L2-normalized float32, so cosine similarity equals `1 - distance/2` for the L2 distance that `sqlite-vec` returns by default. ## Usage You need the `sqlite-vec` extension loaded into your SQLite connection (plain SQLite will error on `vec_tags`). In Python: ```python import sqlite3, sqlite_vec conn = sqlite3.connect("danbooru.db") conn.enable_load_extension(True) sqlite_vec.load(conn) conn.enable_load_extension(False) # Plain metadata query — no extension needed for this one: for name, pc in conn.execute( "SELECT name, post_count FROM tags ORDER BY post_count DESC LIMIT 5" ): print(name, pc) ``` Top 5 tags by post count (sanity check): ``` 1girl 7884730 solo 6603611 long_hair 5804917 breasts 4638498 looking_at_viewer 4565846 ``` ### Semantic search To do retrieval you need to embed a query with the **same model family** as the index. Harrier expects an instruction prefix for queries (not docs): ``` Instruct: Query: ``` The companion CLI uses Q8_0 at query time against the BF16 index (cosine ≈ 0.9997 between BF16 and Q8_0 query vectors, so target ranks against the BF16 corpus are unchanged but Q8_0 is ~5× faster to load and run): ```sh uv run danbooru-db-query --db danbooru.db "a girl wearing a sailor uniform" ``` The query is L2-normalized and matched with: ```sql SELECT t.name, t.post_count, v.distance, t.body_clean FROM vec_tags v JOIN tags t ON t.rowid = v.rowid WHERE v.embedding MATCH :query_blob AND k = 10 ORDER BY v.distance; ``` ## How it was built 1. **Fetch tags** (`danbooru-db-fetch --phase tags`) — paginated tag list from Danbooru's API filtered to general category with `post_count >= 1000`. 2. **Fetch wikis** (`danbooru-db-fetch --phase wikis`) — wiki page for each tag, rate-limited to 1 request/second to be polite. dtext is parsed to produce `body_clean` (markup stripped, `See Also` extracted to its own column, content from the first `Posts` header onward dropped). 3. **Embed** (`danbooru-db-embed`) — `body_clean` truncated to 248 tokens and embedded with the BF16 Harrier-OSS GGUF, L2-normalized, written to `vec_tags`. ## Caveats - **248-token truncation.** `llama-cpp-python` hard-caps per-sequence context at 256 tokens. Wiki bodies are truncated to 248 tokens (≈1000 chars) before embedding. Tag definitions at the top of each wiki survive; trailing related-tag lists do not. If you want full-document embeddings, re-embed `body_clean` with a different runtime. - **General-category only.** Character/copyright/artist/meta tags are excluded — this is a vocabulary of *visual content* tags. - **`post_count >= 1000` floor.** The long tail of rare tags isn't here. - **Wiki content is a snapshot.** Fetched May 2026. `post_count` and wiki bodies drift over time; rebuild from the source repo to refresh. - **Some bodies are empty.** 35 of 9,322 tags have a wiki page but an empty `body_clean` after cleanup and are not embedded. ## License The embeddings, schema, and cleaned bodies in this database are derived from Danbooru's tag wikis, which are user-contributed content on [danbooru.donmai.us](https://danbooru.donmai.us). Original wiki text remains the property of its contributors and is subject to Danbooru's terms of use. The build pipeline (the GitHub repo) is published under its repository license; this dataset card and the SQLite container are released for research and personal use. If you redistribute, credit Danbooru and the wiki authors. ## Citation If this dataset is useful in published work, please cite the embedding model and the source: ```bibtex @misc{harrier-oss-v1-270m, title = {Harrier-OSS-v1-270M}, author = {Microsoft}, url = {https://huggingface.co/microsoft/harrier-oss-v1-270m}, } @misc{danbooru-tag-wiki-vector-db, title = {Danbooru Tag Wiki Vector DB}, author = {JackBinary}, url = {https://github.com/JackBinary/danbooru-db}, year = {2026}, } ```