Building a Local Video Knowledge Graph with Qwen4 and Hybrid Search
Turn a growing YouTube AI archive into a hybrid LanceDB + FTS5 knowledge base, a local Qwen4 35B A3B tool graph, and a 1.31 MB standalone HTML viewer.
We built an ongoing, incrementally updated knowledge base and interactive tool graph from the @theAIsearch YouTube archive using yt-dlp, MiniLM embeddings in LanceDB, SQLite FTS5 with Reciprocal Rank Fusion, and local Qwen4 35B A3B extraction via Ollama. Everything compiles into a 1.31 MB self-contained browser viewer with zero backend hosting cost, and our source audit caught three fixable pipeline bugs.
Why build a local knowledge graph for video archivesLink to this section
Long technical YouTube channels accumulate hundreds of hours of demos, benchmark walkthroughs, and model comparisons that standard video search cannot inspect. A 30-minute tutorial might compare three video models, show a specific ComfyUI node setup, and mention a quantization workaround halfway through the transcript, yet only the title and top description lines are searchable.
In xplormityofficial/the-ai-search-kb, Xplormity Collective built a fully local pipeline that indexes the AI Search YouTube archive into two artifacts: a hybrid vector-plus-keyword search index and a structured tool graph compiled into a 1.31 MB single-file interactive HTML viewer. The pipeline is incremental and built to grow continuously as new videos are published, rather than locking into a static one-off export.
Two local tracks: hybrid retrieval and Qwen4 graph extractionLink to this section
Every stage runs offline on local hardware using open tools and zero paid API calls:
dump_playlist.py + scrape_channel.py (yt-dlp, English SRTs + metadata)
│
├──► srt_parse.py (900-char chunks, 120-char overlap)
│ ├──► build_kb.py -> all-MiniLM-L6-v2 (384d CUDA) -> LanceDB
│ └──► build_fts.py -> SQLite FTS5 (chunks + videos)
│ └──► search.py (Reciprocal Rank Fusion: 1 / (60 + rank))
│
└──► extract_graph_llm.py (qwen4:latest via Ollama, JSON mode, resumable)
└──► build_graph.py -> data/graph.json
└──► index.html / viewer/index.html (1.31 MB canvas UI)Hybrid chunk search (MiniLM + LanceDB + SQLite FTS5)Link to this section
srt_parse.py strips SRT cue indices and timestamps, then slices transcripts into overlapping 900-character chunks (120-character overlap, breaking on sentence boundaries past the midpoint). build_kb.py embeds each chunk on CUDA with all-MiniLM-L6-v2 (384 dimensions, normalized) into a LanceDB table, while build_fts.py builds SQLite FTS5 virtual tables over both transcript chunks and video titles/tools.
At query time, search.py fetches 3k candidates from LanceDB cosine similarity and 3k from SQLite FTS5 BM25, fuses ranks via Reciprocal Rank Fusion (1.0 / (60 + rank)), and groups up to three transcript hits per video.
Structured tool extraction with local Qwen4 35B A3BLink to this section
Instead of hand-tagging videos or paying cloud token bills to process hundreds of transcripts, extract_graph_llm.py runs Qwen4 35B A3B locally through Ollama (model: "qwen4:latest"). Each video prompt combines the title, first 800 characters of the description, and first 3,000 characters of parsed captions, running with temperature: 0, format: "json", num_ctx: 8192, and num_predict: 2400.
Outputs append line-by-line to kb/graph_extracted.jsonl and flush immediately after each video, skipping previously processed IDs on restart. Two things matter when using Qwen4 35B A3B for batch extraction:
- Low active compute per token: Only 3B parameters activate per token, keeping extraction throughput fast across long runs while maintaining strong instruction following on JSON schemas (
compares,replaces,builds-on,alternative-to,mentionsacross eight categories). - Important local sizing note: Unlike older 35B-A3B checkpoints (~21 GB at Q4), Qwen4 35B A3B stores a 20B n-gram embedding table plus a 2B MTP layer alongside its 35B MoE backbone, so Ollama's
qwen4:latest(qwen4:35b-a3b) weighs 36-37 GB on disk (35.18 GBin Unsloth'sUD-Q4_K_MGGUF). Plan for 48 GB+ VRAM, dual 24 GB cards, or unified memory if you want zero CPU offloading; see our Qwen4 35B A3B spec page and VRAM and KV cache guide.
What the initial December 2026 snapshot capturedLink to this section
The pipeline is built for continuous refreshes: running scrape_channel.py and extract_graph_llm.py again only processes newly uploaded videos. As a baseline reference, the initial December 5, 2026 export in data/details.jsonl and data/graph.json covered 443 videos (June 2023 through December 2, 2026; 215.3 hours of runtime; 80,190,322 cumulative views), 15,169 transcript chunks (mean 853 characters), 2,205 distinct tool/model nodes, and 3,135 graph edges.
| Year | Videos indexed | Runtime | Total views | Nodes first seen |
|---|---|---|---|---|
| 2023 | 57 | 12.2 h | 6.39M | 222 |
| 2024 | 142 | 64.5 h | 19.18M | 518 |
| 2025 | 136 | 77.5 h | 26.21M | 742 |
| 2026 (through Dec 2) | 108 | 61.1 h | 28.41M | 723 |
Across those initial 2,205 nodes, 442 of 443 videos returned structured tools (only one short 2023 clip, s0NM6Qf9OXM, emitted an empty list):
| Category | Nodes | Share | Top nodes in initial snapshot |
|---|---|---|---|
Other | 562 | 25.5% | ai search (59), ai-search.io (47), hubspot (23), git (21) |
Video | 453 | 20.5% | higgsfield (38), sora (33), kling (32), veo (26), wan (22) |
LLM | 327 | 14.8% | chatgpt (48), chatllm (47), gemini (32), gpt-4o (27), deepseek (23) |
Image | 318 | 14.4% | stable diffusion (39), nano banana (26), flux (20), upix (19) |
Audio | 200 | 9.1% | suno (17), rvc (15), udio (10), elevenlabs (7) |
Agent | 167 | 7.6% | deepagent (23), monica (13), lovart (6), genspark (5) |
Infra | 122 | 5.5% | comfyui (43), hugging face (23), google ai studio (13) |
Coding | 56 | 2.5% | claude code (8), iquest coder (4), codex (3) |
Two patterns stand out in the extracted structure. First, 81.3% of nodes (1,793 of 2,205) appear in only one video, while 208 appear in three or more and 49 reach ten or more. Second, running an LLM directly over descriptions and intro transcripts without a stop-list pulls recurring sponsors (hubspot: 23) and channel self-references (ai search: 59, ai-search.io: 47) into the Other category alongside legitimate utilities.
Single-file 1.31 MB interactive viewerLink to this section
Instead of paying to host LanceDB and an API server online, the repository compiles its portable artifacts into a standalone HTML5 <canvas> viewer at index.html (mirrored in viewer/index.html, 1,313,023 bytes). Two inline JSON script tags embed the nodes, edges, video metadata, and 1,582 transcript excerpts across 312 videos.
A spatial grid-bucketed force simulation (120 px cells) clusters nodes by category and outlines entities seen within the trailing 60 days in gold (175 recent nodes in the December 5 export). Clicking any node or tag isolates its neighborhood and populates the sidebar with matching videos and highlighted transcript snippets.
Three pipeline bugs caught by auditing the committed filesLink to this section
Inspecting data/chunks.jsonl, data/graph.json, and index.html directly against the Python generators turned up three concrete bugs worth fixing before expanding the archive or cloning this pattern:
- Underscore YouTube IDs break chunk attribution:
scrape_channel.pysaves caption files as{vid}_{title}.srt, andsrt_parse.pyparses the video ID withf.name.split("_")[0]. Because 80 YouTube IDs in the initial set contain underscores - including leading-underscore IDs such as_JXbvSTGPoo(1.91M views), which evaluates to""- 2,748 of 15,169 chunks carry truncated or emptyvideo_idkeys, and zero underscored video IDs appear in the viewer's excerpt map. Replacingsplit("_")[0]withf.name[:11](or^([A-Za-z0-9_-]{11})_) fixes the bug completely. - Version-stripping asymmetry drops 583 graph edges:
build_graph.pybuilds node IDs withgroup_key(canon(name)), stripping trailing version suffixes such askling 4->klingandflux 3->flux. When writing LLMrelationshipsedges, however, it usescanon(source)andcanon(target)without callinggroup_key(). Consequently, 583 of 3,135 edges (18.6%) point to un-grouped version strings missing fromnodes(224alternative-to,139builds-on,133compares,58mentions,27replaces,2targets), leaving 2,552 active edges in the viewer. - Viewer template drift:
tools/make_viewer.pychecked intotools/still reflects an earlier 600-node template without transcript excerpts, the collapsible newest-tools bar, or isolate mode, whereas the committedindex.htmlandviewer/index.htmlhold the updated 2,205-node build. Re-runningmake_viewer.pywithout syncing it first would overwrite those UI features.
A smaller normalization gap also shows up in active edges: provider-prefixed strings such as zai/glm-5.3 or hyphenated forms like gpt-4o stay separate from glm and gpt under a trailing-space regex. A short alias table and sponsor blocklist run right after extract_graph_llm.py solves both in one deterministic step.
Run or extend the pipeline locallyLink to this section
To pull new videos onto an existing knowledge base or adapt the workflow to another YouTube channel after fixing srt_parse.py (f.name[:11]) and build_graph.py (group_key on edge endpoints):
git clone https://github.com/xplormityofficial/the-ai-search-kb.git
ollama pull qwen4
python tools/dump_playlist.py
python tools/scrape_channel.py
python tools/extract_graph_llm.py
python tools/build_graph.py
python tools/build_fts.py
python tools/build_kb.pySnapshot audited December 5, 2026 against xplormityofficial/the-ai-search-kb commit 39fd811a6cfd29e9cff28b10a37551c8dff68319. All corpus counts, edge resolution totals, and model weight measurements come directly from the repository artifacts, Hugging Face config/GGUF trees, and Ollama registry metadata.
Frequently asked
Why combine LanceDB vector search with SQLite FTS5 instead of using embeddings alone?
Dense embeddings (all-MiniLM-L6-v2) surface conceptual matches across paraphrased speech, while SQLite FTS5 BM25 pins exact tool names, model versions, and CLI flags. Fusing both candidate sets with Reciprocal Rank Fusion (1 / (60 + rank)) gives better precision without an external reranker API.
Which local model extracted the tool graph and how much memory does it need?
Graph extraction runs locally via Ollama using qwen4:latest (Qwen4 35B A3B) with temperature set to 0, strict JSON format mode, and an 8,192-token context window. Although only 3B parameters activate per token, Qwen4 includes a 20B n-gram embedding table, so the local Q4 weights take ~35-37 GB on disk.
Is the knowledge base frozen at 443 videos?
No. 443 videos (215.3 hours, 2,205 nodes, 15,169 chunks) is only the initial December 5, 2026 repository snapshot. Both the yt-dlp scraper and extract_graph_llm.py are incremental and resumable by video ID, so new uploads append without reprocessing the archive.
What pipeline bugs did the artifact audit catch?
Auditing the committed JSONL and graph files caught three bugs: srt_parse.py splits subtitle filenames on the first underscore (breaking 2,748 chunk IDs across 80 YouTube IDs that contain underscores), build_graph.py strips version suffixes from node IDs without applying the same normalization to LLM edge endpoints (dropping 583 edges in the viewer), and tools/make_viewer.py has drifted behind the committed 2,205-node viewer, so re-running it would overwrite newer UI features.