Perform a semantic search across all your materials.
Copy
Ask AI
const searchResults = await client.v1.materials.search({ query: 'What is photosynthesis and how does it work?', topK: 5 // Number of results to return});searchResults.results.forEach(result => { console.log(`Score: ${result.score}`); console.log(`Material: ${result.material.name}`); console.log(`Chunk: ${result.text.substring(0, 200)}...`); console.log('---');});
{ "query": "What is photosynthesis and how does it work?", "totalResults": 5, "results": [ { "score": 0.92, "text": "Photosynthesis is the process by which plants convert light energy into chemical energy...", "chunkIndex": 3, "material": { "id": "mat_123abc", "name": "Biology Chapter 3 - Plant Processes", "contentType": "pdf" } }, { "score": 0.87, "text": "The light-dependent reactions of photosynthesis occur in the thylakoid membranes...", "chunkIndex": 5, "material": { "id": "mat_456def", "name": "Plant Biology Textbook", "contentType": "pdf" } } ]}
// Get more results for comprehensive coverageconst results = await client.v1.materials.search({ query: 'cellular respiration and ATP production', topK: 20 // Get top 20 results});console.log(`Found ${results.totalResults} relevant chunks`);