({
memoryName: memoryNameInput,
overwrite,
useLocalEmbeddings
}: {
memoryName: string;
overwrite?: boolean;
useLocalEmbeddings?: boolean;
})
| 13 | import color from 'picocolors'; |
| 14 | |
| 15 | export async function embedMemory({ |
| 16 | memoryName: memoryNameInput, |
| 17 | overwrite, |
| 18 | useLocalEmbeddings |
| 19 | }: { |
| 20 | memoryName: string; |
| 21 | overwrite?: boolean; |
| 22 | useLocalEmbeddings?: boolean; |
| 23 | }) { |
| 24 | // Spinner to show current action. |
| 25 | const s = p.spinner(); |
| 26 | |
| 27 | try { |
| 28 | p.intro( |
| 29 | heading({ |
| 30 | text: 'EMBED', |
| 31 | sub: `Creating embeddings of ${color.cyan(memoryNameInput)}` |
| 32 | }) |
| 33 | ); |
| 34 | |
| 35 | if (!memoryNameInput) { |
| 36 | p.cancel( |
| 37 | 'Memory name is required. Use --memory or -m flag to specify.' |
| 38 | ); |
| 39 | process.exit(1); |
| 40 | } |
| 41 | |
| 42 | // 1- Check memory exists. |
| 43 | const memoryName = validateMemoryName(memoryNameInput); |
| 44 | await checkMemoryExists(memoryName); |
| 45 | |
| 46 | // 2- Load memory data. |
| 47 | s.start('Processing memory docs...'); |
| 48 | let memoryFiles = await loadMemoryFiles(memoryName); |
| 49 | |
| 50 | if (memoryFiles.length === 0) { |
| 51 | p.cancel(`No valid documents found in memory '${memoryName}'.`); |
| 52 | process.exit(1); |
| 53 | } |
| 54 | |
| 55 | // 3- Get memory config. |
| 56 | const memoryConfig = await loadMemoryConfig(memoryName); |
| 57 | |
| 58 | let filesToEmbed: string[] = []; |
| 59 | let filesToDelete: string[] = []; |
| 60 | |
| 61 | if (memoryConfig.git.enabled) { |
| 62 | const { filesToDeploy, filesToDelete: gitFilesToDelete } = |
| 63 | await handleGitSyncMemories({ |
| 64 | memoryName: memoryName, |
| 65 | config: memoryConfig |
| 66 | }); |
| 67 | |
| 68 | filesToEmbed = filesToDeploy; |
| 69 | filesToDelete = gitFilesToDelete; |
| 70 | |
| 71 | // Filter memory files to emebed |
| 72 | memoryFiles = memoryFiles.filter(doc => |
no test coverage detected