Skip to content
Snippets Groups Projects
Unverified Commit 8386510d authored by Jingyi Zhao's avatar Jingyi Zhao Committed by GitHub
Browse files

chore: add e2e working example for ingestion (#1543)

parent b504303c
No related branches found
No related tags found
No related merge requests found
import fs from "node:fs/promises";
import { import {
Document, Document,
IngestionPipeline, IngestionPipeline,
MetadataMode,
OpenAIEmbedding, OpenAIEmbedding,
SentenceSplitter, SentenceSplitter,
VectorStoreIndex,
} from "llamaindex"; } from "llamaindex";
import fs from "node:fs/promises";
async function main() { async function main() {
// Load essay from abramov.txt in Node // Load essay from abramov.txt in Node
const path = "node_modules/llamaindex/examples/abramov.txt"; const path = "../node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8"); const essay = await fs.readFile(path, "utf-8");
...@@ -22,14 +21,23 @@ async function main() { ...@@ -22,14 +21,23 @@ async function main() {
new OpenAIEmbedding(), new OpenAIEmbedding(),
], ],
}); });
console.time("Pipeline Run Time");
// run the pipeline
const nodes = await pipeline.run({ documents: [document] }); const nodes = await pipeline.run({ documents: [document] });
// print out the result of the pipeline run console.timeEnd("Pipeline Run Time");
for (const node of nodes) {
console.log(node.getContent(MetadataMode.NONE)); // initialize the VectorStoreIndex from nodes
} const index = await VectorStoreIndex.init({ nodes });
// Query the index
const queryEngine = index.asQueryEngine();
const { message } = await queryEngine.query({
query: "summarize the article in three sentence",
});
console.log(message);
} }
main().catch(console.error); main().catch(console.error);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment