Testing Semantic Search
October 5, 2025 · View on GitHub
This guide explains how to test the EmbeddingGemma + Orama semantic search integration.
Test Page
A dedicated test page (app/test-search/page.tsx) is available to verify the search system works correctly.
Running the Test
-
Start the development server:
npm run dev -
Open the test page: Navigate to
http://localhost:3000/test-searchin your browser -
Initialize the system:
- Click the "Initialize System" button
- Wait for the EmbeddingGemma model to download (~200MB, one-time)
- Wait for the binary index to load (~20MB)
- Wait for the Orama database to be created and populated
-
Run a search:
- Enter a query in the search box (e.g., "fire sacrifice ritual", "cosmic order", "hymn to dawn")
- Click "Search" or press Enter
- View the results and metrics
What to Look For
✅ Success Indicators
-
Initialization
- Model loads without errors
- Binary index loads successfully
- Documents are inserted into Orama
- Total time: 30-60 seconds (first load), 5-12 seconds (cached)
-
Embedding Generation
- Query embedding is generated
- Dimension is 512
- Time: 200-500ms
- First 5 values are displayed in console
-
Search Results
- Multiple results are returned
- Scores are between 0 and 1
- Higher scored results appear first
- Results are relevant to the query
- Source information is displayed
❌ Failure Indicators
-
Model Load Failures
- Network errors (check internet connection)
- CORS errors (ensure running from localhost)
- Out of memory errors (close other tabs)
-
Search Failures
- No results found (may need to adjust query)
- Incorrect dimensions (should be 512)
- Extremely slow search (>5 seconds)
Metrics to Monitor
| Metric | Expected Value | What It Means |
|---|---|---|
| Initialization Time | 5-60 seconds | Time to load model + index |
| Embedding Time | 200-500ms | Time to generate query embedding |
| Search Time | 10-50ms | Time to perform vector search |
| Total Documents | 10,000+ | Number of searchable documents |
Example Queries
Try these queries to test different aspects:
-
Sanskrit Concepts:
- "dharma and duty"
- "cosmic order rita"
- "sacrifice and ritual"
-
Deities:
- "Indra thunder god"
- "Agni fire deity"
- "Soma sacred drink"
-
Natural Phenomena:
- "dawn and morning"
- "fire and flames"
- "rain and water"
-
Abstract Concepts:
- "truth and cosmic law"
- "creation of the universe"
- "immortality and gods"
Console Output
The test page provides detailed console output showing:
- Each step of initialization
- Tokenization process
- Model inference
- Embedding details (dimension, values)
- Search parameters
- Results with scores
Troubleshooting
Model Doesn't Load
Problem: Model fails to download or times out
Solutions:
- Check internet connection
- Verify HuggingFace CDN is accessible
- Clear browser cache and reload
- Try a different browser
Binary Index Fails to Load
Problem: Binary file not found or corrupted
Solutions:
- Verify
/smrithi-rgveda-embgemma-512d.binexists inpublic/ - Check file size (~20MB)
- Ensure the file wasn't corrupted during download
- Restart dev server
Search Returns No Results
Problem: Vector search finds no matches
Solutions:
- Check embedding dimension matches (should be 512)
- Try different queries
- Verify documents were inserted into Orama
- Check console for error messages
Slow Performance
Problem: Search takes too long
Solutions:
- First query is always slower (model warmup)
- Close other browser tabs to free memory
- Ensure hardware acceleration is enabled
- Try on a different device
Advanced Testing
Testing in Production Build
-
Build the static site:
npm run export -
Serve the build:
npx serve out -
Open
http://localhost:3000/test-search
Testing Different Queries
Create a batch of test queries to verify consistency:
const testQueries = [
"fire and sacrifice",
"cosmic order rita",
"hymn to dawn",
"Indra god of thunder",
"creation of the universe"
];
for (const query of testQueries) {
// Run search and record results
// Compare relevance scores
// Verify results are semantically similar
}
Memory Profiling
Use browser DevTools to monitor memory:
- Open DevTools → Performance tab
- Start recording
- Initialize system
- Run several searches
- Check memory usage and GC behavior
Expected memory usage:
- EmbeddingGemma model: ~200MB
- Binary index: ~20MB
- Orama database: ~50-100MB
- Total: ~270-320MB
Integration Testing
To test the full integration in the main app:
-
Run the development server:
npm run dev -
Open the main app:
http://localhost:3000 -
Select a model and wait for it to load
-
Ask a Sanskrit-related question:
- "What is dharma in the Rigveda?"
- "Tell me about Agni"
- "Explain the concept of rita"
-
Observe the agent workflow:
- Orchestrator classifies the query
- Searcher agent performs semantic search
- Generator agent creates response
-
Check browser console for detailed logs
Benchmarking
Record performance metrics across multiple runs:
| Run | Init Time | Embed Time | Search Time | Results Found |
|---|---|---|---|---|
| 1 | 45s | 320ms | 25ms | 10 |
| 2 | 8s | 280ms | 18ms | 10 |
| 3 | 7s | 295ms | 22ms | 10 |
Average the results to get baseline performance.
Automated Testing
For automated testing, consider using:
- Playwright for browser automation
- Jest for unit tests
- Cypress for E2E tests
Example Playwright test:
test('semantic search works', async ({ page }) => {
await page.goto('http://localhost:3000/test-search');
// Initialize
await page.click('#initBtn');
await page.waitForSelector('.status.success', { timeout: 120000 });
// Search
await page.fill('#queryInput', 'fire sacrifice');
await page.click('#searchBtn');
await page.waitForSelector('.result', { timeout: 10000 });
// Verify results
const results = await page.$$('.result');
expect(results.length).toBeGreaterThan(0);
});
Continuous Integration
Add search testing to CI/CD pipeline:
- name: Test Search
run: |
npm run build
npx serve out &
sleep 5
npx playwright test tests/search.spec.js
Reporting Issues
When reporting search issues, include:
- Browser and version
- Operating system
- Query that failed
- Console output (errors and warnings)
- Network tab (for download issues)
- Performance metrics
- Steps to reproduce
Success Criteria
The search system is working correctly when:
- ✅ Model loads without errors
- ✅ Binary index loads completely
- ✅ Documents are inserted into Orama
- ✅ Query embeddings are generated (512d)
- ✅ Search returns relevant results
- ✅ Performance is within expected ranges
- ✅ Memory usage is reasonable
- ✅ Multiple queries work consistently
- ✅ Results are semantically relevant to queries