( memoryNames: string[] )
| 179 | } |
| 180 | |
| 181 | export async function getDocumentsFromMemory( |
| 182 | memoryNames: string[] |
| 183 | ): Promise<MemoryChunk[]> { |
| 184 | const memoryChunks: MemoryChunk[] = []; |
| 185 | |
| 186 | // Load each memory and get the documents |
| 187 | for (const memoryName of memoryNames) { |
| 188 | // Load the memory |
| 189 | const db: Low<Schema> = await loadDb(memoryName); |
| 190 | |
| 191 | // Process the documents |
| 192 | for (const [docName, document] of Object.entries(db.data.documents)) { |
| 193 | // Get the chunks for the document |
| 194 | const chunks = document.chunkIds.map(id => { |
| 195 | const chunk = db.data.chunks[id]; |
| 196 | return { |
| 197 | text: chunk.text, |
| 198 | embedding: chunk.embedding, |
| 199 | attributes: { |
| 200 | memoryName, |
| 201 | docName |
| 202 | } |
| 203 | }; |
| 204 | }); |
| 205 | |
| 206 | // Add the processed document to the list |
| 207 | memoryChunks.push(...chunks); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // Return the processed documents |
| 212 | return memoryChunks; |
| 213 | } |
| 214 | |
| 215 | export function cosineSimilaritySearch({ |
| 216 | chunks, |
no test coverage detected