Skip to content
Snippets Groups Projects
Commit bc594a06 authored by Marcus Schiesser's avatar Marcus Schiesser
Browse files

doc: update vector index example to show source nodes

parent 208282d6
No related branches found
No related tags found
No related merge requests found
import fs from "node:fs/promises";
import { Document, VectorStoreIndex } from "llamaindex";
import { Document, NodeWithScore, VectorStoreIndex } from "llamaindex";
async function main() {
// Load essay from abramov.txt in Node
......@@ -16,12 +16,18 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({
const { response, sourceNodes } = await queryEngine.query({
query: "What did the author do in college?",
});
// Output response
console.log(response.toString());
// Output response with sources
console.log(response);
sourceNodes.forEach((source: NodeWithScore, index: number) => {
console.log(
`\n${index}: Score: ${source.score} - ${source.node.text.substring(0, 50)}...\n`,
);
});
}
main().catch(console.error);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment