Zack Saadioui
8/26/2024
1
2
bash
npm install llamaindex
1
OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXX
1
dotenv
1
2
bash
npm install dotenv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import fs from 'fs/promises'; import { Document, VectorStoreIndex } from 'llamaindex'; async function main() { // Load some document, say an essay const documentContent = await fs.readFile('path/to/your/document.txt', 'utf-8'); const document = new Document({ text: documentContent }); // Create an index from the document const index = await VectorStoreIndex.fromDocuments([document]); const queryEngine = index.asQueryEngine(); // Now, let's query the index! const response = await queryEngine.query({ query: 'What is the main idea of this essay?' }); console.log(response.toString()); } main();
Copyright © Arsturn 2024