| 128 | }; |
| 129 | |
| 130 | const indexQuery = async () => { |
| 131 | if (!query) { |
| 132 | console.warn('Please provide a query string.'); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | try { |
| 137 | const queryEmbedding = await cactusLM.embed({ text: query }); |
| 138 | const queryResult = await cactusIndex.query({ |
| 139 | embeddings: [queryEmbedding.embedding], |
| 140 | options: { topK: 3, scoreThreshold: 0.1 }, |
| 141 | }); |
| 142 | |
| 143 | console.log('Query results:', queryResult); |
| 144 | setQueryResults(queryResult); |
| 145 | |
| 146 | if (!queryResult.ids[0]) { |
| 147 | console.log('No results found for the query.'); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | setGetResults(await cactusIndex.get({ ids: queryResult.ids[0] })); |
| 152 | } catch (e) { |
| 153 | console.error('Error querying index:', e); |
| 154 | return; |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | if (cactusLM.isDownloading) { |
| 159 | return ( |