跪拜 Guibai
← All articles
Python · LLM

Under One Yuan: Regex, SQLite, and an LLM Turn 1,500 AI Chats into a Personal Knowledge Base

By 大侠在此在在此 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most users let hundreds of AI conversations rot in history logs. This pipeline demonstrates that a small deterministic front-end (regex, SQLite hashing) can make LLM processing affordable enough for an individual, and that a context-aware classification prompt beats a generic tagger. The same pattern applies to anyone holding exported chat JSON from any LLM.

Summary

A 60MB conversations.json export becomes a searchable knowledge base through three layers: local regex and keywords filter out about 70% of casual chat, a SQLite-backed hybrid fingerprint skips unchanged conversations so the API is never re-billed, and a DeepSeek call then classifies and scores the remaining sessions into categories. The classification prompt embeds the user's identity and focus areas, which separates hard technical troubleshooting from emotional venting far better than a generic tagger.

A separate deep_scan.py handles marathon conversations of over 1,000 messages, extracting all user utterances to pull out late-stage breakthroughs that a first-pass look would miss. Pitfalls along the way include a Windows file lock from an open Excel sheet, CTF sessions mis-scored because security keywords were missing from the initial list, and a dedup logic that had to balance missing new messages against re-sending old ones. The final outputs are an Excel scoring sheet and distilled Markdown notes ready for Obsidian.

Takeaways
— The entire processing of 1,500 conversations cost under 1 RMB (about $0.15).
— Local regex and keywords filter out about 70% of chat noise before any API call is made.
— A hybrid fingerprint of SHA-256(session ID + message count + last message timestamp) stored in SQLite determines whether a conversation changed, preventing repeat API charges.
— DeepSeek's exported JSON bundles REQUEST, RESPONSE, and THINK in each fragment; dropping THINK controls token consumption.
— Including the user's identity and focus areas in the scoring prompt improves classification accuracy for domain-specific content.
— A deep_scan script processes ultra-long conversations by extracting all user utterances, catching high-value content later in the thread.
— Misclassifications were fixed by updating the keyword list and re-running only affected conversations, costing just a few cents.
— An open Excel file on Windows blocks Python writes, causing PermissionError; a try/except with a friendly prompt handles it.
— The 8-step checklist starts with exporting conversations.json and ends with a sorted Excel sheet and distilled Markdown notes.
Conclusions

Skipping vector search in favor of regex filtering plus LLM scoring is a deliberate trade-off: retrieval gives fragments, but the stated goal is distillation into structured troubleshooting notes, so the evaluator approach fits the output.

The hybrid fingerprint is a pragmatic incremental-processing trick. Hashing session ID, message count, and last timestamp detects changes without re-reading message bodies, balancing cost and completeness.

Embedding the user's persona into the classification prompt is a low-cost accuracy booster. It shows why generic classifiers fail: they lack the context to distinguish a Docker error from a rant.

The decision to do coarse filtering locally before any API call shifts most of the cost burden to deterministic code, making large-scale personal document processing viable on a hobbyist budget.

Concepts & terms
Hybrid fingerprint
A hash computed from session ID, message count, and last message timestamp (SHA-256) stored in SQLite. It identifies whether a chat conversation changed since the last run, allowing incremental processing without re-sending unchanged data to the LLM.
THINK fragments
In DeepSeek's exported JSON, each message in the fragments array can include a THINK field containing the model's internal reasoning trace. These are typically long and filtered out to save tokens and keep only clean user requests and AI responses.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗