This project now includes a "Semantic Flashcards" feature powered by MongoDB Atlas. It runs a local Express server alongside the Expo app to handle data synchronization and vector search.
The backend is located in the server/ directory.
-
Install Dependencies
cd server npm install -
Environment Variables Ensure your root
.envincludes:# MongoDB Atlas Connection String MONGODB_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority # Enable Sync Feature EXPO_PUBLIC_ENABLE_MONGODB_SYNC=true # Base URL for local dev (Android Emulator: 10.0.2.2, iOS Simulator: localhost) EXPO_PUBLIC_API_BASE_URL=http://localhost:3000/api # Gemini API Key (for embeddings) EXPO_PUBLIC_GEMINI_API_KEY=AIza...
-
Run Server
cd server npm run dev # Server runs on http://localhost:3000
To enable "Struggled With" mode, you must create a Vector Search Index in MongoDB Atlas.
- Go to your Cluster -> Atlas Search -> Create Search Index.
- Select JSON Editor.
- Select Database: (your db name), Collection: flashcards.
- Index Name:
vector_index. - Configuration JSON:
(Note: Gemini
{ "fields": [ { "numDimensions": 768, "path": "embedding", "similarity": "cosine", "type": "vector" } ] }text-embedding-004uses 768 dimensions. If using a different model, adjustnumDimensions.)
- Start Session: Talk to the AI agent. Make some intentional mistakes (e.g., say "Je suis fini" instead of "J'ai fini").
- End Session: Tap "End Session". This triggers the background sync (
POST /sync-session). - Embeddings: The server automatically queues generating embeddings for your mistakes and flashcards (
POST /embed-pendingtriggered after sync). - Go to Flashcards:
- Toggle "By Scenario" (Standard view).
- Toggle "Struggled With" (Semantic view).
- Observe: You should see flashcards conceptually related to your recent mistakes (e.g., if you messed up "finir", you might see cards about finishing tasks or past tense verbs).
- Mongo Disabled: Set
ENABLE_MONGODB_SYNC=false. App should behave exactly as before (local storage only). - Sync: Finish a session. Check MongoDB Atlas collection
sessions. Data should appear. - Embeddings: Check
flashcardscollection. Fieldembeddingshould be populated (array of numbers). - Vector Search: Toggle "Struggled With". Use
serverlogs (npm run dev) to see if/api/flashcards/strugglesis called and returns results.
- Network Error: Ensure
EXPO_PUBLIC_API_BASE_URLis correct. iOS Simulator useslocalhost, Android Emulator uses10.0.2.2. - No Embeddings: Check server console for Gemini API errors.