This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const fs = require('fs');
|
||||
const { RecursiveCharacterTextSplitter } = require('@langchain/textsplitter');
|
||||
const { addDocuments, clearVectorStore } = require('./vectorStore');
|
||||
const agent = require('./agent');
|
||||
|
||||
async function addDocumentFromFile(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`File not found: ${filePath}`);
|
||||
}
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
const splitter = new RecursiveCharacterTextSplitter({
|
||||
chunkSize: 1000,
|
||||
chunkOverlap: 200,
|
||||
});
|
||||
const docs = await splitter.splitText(content);
|
||||
await addDocuments(docs);
|
||||
console.log(`Added ${docs.length} chunks from ${filePath}`);
|
||||
}
|
||||
|
||||
async function clearMemory() {
|
||||
await clearVectorStore();
|
||||
console.log('Cleared vector store memory.');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addDocumentFromFile,
|
||||
clearMemory,
|
||||
agent,
|
||||
};
|
||||
Reference in New Issue
Block a user