Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
bc594a06
Commit
bc594a06
authored
11 months ago
by
Marcus Schiesser
Browse files
Options
Downloads
Patches
Plain Diff
doc: update vector index example to show source nodes
parent
208282d6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/vectorIndex.ts
+10
-4
10 additions, 4 deletions
examples/vectorIndex.ts
with
10 additions
and
4 deletions
examples/vectorIndex.ts
+
10
−
4
View file @
bc594a06
import
fs
from
"
node:fs/promises
"
;
import
fs
from
"
node:fs/promises
"
;
import
{
Document
,
VectorStoreIndex
}
from
"
llamaindex
"
;
import
{
Document
,
NodeWithScore
,
VectorStoreIndex
}
from
"
llamaindex
"
;
async
function
main
()
{
async
function
main
()
{
// Load essay from abramov.txt in Node
// Load essay from abramov.txt in Node
...
@@ -16,12 +16,18 @@ async function main() {
...
@@ -16,12 +16,18 @@ async function main() {
// Query the index
// Query the index
const
queryEngine
=
index
.
asQueryEngine
();
const
queryEngine
=
index
.
asQueryEngine
();
const
response
=
await
queryEngine
.
query
({
const
{
response
,
sourceNodes
}
=
await
queryEngine
.
query
({
query
:
"
What did the author do in college?
"
,
query
:
"
What did the author do in college?
"
,
});
});
// Output response
// Output response with sources
console
.
log
(
response
.
toString
());
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
);
main
().
catch
(
console
.
error
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment