Mind Palace extracts topic-specific context with a local ONNX embedding model (nomic-embed-text-v1.5, int8). This replaces the old “first 8k characters” heuristic and avoids external embedding APIs.
Before: text_content[:8000] regardless of topic.
Now: Semantic similarity over sentences → top relevant chunks per topic (up to ~8k chars).
from utils.text_extraction import get_topic_text
topic_text = get_topic_text(full_text, topic="Cell Biology")- Split text into sentences.
- Embed sentences with ONNX (
search_document:prefix) + embed the topic query (search_query:). - Cosine similarity to rank sentences.
- Take top 20 (ordered) with local context to build a coherent excerpt.
- Return the first ~8k chars.
Model/loader lives in utils/onnx_embedder.py and expects onnx/model_int8.onnx.
- Model:
nomic-embed-text-v1.5(int8 ONNX) - Runtime:
onnxruntime(CPU) - Tokenizer:
transformersAutoTokenizer (downloaded once) - Footprint: ~22 MB model file (already placed under
onnx/) - Cost: Free / offline after first tokenizer download
- Flashcards: topic-aware context before Groq generation.
- Quiz: targeted text for structured MCQs.
- Mnemonics: better acronyms/songs/phrases/stories per topic.
- Talk to Doc: Socratic tutor pulls focused context.
If embeddings fail or model is missing:
_simple_keyword_extraction(text, topic)Returns a keyword-centered window or the first max_length chars so pages keep working.
Dependencies already listed in requirements.txt:
onnxruntime
numpy
transformers
scikit-learn
nltk
Ensure onnx/model_int8.onnx exists; if you swap models, update the path in onnx_embedder.py.
- Topic-focused prompts → better flashcards/quizzes/mnemonics/chat
- Offline, no extra API cost
- Consistent performance (<1s for ~50k chars on CPU)
- Graceful degradation via keyword fallback
from utils.text_extraction import get_topic_text
text = open("sample.txt").read()
print(get_topic_text(text, "Neural Networks")[:500])If this returns relevant text, ONNX extraction is ready. 🧠✨