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
fc65e6b9
Commit
fc65e6b9
authored
1 year ago
by
Logan Markewich
Browse files
Options
Downloads
Patches
Plain Diff
initial storage examples attempt
parent
629bd323
No related branches found
Branches containing commit
Tags
@llamaindex/autotool@3.0.19
@llamaindex/experimental@0.0.97
llamaindex@0.6.19
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/storageContext.ts
+37
-0
37 additions, 0 deletions
examples/storageContext.ts
packages/core/src/tests/StorageContext.test.ts
+17
-0
17 additions, 0 deletions
packages/core/src/tests/StorageContext.test.ts
with
54 additions
and
0 deletions
examples/storageContext.ts
0 → 100644
+
37
−
0
View file @
fc65e6b9
import
fs
from
"
fs/promises
"
;
import
{
Document
,
VectorStoreIndex
,
storageContextFromDefaults
}
from
"
llamaindex
"
;
async
function
main
()
{
// Load essay from abramov.txt in Node
const
essay
=
await
fs
.
readFile
(
"
node_modules/llamaindex/examples/abramov.txt
"
,
"
utf-8
"
);
// Create Document object with essay
const
document
=
new
Document
({
text
:
essay
});
// Split text and create embeddings. Store them in a VectorStoreIndex
// persist the vector store automatically with the storage context
const
storageContext
=
await
storageContextFromDefaults
({
persistDir
:
"
./storage
"
});
const
index
=
await
VectorStoreIndex
.
fromDocuments
([
document
],
storageContext
);
// Query the index
const
queryEngine
=
index
.
asQueryEngine
();
const
response
=
await
queryEngine
.
query
(
"
What did the author do in college?
"
);
// Output response
console
.
log
(
response
.
toString
());
// load the index
const
loadedIndex
=
await
VectorStoreIndex
.
fromDocuments
([],
storageContext
);
const
laodedQueryEngine
=
loadedIndex
.
asQueryEngine
();
const
loadedResponse
=
await
laodedQueryEngine
.
query
(
"
What did the author do growing up?
"
);
console
.
log
(
loadedResponse
.
toString
());
}
main
().
catch
(
console
.
error
);
This diff is collapsed.
Click to expand it.
packages/core/src/tests/StorageContext.test.ts
0 → 100644
+
17
−
0
View file @
fc65e6b9
import
{
existsSync
,
rmSync
}
from
"
fs
"
;
import
{
storageContextFromDefaults
,
StorageContext
}
from
"
../storage/StorageContext
"
;
import
{
Document
}
from
"
../Node
"
;
import
{
VectorStoreIndex
}
from
"
../indices
"
;
import
{
ListIndex
}
from
"
../indices
"
;
describe
(
"
StorageContext
"
,
()
=>
{
test
(
"
initializes
"
,
async
()
=>
{
const
storageContext
=
await
storageContextFromDefaults
({
persistDir
:
"
/tmp/test_dir
"
});
expect
(
existsSync
(
"
/tmp/test_dir
"
)).
toBe
(
true
);
expect
(
storageContext
).
toBeDefined
();
// cleanup
rmSync
(
"
/tmp/test_dir
"
,
{
recursive
:
true
});
});
});
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