MCPcopy Index your code
hub / github.com/CommandCodeAI/BaseAI / embedMemory

Function embedMemory

packages/baseai/src/memory/embed.ts:15–108  ·  view source on GitHub ↗
({
	memoryName: memoryNameInput,
	overwrite,
	useLocalEmbeddings
}: {
	memoryName: string;
	overwrite?: boolean;
	useLocalEmbeddings?: boolean;
})

Source from the content-addressed store, hash-verified

13import color from 'picocolors';
14
15export 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 =>

Callers 2

index.tsFile · 0.90
setLocalEmbeddingsConfigFunction · 0.90

Calls 11

headingFunction · 0.90
validateMemoryNameFunction · 0.90
checkMemoryExistsFunction · 0.90
loadMemoryFilesFunction · 0.90
handleGitSyncMemoriesFunction · 0.90
generateEmbeddingsFunction · 0.90
updateEmbeddedCommitHashFunction · 0.90
loadMemoryConfigFunction · 0.85
deleteDocumentsFromDBFunction · 0.85
cancelMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected