Compare commits

...

31 Commits

Author SHA1 Message Date
Yi Ding 824c13cb85 changesets 2023-08-15 08:51:26 -07:00
Yi Ding 0904d3dc5d allow adding of nodes with hash comparisons
Allows our scripts to be run repeatedly with vector store backing and
persistence without throwing an error.

This is rudimentary support which doesn't work if the document has
changed over time.

Also added the insert and delete functions so that documents can be
added manually.
2023-08-15 08:49:06 -07:00
Yi Ding 18b8915f22 changeset 2023-08-09 15:20:09 -07:00
Yi Ding 9bbfc2414e example npm update 2023-08-09 14:50:38 -07:00
yisding 9487aa1ed5 Merge pull request #65 from TomPenguin/export-store
Export storage
2023-08-09 06:30:27 -07:00
TomPenguin fd74c52fe8 export storage 2023-08-09 18:13:27 +09:00
Yi Ding 0d2bf51a2e 0.0.17 2023-08-08 18:13:08 -07:00
yisding 551c0edadf Merge pull request #64 from run-llama/llama2-fixes
Llama2 4bit support
2023-08-08 18:10:26 -07:00
Yi Ding f80b06293b changed default temp to 0.1 2023-08-08 17:28:56 -07:00
Yi Ding b3fec86413 Llama2 fixes with 4 bit model support 2023-08-08 17:22:42 -07:00
Yi Ding ab886a34d7 add other @tyre PR to the CHANGELOG 2023-08-07 06:46:11 -07:00
Yi Ding 1ec9da120e 0.0.16 2023-08-07 06:30:23 -07:00
yisding 817178272d Merge pull request #59 from run-llama/azure
add azure OpenAI
2023-08-07 06:28:40 -07:00
Yi Ding 3316c6b41c add azure OpenAI
Update OpenAI v4 to latest beta and fixed a few bugs
2023-08-07 06:23:47 -07:00
Yi Ding 9214b0669d fix persistence bug 2023-08-04 23:33:16 -07:00
yisding b3d659b9af Merge pull request #58 from tyre/index-constructor
add constructor to index node so it keeps passed-in indexId
2023-08-02 14:37:25 -07:00
Chris Maddox 05b0fca610 add constructor to index node so it keeps passed-in indexId 2023-08-02 22:33:20 +02:00
yisding 64b909f436 Merge pull request #57 from tyre/typed-filters
add a filter type to exact match filters
2023-08-01 16:09:11 -07:00
Chris Maddox a2e6299aaa add a filter type to exact match filters 2023-08-02 01:04:28 +02:00
yisding 1fbfcab55e Merge pull request #55 from run-llama/repo-maintenance
Repo maintenance
2023-08-01 08:15:39 -07:00
Yi Ding 7db567ea74 remove unnecessary package-lock.json from docs
Also ran some upgrades on npm/pnpm
pnpm install should install the right packages without the
package-lock.json in the docs folder
2023-08-01 08:11:12 -07:00
Yi Ding 6354c16776 add the docs/api folder back in 2023-08-01 08:01:59 -07:00
Yi Ding eb4c3dd3c7 Revert "try replacing CONTRIBUTING and README with symlinks"
This reverts commit 8a4330132c.

Symlinks didn't quite work
2023-07-31 22:54:31 -07:00
Yi Ding 8a4330132c try replacing CONTRIBUTING and README with symlinks
Avoid duplication
2023-07-31 22:49:48 -07:00
Yi Ding f2d4f828d4 repo maintenance
upgrade packages
update docs
update README and CONTRIBUTING
2023-07-31 22:47:13 -07:00
Yi Ding fe8030a9ad updated docs and removed trim vuln
dependabot was complaining about the trim version in the docusaurus so
pinned it to a non-vuln version
2023-07-31 10:50:43 -07:00
Yi Ding ec12633ae0 changeset for #54 2023-07-31 10:30:16 -07:00
yisding 5e24733e41 Merge pull request #54 from tyre/async-vector-stores
make VectorStore function signatures unique, export VectorStore types
2023-07-31 10:23:12 -07:00
Chris Maddox a13911435f make VectorStore function signatures unique, export VectorStore types to allow for extensions 2023-07-31 19:15:50 +02:00
Yi Ding 857bb4596a 0.0.15 2023-07-31 00:29:57 -07:00
yisding 1359de75b5 Merge pull request #52 from run-llama/anthropic
Anthropic support
2023-07-31 00:28:51 -07:00
103 changed files with 3663 additions and 14164 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
Breaking: allow documents to be reimported with hash checking.
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
Update storage exports (thanks @TomPenguin)
-5
View File
@@ -1,5 +0,0 @@
---
"llamaindex": patch
---
Added Anthropic Claude support
-5
View File
@@ -1,5 +0,0 @@
---
"llamaindex": patch
---
Add Top P
+5
View File
@@ -0,0 +1,5 @@
---
"llamaindex": patch
---
Breaking: removed nodeId and docId. Just use id\_
+4 -2
View File
@@ -12,7 +12,7 @@ apps/simple is where the demo code lives
### Turborepo docs
You can checkout how Turborepo works using the built in [README-turborepo.md](README-turborepo.md)
You can checkout how Turborepo works using the default [README-turborepo.md](/README-turborepo.md)
## Getting Started
@@ -41,12 +41,14 @@ To run them, run
pnpm run test
```
To write new test cases write them in packages/core/src/tests
To write new test cases write them in [packages/core/src/tests](/packages/core/src/tests)
We use Jest https://jestjs.io/ to write our test cases. Jest comes with a bunch of built in assertions using the expect function: https://jestjs.io/docs/expect
### Demo applications
There is an existing ["simple"](/apps/simple/README.md) demos folder with mainly NodeJS scripts. Feel free to add additional demos to that folder. If you would like to try out your changes in the core package with a new demo, you need to run the build command in the README.
You can create new demo applications in the apps folder. Just run pnpm init in the folder after you create it to create its own package.json
### Installing packages
+23 -17
View File
@@ -64,29 +64,35 @@ Then you can run it using
pnpm dlx ts-node example.ts
```
## Core concepts for getting started:
- [Document](packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Node](packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Embedding](packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Indices](packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [QueryEngine](packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [ChatEngine](packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [SimplePrompt](packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
## Playground
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
## Core concepts for getting started:
- [Document](/packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Node](/packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Embedding](/packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Indices](/packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [QueryEngine](/packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [ChatEngine](/packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [SimplePrompt](/packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
## Supported LLMs:
- OpenAI GPT-3.5-turbo and GPT-4
- Anthropic Claude Instant and Claude 2
- Llama2 Chat LLMs (70B, 13B, and 7B parameters)
## Contributing:
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](CONTRIBUTING.md)
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
## Bugs? Questions?
+22 -12
View File
@@ -26,7 +26,7 @@ Anthropic LLM implementation
#### Defined in
[llm/LLM.ts:343](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L343)
[llm/LLM.ts:449](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L449)
## Properties
@@ -36,7 +36,7 @@ Anthropic LLM implementation
#### Defined in
[llm/LLM.ts:336](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L336)
[llm/LLM.ts:442](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L442)
___
@@ -46,7 +46,7 @@ ___
#### Defined in
[llm/LLM.ts:341](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L341)
[llm/LLM.ts:447](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L447)
___
@@ -56,7 +56,7 @@ ___
#### Defined in
[llm/LLM.ts:337](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L337)
[llm/LLM.ts:443](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L443)
___
@@ -66,7 +66,7 @@ ___
#### Defined in
[llm/LLM.ts:333](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L333)
[llm/LLM.ts:439](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L439)
___
@@ -76,7 +76,7 @@ ___
#### Defined in
[llm/LLM.ts:331](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L331)
[llm/LLM.ts:436](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L436)
___
@@ -86,7 +86,7 @@ ___
#### Defined in
[llm/LLM.ts:339](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L339)
[llm/LLM.ts:445](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L445)
___
@@ -96,7 +96,7 @@ ___
#### Defined in
[llm/LLM.ts:332](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L332)
[llm/LLM.ts:437](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L437)
___
@@ -106,7 +106,17 @@ ___
#### Defined in
[llm/LLM.ts:338](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L338)
[llm/LLM.ts:444](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L444)
___
### topP
**topP**: `number`
#### Defined in
[llm/LLM.ts:438](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L438)
## Methods
@@ -133,7 +143,7 @@ Get a chat response from the LLM
#### Defined in
[llm/LLM.ts:377](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L377)
[llm/LLM.ts:484](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L484)
___
@@ -160,7 +170,7 @@ Get a prompt completion from the LLM
#### Defined in
[llm/LLM.ts:394](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L394)
[llm/LLM.ts:502](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L502)
___
@@ -180,4 +190,4 @@ ___
#### Defined in
[llm/LLM.ts:362](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L362)
[llm/LLM.ts:469](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L469)
+3 -3
View File
@@ -36,7 +36,7 @@ custom_edit_url: null
#### Defined in
[Embedding.ts:206](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L206)
[Embedding.ts:213](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L213)
___
@@ -56,7 +56,7 @@ ___
#### Defined in
[Embedding.ts:205](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L205)
[Embedding.ts:212](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L212)
___
@@ -78,4 +78,4 @@ ___
#### Defined in
[Embedding.ts:197](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L197)
[Embedding.ts:204](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L204)
+73 -10
View File
@@ -43,7 +43,7 @@ they can be retrieved for our queries.
#### Defined in
[indices/BaseIndex.ts:122](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L122)
[indices/BaseIndex.ts:130](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L130)
## Properties
@@ -53,7 +53,7 @@ they can be retrieved for our queries.
#### Defined in
[indices/BaseIndex.ts:117](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L117)
[indices/BaseIndex.ts:125](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L125)
___
@@ -63,7 +63,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L119)
[indices/BaseIndex.ts:127](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L127)
___
@@ -73,7 +73,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:120](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L120)
[indices/BaseIndex.ts:128](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L128)
___
@@ -83,7 +83,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:115](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L115)
[indices/BaseIndex.ts:123](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L123)
___
@@ -93,17 +93,17 @@ ___
#### Defined in
[indices/BaseIndex.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L116)
[indices/BaseIndex.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L124)
___
### vectorStore
`Optional` **vectorStore**: `VectorStore`
`Optional` **vectorStore**: [`VectorStore`](../interfaces/VectorStore.md)
#### Defined in
[indices/BaseIndex.ts:118](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L118)
[indices/BaseIndex.ts:126](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L126)
## Methods
@@ -128,7 +128,7 @@ and response synthezier if they are not provided.
#### Defined in
[indices/BaseIndex.ts:142](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L142)
[indices/BaseIndex.ts:150](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L150)
___
@@ -150,4 +150,67 @@ Create a new retriever from the index.
#### Defined in
[indices/BaseIndex.ts:135](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L135)
[indices/BaseIndex.ts:143](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L143)
___
### deleteRefDoc
`Abstract` **deleteRefDoc**(`refDocId`, `deleteFromDocStore?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
| `deleteFromDocStore?` | `boolean` |
#### Returns
`Promise`<`void`\>
#### Defined in
[indices/BaseIndex.ts:168](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L168)
___
### insert
**insert**(`document`): `Promise`<`void`\>
Insert a document into the index.
#### Parameters
| Name | Type |
| :------ | :------ |
| `document` | [`Document`](Document.md) |
#### Returns
`Promise`<`void`\>
#### Defined in
[indices/BaseIndex.ts:159](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L159)
___
### insertNodes
`Abstract` **insertNodes**(`nodes`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodes` | [`BaseNode`](BaseNode.md)[] |
#### Returns
`Promise`<`void`\>
#### Defined in
[indices/BaseIndex.ts:167](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L167)
+54 -33
View File
@@ -28,7 +28,7 @@ Generic abstract class for retrievable nodes
#### Defined in
[Node.ts:48](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L48)
[Node.ts:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L55)
## Properties
@@ -38,7 +38,7 @@ Generic abstract class for retrievable nodes
#### Defined in
[Node.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L39)
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
___
@@ -48,7 +48,7 @@ ___
#### Defined in
[Node.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L43)
[Node.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L50)
___
@@ -58,7 +58,7 @@ ___
#### Defined in
[Node.ts:44](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L44)
[Node.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L51)
___
@@ -68,7 +68,7 @@ ___
#### Defined in
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
[Node.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L53)
___
@@ -76,9 +76,14 @@ ___
**id\_**: `string`
The unique ID of the Node/Document. The trailing underscore is here
to avoid collisions with the id keyword in Python.
Set to a UUID by default.
#### Defined in
[Node.ts:38](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L38)
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
___
@@ -88,7 +93,7 @@ ___
#### Defined in
[Node.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L42)
[Node.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L49)
___
@@ -98,7 +103,7 @@ ___
#### Defined in
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
[Node.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L52)
## Accessors
@@ -112,7 +117,7 @@ ___
#### Defined in
[Node.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L104)
[Node.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L107)
___
@@ -126,21 +131,7 @@ ___
#### Defined in
[Node.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L84)
___
### nodeId
`get` **nodeId**(): `string`
#### Returns
`string`
#### Defined in
[Node.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L58)
[Node.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L87)
___
@@ -154,7 +145,7 @@ ___
#### Defined in
[Node.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L94)
[Node.ts:97](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L97)
___
@@ -168,7 +159,7 @@ ___
#### Defined in
[Node.ts:72](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L72)
[Node.ts:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L75)
___
@@ -182,7 +173,7 @@ ___
#### Defined in
[Node.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L62)
[Node.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L65)
## Methods
@@ -196,7 +187,21 @@ ___
#### Defined in
[Node.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L124)
[Node.ts:129](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L129)
___
### generateHash
`Abstract` **generateHash**(): `string`
#### Returns
`string`
#### Defined in
[Node.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L119)
___
@@ -216,7 +221,7 @@ ___
#### Defined in
[Node.ts:54](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L54)
[Node.ts:61](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L61)
___
@@ -230,7 +235,7 @@ ___
#### Defined in
[Node.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L116)
[Node.ts:121](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L121)
___
@@ -250,7 +255,7 @@ ___
#### Defined in
[Node.ts:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L55)
[Node.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L62)
___
@@ -264,7 +269,7 @@ ___
#### Defined in
[Node.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L52)
[Node.ts:59](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L59)
___
@@ -284,4 +289,20 @@ ___
#### Defined in
[Node.ts:56](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L56)
[Node.ts:63](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L63)
___
### toJSON
**toJSON**(): `Record`<`string`, `any`\>
Used with built in JSON.stringify
#### Returns
`Record`<`string`, `any`\>
#### Defined in
[Node.ts:141](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L141)
+56 -60
View File
@@ -32,7 +32,7 @@ A document is just a special text node with a docId.
#### Defined in
[Node.ts:216](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L216)
[Node.ts:257](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L257)
## Properties
@@ -46,7 +46,7 @@ A document is just a special text node with a docId.
#### Defined in
[Node.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L39)
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[Node.ts:139](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L139)
[Node.ts:152](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L152)
___
@@ -74,7 +74,7 @@ ___
#### Defined in
[Node.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L43)
[Node.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L50)
___
@@ -88,7 +88,7 @@ ___
#### Defined in
[Node.ts:44](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L44)
[Node.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L51)
___
@@ -102,7 +102,7 @@ ___
#### Defined in
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
[Node.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L53)
___
@@ -110,13 +110,18 @@ ___
**id\_**: `string`
The unique ID of the Node/Document. The trailing underscore is here
to avoid collisions with the id keyword in Python.
Set to a UUID by default.
#### Inherited from
[TextNode](TextNode.md).[id_](TextNode.md#id_)
#### Defined in
[Node.ts:38](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L38)
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
___
@@ -130,7 +135,7 @@ ___
#### Defined in
[Node.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L42)
[Node.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L49)
___
@@ -144,7 +149,7 @@ ___
#### Defined in
[Node.ts:142](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L142)
[Node.ts:155](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L155)
___
@@ -158,7 +163,7 @@ ___
#### Defined in
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
[Node.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L52)
___
@@ -172,7 +177,7 @@ ___
#### Defined in
[Node.ts:138](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L138)
[Node.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L151)
___
@@ -186,7 +191,7 @@ ___
#### Defined in
[Node.ts:137](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L137)
[Node.ts:150](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L150)
## Accessors
@@ -204,21 +209,7 @@ TextNode.childNodes
#### Defined in
[Node.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L104)
___
### docId
`get` **docId**(): `string`
#### Returns
`string`
#### Defined in
[Node.ts:225](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L225)
[Node.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L107)
___
@@ -236,25 +227,7 @@ TextNode.nextNode
#### Defined in
[Node.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L84)
___
### nodeId
`get` **nodeId**(): `string`
#### Returns
`string`
#### Inherited from
TextNode.nodeId
#### Defined in
[Node.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L58)
[Node.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L87)
___
@@ -272,7 +245,7 @@ TextNode.parentNode
#### Defined in
[Node.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L94)
[Node.ts:97](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L97)
___
@@ -290,7 +263,7 @@ TextNode.prevNode
#### Defined in
[Node.ts:72](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L72)
[Node.ts:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L75)
___
@@ -308,7 +281,7 @@ TextNode.sourceNode
#### Defined in
[Node.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L62)
[Node.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L65)
## Methods
@@ -326,17 +299,20 @@ TextNode.sourceNode
#### Defined in
[Node.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L124)
[Node.ts:129](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L129)
___
### generateHash
**generateHash**(): `void`
**generateHash**(): `string`
Generate a hash of the text node.
The ID is not part of the hash as it can change independent of content.
#### Returns
`void`
`string`
#### Inherited from
@@ -344,7 +320,7 @@ ___
#### Defined in
[Node.ts:149](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L149)
[Node.ts:173](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L173)
___
@@ -368,7 +344,7 @@ ___
#### Defined in
[Node.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L157)
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
___
@@ -386,7 +362,7 @@ ___
#### Defined in
[Node.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L116)
[Node.ts:121](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L121)
___
@@ -410,7 +386,7 @@ ___
#### Defined in
[Node.ts:162](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L162)
[Node.ts:192](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L192)
___
@@ -433,7 +409,7 @@ ___
#### Defined in
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
[Node.ts:219](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L219)
___
@@ -451,7 +427,7 @@ ___
#### Defined in
[Node.ts:191](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L191)
[Node.ts:223](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L223)
___
@@ -469,7 +445,7 @@ ___
#### Defined in
[Node.ts:221](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L221)
[Node.ts:266](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L266)
___
@@ -493,4 +469,24 @@ ___
#### Defined in
[Node.ts:183](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L183)
[Node.ts:213](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L213)
___
### toJSON
**toJSON**(): `Record`<`string`, `any`\>
Used with built in JSON.stringify
#### Returns
`Record`<`string`, `any`\>
#### Inherited from
[TextNode](TextNode.md).[toJSON](TextNode.md#tojson)
#### Defined in
[Node.ts:141](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L141)
+24 -14
View File
@@ -37,16 +37,6 @@ The underlying structure of each index.
## Properties
### docStore
**docStore**: `Record`<`string`, [`Document`](Document.md)\> = `{}`
#### Defined in
[indices/BaseIndex.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L46)
___
### indexId
**indexId**: `string`
@@ -91,7 +81,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:47](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L47)
[indices/BaseIndex.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L46)
## Methods
@@ -112,7 +102,27 @@ ___
#### Defined in
[indices/BaseIndex.ts:56](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L56)
[indices/BaseIndex.ts:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L55)
___
### delete
**delete**(`nodeId`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodeId` | `string` |
#### Returns
`void`
#### Defined in
[indices/BaseIndex.ts:68](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L68)
___
@@ -130,7 +140,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L49)
[indices/BaseIndex.ts:48](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L48)
___
@@ -148,4 +158,4 @@ ___
#### Defined in
[indices/BaseIndex.ts:61](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L61)
[indices/BaseIndex.ts:60](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L60)
+4 -4
View File
@@ -57,7 +57,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:85](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L85)
[indices/BaseIndex.ts:93](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L93)
___
@@ -81,7 +81,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:86](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L86)
[indices/BaseIndex.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L94)
## Methods
@@ -101,7 +101,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:88](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L88)
[indices/BaseIndex.ts:96](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L96)
___
@@ -137,4 +137,4 @@ ___
#### Defined in
[indices/BaseIndex.ts:92](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L92)
[indices/BaseIndex.ts:100](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L100)
+59 -49
View File
@@ -24,15 +24,15 @@ TextNode is the default node type for text. Most common node type in LlamaIndex.
| Name | Type |
| :------ | :------ |
| `init?` | `Partial`<[`TextNode`](TextNode.md)\> |
| `init?` | `Partial`<[`IndexNode`](IndexNode.md)\> |
#### Inherited from
#### Overrides
[TextNode](TextNode.md).[constructor](TextNode.md#constructor)
#### Defined in
[Node.ts:144](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L144)
[Node.ts:239](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L239)
## Properties
@@ -46,7 +46,7 @@ TextNode is the default node type for text. Most common node type in LlamaIndex.
#### Defined in
[Node.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L39)
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[Node.ts:139](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L139)
[Node.ts:152](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L152)
___
@@ -74,7 +74,7 @@ ___
#### Defined in
[Node.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L43)
[Node.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L50)
___
@@ -88,7 +88,7 @@ ___
#### Defined in
[Node.ts:44](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L44)
[Node.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L51)
___
@@ -102,7 +102,7 @@ ___
#### Defined in
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
[Node.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L53)
___
@@ -110,13 +110,18 @@ ___
**id\_**: `string`
The unique ID of the Node/Document. The trailing underscore is here
to avoid collisions with the id keyword in Python.
Set to a UUID by default.
#### Inherited from
[TextNode](TextNode.md).[id_](TextNode.md#id_)
#### Defined in
[Node.ts:38](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L38)
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
___
@@ -126,7 +131,7 @@ ___
#### Defined in
[Node.ts:205](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L205)
[Node.ts:237](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L237)
___
@@ -140,7 +145,7 @@ ___
#### Defined in
[Node.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L42)
[Node.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L49)
___
@@ -154,7 +159,7 @@ ___
#### Defined in
[Node.ts:142](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L142)
[Node.ts:155](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L155)
___
@@ -168,7 +173,7 @@ ___
#### Defined in
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
[Node.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L52)
___
@@ -182,7 +187,7 @@ ___
#### Defined in
[Node.ts:138](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L138)
[Node.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L151)
___
@@ -196,7 +201,7 @@ ___
#### Defined in
[Node.ts:137](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L137)
[Node.ts:150](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L150)
## Accessors
@@ -214,7 +219,7 @@ TextNode.childNodes
#### Defined in
[Node.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L104)
[Node.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L107)
___
@@ -232,25 +237,7 @@ TextNode.nextNode
#### Defined in
[Node.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L84)
___
### nodeId
`get` **nodeId**(): `string`
#### Returns
`string`
#### Inherited from
TextNode.nodeId
#### Defined in
[Node.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L58)
[Node.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L87)
___
@@ -268,7 +255,7 @@ TextNode.parentNode
#### Defined in
[Node.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L94)
[Node.ts:97](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L97)
___
@@ -286,7 +273,7 @@ TextNode.prevNode
#### Defined in
[Node.ts:72](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L72)
[Node.ts:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L75)
___
@@ -304,7 +291,7 @@ TextNode.sourceNode
#### Defined in
[Node.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L62)
[Node.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L65)
## Methods
@@ -322,17 +309,20 @@ TextNode.sourceNode
#### Defined in
[Node.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L124)
[Node.ts:129](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L129)
___
### generateHash
**generateHash**(): `void`
**generateHash**(): `string`
Generate a hash of the text node.
The ID is not part of the hash as it can change independent of content.
#### Returns
`void`
`string`
#### Inherited from
@@ -340,7 +330,7 @@ ___
#### Defined in
[Node.ts:149](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L149)
[Node.ts:173](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L173)
___
@@ -364,7 +354,7 @@ ___
#### Defined in
[Node.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L157)
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
___
@@ -382,7 +372,7 @@ ___
#### Defined in
[Node.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L116)
[Node.ts:121](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L121)
___
@@ -406,7 +396,7 @@ ___
#### Defined in
[Node.ts:162](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L162)
[Node.ts:192](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L192)
___
@@ -429,7 +419,7 @@ ___
#### Defined in
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
[Node.ts:219](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L219)
___
@@ -447,7 +437,7 @@ ___
#### Defined in
[Node.ts:191](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L191)
[Node.ts:223](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L223)
___
@@ -465,7 +455,7 @@ ___
#### Defined in
[Node.ts:207](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L207)
[Node.ts:248](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L248)
___
@@ -489,4 +479,24 @@ ___
#### Defined in
[Node.ts:183](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L183)
[Node.ts:213](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L213)
___
### toJSON
**toJSON**(): `Record`<`string`, `any`\>
Used with built in JSON.stringify
#### Returns
`Record`<`string`, `any`\>
#### Inherited from
[TextNode](TextNode.md).[toJSON](TextNode.md#tojson)
#### Defined in
[Node.ts:141](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L141)
+112 -56
View File
@@ -32,7 +32,7 @@ A ListIndex keeps nodes in a sequential list structure
#### Defined in
[indices/list/ListIndex.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L43)
[indices/list/ListIndex.ts:47](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L47)
## Properties
@@ -46,7 +46,7 @@ A ListIndex keeps nodes in a sequential list structure
#### Defined in
[indices/BaseIndex.ts:117](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L117)
[indices/BaseIndex.ts:125](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L125)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L119)
[indices/BaseIndex.ts:127](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L127)
___
@@ -74,7 +74,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:120](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L120)
[indices/BaseIndex.ts:128](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L128)
___
@@ -88,7 +88,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:115](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L115)
[indices/BaseIndex.ts:123](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L123)
___
@@ -102,13 +102,13 @@ ___
#### Defined in
[indices/BaseIndex.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L116)
[indices/BaseIndex.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L124)
___
### vectorStore
`Optional` **vectorStore**: `VectorStore`
`Optional` **vectorStore**: [`VectorStore`](../interfaces/VectorStore.md)
#### Inherited from
@@ -116,50 +116,10 @@ ___
#### Defined in
[indices/BaseIndex.ts:118](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L118)
[indices/BaseIndex.ts:126](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L126)
## Methods
### \_deleteNode
`Protected` **_deleteNode**(`nodeId`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodeId` | `string` |
#### Returns
`void`
#### Defined in
[indices/list/ListIndex.ts:193](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L193)
___
### \_insert
`Protected` **_insert**(`nodes`): `void`
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodes` | [`BaseNode`](BaseNode.md)[] |
#### Returns
`void`
#### Defined in
[indices/list/ListIndex.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L187)
___
### asQueryEngine
**asQueryEngine**(`options?`): [`BaseQueryEngine`](../interfaces/BaseQueryEngine.md)
@@ -185,7 +145,7 @@ and response synthezier if they are not provided.
#### Defined in
[indices/list/ListIndex.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L151)
[indices/list/ListIndex.ts:155](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L155)
___
@@ -212,7 +172,53 @@ Create a new retriever from the index.
#### Defined in
[indices/list/ListIndex.ts:138](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L138)
[indices/list/ListIndex.ts:142](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L142)
___
### deleteNodes
**deleteNodes**(`nodeIds`, `deleteFromDocStore`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodeIds` | `string`[] |
| `deleteFromDocStore` | `boolean` |
#### Returns
`Promise`<`void`\>
#### Defined in
[indices/list/ListIndex.ts:216](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L216)
___
### deleteRefDoc
**deleteRefDoc**(`refDocId`, `deleteFromDocStore?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
| `deleteFromDocStore?` | `boolean` |
#### Returns
`Promise`<`void`\>
#### Overrides
[BaseIndex](BaseIndex.md).[deleteRefDoc](BaseIndex.md#deleterefdoc)
#### Defined in
[indices/list/ListIndex.ts:197](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L197)
___
@@ -226,13 +232,63 @@ ___
#### Defined in
[indices/list/ListIndex.ts:199](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L199)
[indices/list/ListIndex.ts:230](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L230)
___
### \_buildIndexFromNodes
### insert
`Static` **_buildIndexFromNodes**(`nodes`, `docStore`, `indexStruct?`): `Promise`<[`IndexList`](IndexList.md)\>
**insert**(`document`): `Promise`<`void`\>
Insert a document into the index.
#### Parameters
| Name | Type |
| :------ | :------ |
| `document` | [`Document`](Document.md) |
#### Returns
`Promise`<`void`\>
#### Inherited from
[BaseIndex](BaseIndex.md).[insert](BaseIndex.md#insert)
#### Defined in
[indices/BaseIndex.ts:159](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L159)
___
### insertNodes
**insertNodes**(`nodes`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodes` | [`BaseNode`](BaseNode.md)[] |
#### Returns
`Promise`<`void`\>
#### Overrides
[BaseIndex](BaseIndex.md).[insertNodes](BaseIndex.md#insertnodes)
#### Defined in
[indices/list/ListIndex.ts:191](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L191)
___
### buildIndexFromNodes
`Static` **buildIndexFromNodes**(`nodes`, `docStore`, `indexStruct?`): `Promise`<[`IndexList`](IndexList.md)\>
#### Parameters
@@ -248,7 +304,7 @@ ___
#### Defined in
[indices/list/ListIndex.ts:172](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L172)
[indices/list/ListIndex.ts:176](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L176)
___
@@ -271,7 +327,7 @@ ___
#### Defined in
[indices/list/ListIndex.ts:112](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L112)
[indices/list/ListIndex.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L116)
___
@@ -291,4 +347,4 @@ ___
#### Defined in
[indices/list/ListIndex.ts:47](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L47)
[indices/list/ListIndex.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L51)
+50 -23
View File
@@ -26,7 +26,7 @@ Llama2 LLM implementation
#### Defined in
[llm/LLM.ts:204](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L204)
[llm/LLM.ts:266](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L266)
## Properties
@@ -36,7 +36,7 @@ Llama2 LLM implementation
#### Defined in
[llm/LLM.ts:199](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L199)
[llm/LLM.ts:260](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L260)
___
@@ -46,17 +46,17 @@ ___
#### Defined in
[llm/LLM.ts:201](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L201)
[llm/LLM.ts:263](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L263)
___
### model
**model**: ``"Llama-2-70b-chat"`` \| ``"Llama-2-13b-chat"`` \| ``"Llama-2-7b-chat"``
**model**: ``"Llama-2-70b-chat-old"`` \| ``"Llama-2-70b-chat-4bit"`` \| ``"Llama-2-13b-chat"`` \| ``"Llama-2-13b-chat-4bit"`` \| ``"Llama-2-7b-chat"`` \| ``"Llama-2-7b-chat-4bit"``
#### Defined in
[llm/LLM.ts:198](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L198)
[llm/LLM.ts:259](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L259)
___
@@ -66,7 +66,7 @@ ___
#### Defined in
[llm/LLM.ts:202](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L202)
[llm/LLM.ts:264](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L264)
___
@@ -76,7 +76,17 @@ ___
#### Defined in
[llm/LLM.ts:200](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L200)
[llm/LLM.ts:261](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L261)
___
### topP
• **topP**: `number`
#### Defined in
[llm/LLM.ts:262](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L262)
## Methods
@@ -103,7 +113,7 @@ Get a chat response from the LLM
#### Defined in
[llm/LLM.ts:294](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L294)
[llm/LLM.ts:385](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L385)
___
@@ -130,7 +140,7 @@ Get a prompt completion from the LLM
#### Defined in
[llm/LLM.ts:317](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L317)
[llm/LLM.ts:422](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L422)
___
@@ -150,13 +160,13 @@ ___
#### Defined in
[llm/LLM.ts:235](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L235)
[llm/LLM.ts:309](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L309)
___
### mapMessagesToPrompt
▸ **mapMessagesToPrompt**(`messages`): `string`
▸ **mapMessagesToPrompt**(`messages`): `Object`
#### Parameters
@@ -166,17 +176,22 @@ ___
#### Returns
`string`
`Object`
| Name | Type |
| :------ | :------ |
| `prompt` | `string` |
| `systemPrompt` | `undefined` \| `string` |
#### Defined in
[llm/LLM.ts:212](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L212)
[llm/LLM.ts:281](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L281)
___
### mapMessagesToPromptA16Z
▸ **mapMessagesToPromptA16Z**(`messages`): `string`
▸ **mapMessagesToPromptA16Z**(`messages`): `Object`
#### Parameters
@@ -186,29 +201,41 @@ ___
#### Returns
`string`
`Object`
| Name | Type |
| :------ | :------ |
| `prompt` | `string` |
| `systemPrompt` | `undefined` |
#### Defined in
[llm/LLM.ts:224](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L224)
[llm/LLM.ts:295](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L295)
___
### mapMessagesToPromptMeta
▸ **mapMessagesToPromptMeta**(`messages`, `withBos?`): `string`
▸ **mapMessagesToPromptMeta**(`messages`, `opts?`): `Object`
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] | `undefined` |
| `withBos` | `boolean` | `false` |
| Name | Type |
| :------ | :------ |
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
| `opts?` | `Object` |
| `opts.replicate4Bit?` | `boolean` |
| `opts.withBos?` | `boolean` |
#### Returns
`string`
`Object`
| Name | Type |
| :------ | :------ |
| `prompt` | `string` |
| `systemPrompt` | `undefined` \| `string` |
#### Defined in
[llm/LLM.ts:248](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L248)
[llm/LLM.ts:322](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L322)
+23 -13
View File
@@ -22,11 +22,11 @@ OpenAI LLM implementation
| Name | Type |
| :------ | :------ |
| `init?` | `Partial`<[`OpenAI`](OpenAI.md)\> |
| `init?` | `Partial`<[`OpenAI`](OpenAI.md)\> & { `azure?`: `AzureOpenAIConfig` } |
#### Defined in
[llm/LLM.ts:86](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L86)
[llm/LLM.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L94)
## Properties
@@ -36,7 +36,7 @@ OpenAI LLM implementation
#### Defined in
[llm/LLM.ts:79](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L79)
[llm/LLM.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L87)
___
@@ -46,7 +46,7 @@ ___
#### Defined in
[llm/LLM.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L84)
[llm/LLM.ts:92](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L92)
___
@@ -56,7 +56,7 @@ ___
#### Defined in
[llm/LLM.ts:80](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L80)
[llm/LLM.ts:88](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L88)
___
@@ -66,7 +66,7 @@ ___
#### Defined in
[llm/LLM.ts:76](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L76)
[llm/LLM.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L84)
___
@@ -76,7 +76,7 @@ ___
#### Defined in
[llm/LLM.ts:74](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L74)
[llm/LLM.ts:81](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L81)
___
@@ -86,7 +86,7 @@ ___
#### Defined in
[llm/LLM.ts:82](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L82)
[llm/LLM.ts:90](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L90)
___
@@ -96,7 +96,7 @@ ___
#### Defined in
[llm/LLM.ts:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L75)
[llm/LLM.ts:82](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L82)
___
@@ -106,7 +106,17 @@ ___
#### Defined in
[llm/LLM.ts:81](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L81)
[llm/LLM.ts:89](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L89)
___
### topP
• **topP**: `number`
#### Defined in
[llm/LLM.ts:83](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L83)
## Methods
@@ -133,7 +143,7 @@ Get a chat response from the LLM
#### Defined in
[llm/LLM.ts:122](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L122)
[llm/LLM.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L157)
___
@@ -160,7 +170,7 @@ Get a prompt completion from the LLM
#### Defined in
[llm/LLM.ts:160](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L160)
[llm/LLM.ts:197](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L197)
___
@@ -180,4 +190,4 @@ ___
#### Defined in
[llm/LLM.ts:105](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L105)
[llm/LLM.ts:140](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L140)
+11 -11
View File
@@ -22,7 +22,7 @@ custom_edit_url: null
| Name | Type |
| :------ | :------ |
| `init?` | `Partial`<[`OpenAIEmbedding`](OpenAIEmbedding.md)\> |
| `init?` | `Partial`<[`OpenAIEmbedding`](OpenAIEmbedding.md)\> & { `azure?`: `AzureOpenAIConfig` } |
#### Overrides
@@ -30,7 +30,7 @@ custom_edit_url: null
#### Defined in
[Embedding.ts:222](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L222)
[Embedding.ts:229](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L229)
## Properties
@@ -40,7 +40,7 @@ custom_edit_url: null
#### Defined in
[Embedding.ts:217](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L217)
[Embedding.ts:224](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L224)
___
@@ -50,7 +50,7 @@ ___
#### Defined in
[Embedding.ts:218](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L218)
[Embedding.ts:225](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L225)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[Embedding.ts:214](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L214)
[Embedding.ts:221](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L221)
___
@@ -70,7 +70,7 @@ ___
#### Defined in
[Embedding.ts:220](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L220)
[Embedding.ts:227](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L227)
___
@@ -80,7 +80,7 @@ ___
#### Defined in
[Embedding.ts:219](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L219)
[Embedding.ts:226](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L226)
## Methods
@@ -100,7 +100,7 @@ ___
#### Defined in
[Embedding.ts:237](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L237)
[Embedding.ts:270](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L270)
___
@@ -124,7 +124,7 @@ ___
#### Defined in
[Embedding.ts:253](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L253)
[Embedding.ts:286](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L286)
___
@@ -148,7 +148,7 @@ ___
#### Defined in
[Embedding.ts:249](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L249)
[Embedding.ts:282](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L282)
___
@@ -174,4 +174,4 @@ ___
#### Defined in
[Embedding.ts:197](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L197)
[Embedding.ts:204](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L204)
@@ -0,0 +1,480 @@
---
id: "SimpleDocumentStore"
title: "Class: SimpleDocumentStore"
sidebar_label: "SimpleDocumentStore"
sidebar_position: 0
custom_edit_url: null
---
## Hierarchy
- `KVDocumentStore`
**`SimpleDocumentStore`**
## Constructors
### constructor
**new SimpleDocumentStore**(`kvStore?`, `namespace?`)
#### Parameters
| Name | Type |
| :------ | :------ |
| `kvStore?` | `SimpleKVStore` |
| `namespace?` | `string` |
#### Overrides
KVDocumentStore.constructor
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:19](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L19)
## Properties
### kvStore
`Private` **kvStore**: `SimpleKVStore`
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:17](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L17)
## Methods
### addDocuments
**addDocuments**(`docs`, `allowUpdate?`): `Promise`<`void`\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `docs` | [`BaseNode`](BaseNode.md)[] | `undefined` |
| `allowUpdate` | `boolean` | `true` |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVDocumentStore.addDocuments
#### Defined in
[storage/docStore/KVDocumentStore.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L33)
___
### deleteDocument
**deleteDocument**(`docId`, `raiseError?`, `removeRefDocNode?`): `Promise`<`void`\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `docId` | `string` | `undefined` |
| `raiseError` | `boolean` | `true` |
| `removeRefDocNode` | `boolean` | `true` |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVDocumentStore.deleteDocument
#### Defined in
[storage/docStore/KVDocumentStore.ts:131](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L131)
___
### deleteRefDoc
**deleteRefDoc**(`refDocId`, `raiseError?`): `Promise`<`void`\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `refDocId` | `string` | `undefined` |
| `raiseError` | `boolean` | `true` |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVDocumentStore.deleteRefDoc
#### Defined in
[storage/docStore/KVDocumentStore.ts:148](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L148)
___
### docs
**docs**(): `Promise`<`Record`<`string`, [`BaseNode`](BaseNode.md)\>\>
#### Returns
`Promise`<`Record`<`string`, [`BaseNode`](BaseNode.md)\>\>
#### Inherited from
KVDocumentStore.docs
#### Defined in
[storage/docStore/KVDocumentStore.ts:24](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L24)
___
### documentExists
**documentExists**(`docId`): `Promise`<`boolean`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `docId` | `string` |
#### Returns
`Promise`<`boolean`\>
#### Inherited from
KVDocumentStore.documentExists
#### Defined in
[storage/docStore/KVDocumentStore.ts:105](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L105)
___
### getAllRefDocInfo
**getAllRefDocInfo**(): `Promise`<`undefined` \| `Record`<`string`, `RefDocInfo`\>\>
#### Returns
`Promise`<`undefined` \| `Record`<`string`, `RefDocInfo`\>\>
#### Inherited from
KVDocumentStore.getAllRefDocInfo
#### Defined in
[storage/docStore/KVDocumentStore.ts:93](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L93)
___
### getDocument
**getDocument**(`docId`, `raiseError?`): `Promise`<`undefined` \| [`BaseNode`](BaseNode.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `docId` | `string` | `undefined` |
| `raiseError` | `boolean` | `true` |
#### Returns
`Promise`<`undefined` \| [`BaseNode`](BaseNode.md)\>
#### Inherited from
KVDocumentStore.getDocument
#### Defined in
[storage/docStore/KVDocumentStore.ts:73](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L73)
___
### getDocumentHash
**getDocumentHash**(`docId`): `Promise`<`undefined` \| `string`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `docId` | `string` |
#### Returns
`Promise`<`undefined` \| `string`\>
#### Inherited from
KVDocumentStore.getDocumentHash
#### Defined in
[storage/docStore/KVDocumentStore.ts:174](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L174)
___
### getNode
**getNode**(`nodeId`, `raiseError?`): `Promise`<[`BaseNode`](BaseNode.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `nodeId` | `string` | `undefined` |
| `raiseError` | `boolean` | `true` |
#### Returns
`Promise`<[`BaseNode`](BaseNode.md)\>
#### Inherited from
KVDocumentStore.getNode
#### Defined in
[storage/docStore/types.ts:57](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/types.ts#L57)
___
### getNodeDict
**getNodeDict**(`nodeIdDict`): `Promise`<`Record`<`number`, [`BaseNode`](BaseNode.md)\>\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodeIdDict` | `Object` |
#### Returns
`Promise`<`Record`<`number`, [`BaseNode`](BaseNode.md)\>\>
#### Inherited from
KVDocumentStore.getNodeDict
#### Defined in
[storage/docStore/types.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/types.ts#L65)
___
### getNodes
**getNodes**(`nodeIds`, `raiseError?`): `Promise`<[`BaseNode`](BaseNode.md)[]\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `nodeIds` | `string`[] | `undefined` |
| `raiseError` | `boolean` | `true` |
#### Returns
`Promise`<[`BaseNode`](BaseNode.md)[]\>
#### Inherited from
KVDocumentStore.getNodes
#### Defined in
[storage/docStore/types.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/types.ts#L51)
___
### getRefDocInfo
**getRefDocInfo**(`refDocId`): `Promise`<`undefined` \| `RefDocInfo`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
#### Returns
`Promise`<`undefined` \| `RefDocInfo`\>
#### Inherited from
KVDocumentStore.getRefDocInfo
#### Defined in
[storage/docStore/KVDocumentStore.ts:88](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L88)
___
### persist
**persist**(`persistPath?`, `fs?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `persistPath` | `string` |
| `fs?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) |
#### Returns
`Promise`<`void`\>
#### Overrides
KVDocumentStore.persist
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L52)
___
### refDocExists
**refDocExists**(`refDocId`): `Promise`<`boolean`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
#### Returns
`Promise`<`boolean`\>
#### Inherited from
KVDocumentStore.refDocExists
#### Defined in
[storage/docStore/KVDocumentStore.ts:101](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L101)
___
### setDocumentHash
**setDocumentHash**(`docId`, `docHash`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `docId` | `string` |
| `docHash` | `string` |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVDocumentStore.setDocumentHash
#### Defined in
[storage/docStore/KVDocumentStore.ts:169](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/KVDocumentStore.ts#L169)
___
### toDict
**toDict**(): `SaveDict`
#### Returns
`SaveDict`
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:73](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L73)
___
### fromDict
`Static` **fromDict**(`saveDict`, `namespace?`): [`SimpleDocumentStore`](SimpleDocumentStore.md)
#### Parameters
| Name | Type |
| :------ | :------ |
| `saveDict` | `SaveDict` |
| `namespace?` | `string` |
#### Returns
[`SimpleDocumentStore`](SimpleDocumentStore.md)
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:68](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L68)
___
### fromPersistDir
`Static` **fromPersistDir**(`persistDir?`, `namespace?`, `fsModule?`): `Promise`<[`SimpleDocumentStore`](SimpleDocumentStore.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `persistDir` | `string` | `DEFAULT_PERSIST_DIR` |
| `namespace?` | `string` | `undefined` |
| `fsModule?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) | `undefined` |
#### Returns
`Promise`<[`SimpleDocumentStore`](SimpleDocumentStore.md)\>
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:26](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L26)
___
### fromPersistPath
`Static` **fromPersistPath**(`persistPath`, `namespace?`, `fs?`): `Promise`<[`SimpleDocumentStore`](SimpleDocumentStore.md)\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `persistPath` | `string` |
| `namespace?` | `string` |
| `fs?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) |
#### Returns
`Promise`<[`SimpleDocumentStore`](SimpleDocumentStore.md)\>
#### Defined in
[storage/docStore/SimpleDocumentStore.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/docStore/SimpleDocumentStore.ts#L42)
@@ -0,0 +1,234 @@
---
id: "SimpleIndexStore"
title: "Class: SimpleIndexStore"
sidebar_label: "SimpleIndexStore"
sidebar_position: 0
custom_edit_url: null
---
## Hierarchy
- `KVIndexStore`
**`SimpleIndexStore`**
## Constructors
### constructor
**new SimpleIndexStore**(`kvStore?`)
#### Parameters
| Name | Type |
| :------ | :------ |
| `kvStore?` | `BaseInMemoryKVStore` |
#### Overrides
KVIndexStore.constructor
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:16](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L16)
## Properties
### kvStore
`Private` **kvStore**: `BaseInMemoryKVStore`
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:14](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L14)
## Methods
### addIndexStruct
**addIndexStruct**(`indexStruct`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `indexStruct` | [`IndexStruct`](IndexStruct.md) |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVIndexStore.addIndexStruct
#### Defined in
[storage/indexStore/KVIndexStore.ts:17](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/KVIndexStore.ts#L17)
___
### deleteIndexStruct
**deleteIndexStruct**(`key`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `key` | `string` |
#### Returns
`Promise`<`void`\>
#### Inherited from
KVIndexStore.deleteIndexStruct
#### Defined in
[storage/indexStore/KVIndexStore.ts:23](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/KVIndexStore.ts#L23)
___
### getIndexStruct
**getIndexStruct**(`structId?`): `Promise`<`undefined` \| [`IndexStruct`](IndexStruct.md)\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `structId?` | `string` |
#### Returns
`Promise`<`undefined` \| [`IndexStruct`](IndexStruct.md)\>
#### Inherited from
KVIndexStore.getIndexStruct
#### Defined in
[storage/indexStore/KVIndexStore.ts:27](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/KVIndexStore.ts#L27)
___
### getIndexStructs
**getIndexStructs**(): `Promise`<[`IndexStruct`](IndexStruct.md)[]\>
#### Returns
`Promise`<[`IndexStruct`](IndexStruct.md)[]\>
#### Inherited from
KVIndexStore.getIndexStructs
#### Defined in
[storage/indexStore/KVIndexStore.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/KVIndexStore.ts#L43)
___
### persist
**persist**(`persistPath?`, `fs?`): `Promise`<`void`\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `persistPath` | `string` | `DEFAULT_PERSIST_DIR` |
| `fs` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) | `DEFAULT_FS` |
#### Returns
`Promise`<`void`\>
#### Overrides
KVIndexStore.persist
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:41](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L41)
___
### toDict
**toDict**(): `Record`<`string`, `unknown`\>
#### Returns
`Record`<`string`, `unknown`\>
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L53)
___
### fromDict
`Static` **fromDict**(`saveDict`): [`SimpleIndexStore`](SimpleIndexStore.md)
#### Parameters
| Name | Type |
| :------ | :------ |
| `saveDict` | `DataType` |
#### Returns
[`SimpleIndexStore`](SimpleIndexStore.md)
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:48](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L48)
___
### fromPersistDir
`Static` **fromPersistDir**(`persistDir?`, `fs?`): `Promise`<[`SimpleIndexStore`](SimpleIndexStore.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `persistDir` | `string` | `DEFAULT_PERSIST_DIR` |
| `fs` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) | `DEFAULT_FS` |
#### Returns
`Promise`<[`SimpleIndexStore`](SimpleIndexStore.md)\>
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L22)
___
### fromPersistPath
`Static` **fromPersistPath**(`persistPath`, `fs?`): `Promise`<[`SimpleIndexStore`](SimpleIndexStore.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `persistPath` | `string` | `undefined` |
| `fs` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) | `DEFAULT_FS` |
#### Returns
`Promise`<[`SimpleIndexStore`](SimpleIndexStore.md)\>
#### Defined in
[storage/indexStore/SimpleIndexStore.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/indexStore/SimpleIndexStore.ts#L33)
@@ -0,0 +1,283 @@
---
id: "SimpleVectorStore"
title: "Class: SimpleVectorStore"
sidebar_label: "SimpleVectorStore"
sidebar_position: 0
custom_edit_url: null
---
## Implements
- [`VectorStore`](../interfaces/VectorStore.md)
## Constructors
### constructor
**new SimpleVectorStore**(`data?`, `fs?`)
#### Parameters
| Name | Type |
| :------ | :------ |
| `data?` | `SimpleVectorStoreData` |
| `fs?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) |
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:37](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L37)
## Properties
### data
`Private` **data**: `SimpleVectorStoreData`
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L33)
___
### fs
`Private` **fs**: [`GenericFileSystem`](../interfaces/GenericFileSystem.md) = `DEFAULT_FS`
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:34](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L34)
___
### persistPath
`Private` **persistPath**: `undefined` \| `string`
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:35](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L35)
___
### storesText
**storesText**: `boolean` = `false`
#### Implementation of
[VectorStore](../interfaces/VectorStore.md).[storesText](../interfaces/VectorStore.md#storestext)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:32](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L32)
## Accessors
### client
`get` **client**(): `any`
#### Returns
`any`
#### Implementation of
VectorStore.client
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L50)
## Methods
### add
**add**(`embeddingResults`): `Promise`<`string`[]\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `embeddingResults` | [`NodeWithEmbedding`](../interfaces/NodeWithEmbedding.md)[] |
#### Returns
`Promise`<`string`[]\>
#### Implementation of
[VectorStore](../interfaces/VectorStore.md).[add](../interfaces/VectorStore.md#add)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L58)
___
### delete
**delete**(`refDocId`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
#### Returns
`Promise`<`void`\>
#### Implementation of
[VectorStore](../interfaces/VectorStore.md).[delete](../interfaces/VectorStore.md#delete)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:78](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L78)
___
### get
**get**(`textId`): `Promise`<`number`[]\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `textId` | `string` |
#### Returns
`Promise`<`number`[]\>
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:54](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L54)
___
### persist
**persist**(`persistPath?`, `fs?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `persistPath` | `string` |
| `fs?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) |
#### Returns
`Promise`<`void`\>
#### Implementation of
[VectorStore](../interfaces/VectorStore.md).[persist](../interfaces/VectorStore.md#persist)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:147](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L147)
___
### query
**query**(`query`): `Promise`<[`VectorStoreQueryResult`](../interfaces/VectorStoreQueryResult.md)\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `query` | [`VectorStoreQuery`](../interfaces/VectorStoreQuery.md) |
#### Returns
`Promise`<[`VectorStoreQueryResult`](../interfaces/VectorStoreQueryResult.md)\>
#### Implementation of
[VectorStore](../interfaces/VectorStore.md).[query](../interfaces/VectorStore.md#query)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:89](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L89)
___
### toDict
**toDict**(): `SimpleVectorStoreData`
#### Returns
`SimpleVectorStoreData`
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:197](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L197)
___
### fromDict
`Static` **fromDict**(`saveDict`): [`SimpleVectorStore`](SimpleVectorStore.md)
#### Parameters
| Name | Type |
| :------ | :------ |
| `saveDict` | `SimpleVectorStoreData` |
#### Returns
[`SimpleVectorStore`](SimpleVectorStore.md)
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:190](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L190)
___
### fromPersistDir
`Static` **fromPersistDir**(`persistDir?`, `fs?`): `Promise`<[`SimpleVectorStore`](SimpleVectorStore.md)\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `persistDir` | `string` | `DEFAULT_PERSIST_DIR` |
| `fs` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) | `DEFAULT_FS` |
#### Returns
`Promise`<[`SimpleVectorStore`](SimpleVectorStore.md)\>
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L42)
___
### fromPersistPath
`Static` **fromPersistPath**(`persistPath`, `fs?`): `Promise`<[`SimpleVectorStore`](SimpleVectorStore.md)\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `persistPath` | `string` |
| `fs?` | [`GenericFileSystem`](../interfaces/GenericFileSystem.md) |
#### Returns
`Promise`<[`SimpleVectorStore`](SimpleVectorStore.md)\>
#### Defined in
[storage/vectorStore/SimpleVectorStore.ts:160](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L160)
+60 -46
View File
@@ -36,7 +36,7 @@ TextNode is the default node type for text. Most common node type in LlamaIndex.
#### Defined in
[Node.ts:144](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L144)
[Node.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L157)
## Properties
@@ -50,7 +50,7 @@ TextNode is the default node type for text. Most common node type in LlamaIndex.
#### Defined in
[Node.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L39)
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[Node.ts:139](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L139)
[Node.ts:152](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L152)
___
@@ -74,7 +74,7 @@ ___
#### Defined in
[Node.ts:43](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L43)
[Node.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L50)
___
@@ -88,7 +88,7 @@ ___
#### Defined in
[Node.ts:44](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L44)
[Node.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L51)
___
@@ -102,7 +102,7 @@ ___
#### Defined in
[Node.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L46)
[Node.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L53)
___
@@ -110,13 +110,18 @@ ___
**id\_**: `string`
The unique ID of the Node/Document. The trailing underscore is here
to avoid collisions with the id keyword in Python.
Set to a UUID by default.
#### Inherited from
[BaseNode](BaseNode.md).[id_](BaseNode.md#id_)
#### Defined in
[Node.ts:38](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L38)
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
___
@@ -130,7 +135,7 @@ ___
#### Defined in
[Node.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L42)
[Node.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L49)
___
@@ -140,7 +145,7 @@ ___
#### Defined in
[Node.ts:142](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L142)
[Node.ts:155](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L155)
___
@@ -154,7 +159,7 @@ ___
#### Defined in
[Node.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L45)
[Node.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L52)
___
@@ -164,7 +169,7 @@ ___
#### Defined in
[Node.ts:138](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L138)
[Node.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L151)
___
@@ -174,7 +179,7 @@ ___
#### Defined in
[Node.ts:137](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L137)
[Node.ts:150](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L150)
## Accessors
@@ -192,7 +197,7 @@ BaseNode.childNodes
#### Defined in
[Node.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L104)
[Node.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L107)
___
@@ -210,25 +215,7 @@ BaseNode.nextNode
#### Defined in
[Node.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L84)
___
### nodeId
`get` **nodeId**(): `string`
#### Returns
`string`
#### Inherited from
BaseNode.nodeId
#### Defined in
[Node.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L58)
[Node.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L87)
___
@@ -246,7 +233,7 @@ BaseNode.parentNode
#### Defined in
[Node.ts:94](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L94)
[Node.ts:97](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L97)
___
@@ -264,7 +251,7 @@ BaseNode.prevNode
#### Defined in
[Node.ts:72](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L72)
[Node.ts:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L75)
___
@@ -282,7 +269,7 @@ BaseNode.sourceNode
#### Defined in
[Node.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L62)
[Node.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L65)
## Methods
@@ -300,21 +287,28 @@ BaseNode.sourceNode
#### Defined in
[Node.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L124)
[Node.ts:129](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L129)
___
### generateHash
**generateHash**(): `void`
**generateHash**(): `string`
Generate a hash of the text node.
The ID is not part of the hash as it can change independent of content.
#### Returns
`void`
`string`
#### Overrides
[BaseNode](BaseNode.md).[generateHash](BaseNode.md#generatehash)
#### Defined in
[Node.ts:149](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L149)
[Node.ts:173](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L173)
___
@@ -338,7 +332,7 @@ ___
#### Defined in
[Node.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L157)
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
___
@@ -356,7 +350,7 @@ ___
#### Defined in
[Node.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L116)
[Node.ts:121](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L121)
___
@@ -380,7 +374,7 @@ ___
#### Defined in
[Node.ts:162](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L162)
[Node.ts:192](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L192)
___
@@ -399,7 +393,7 @@ ___
#### Defined in
[Node.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L187)
[Node.ts:219](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L219)
___
@@ -413,7 +407,7 @@ ___
#### Defined in
[Node.ts:191](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L191)
[Node.ts:223](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L223)
___
@@ -431,7 +425,7 @@ ___
#### Defined in
[Node.ts:153](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L153)
[Node.ts:183](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L183)
___
@@ -455,4 +449,24 @@ ___
#### Defined in
[Node.ts:183](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L183)
[Node.ts:213](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L213)
___
### toJSON
**toJSON**(): `Record`<`string`, `any`\>
Used with built in JSON.stringify
#### Returns
`Record`<`string`, `any`\>
#### Inherited from
[BaseNode](BaseNode.md).[toJSON](BaseNode.md#tojson)
#### Defined in
[Node.ts:141](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L141)
+89 -13
View File
@@ -46,7 +46,7 @@ The VectorStoreIndex, an index that stores the nodes only according to their vec
#### Defined in
[indices/BaseIndex.ts:117](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L117)
[indices/BaseIndex.ts:125](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L125)
___
@@ -60,7 +60,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L119)
[indices/BaseIndex.ts:127](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L127)
___
@@ -74,7 +74,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:120](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L120)
[indices/BaseIndex.ts:128](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L128)
___
@@ -88,7 +88,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:115](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L115)
[indices/BaseIndex.ts:123](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L123)
___
@@ -102,13 +102,13 @@ ___
#### Defined in
[indices/BaseIndex.ts:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L116)
[indices/BaseIndex.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L124)
___
### vectorStore
**vectorStore**: `VectorStore`
**vectorStore**: [`VectorStore`](../interfaces/VectorStore.md)
#### Overrides
@@ -145,7 +145,7 @@ and response synthezier if they are not provided.
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:215](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L215)
[indices/vectorStore/VectorStoreIndex.ts:223](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L223)
___
@@ -171,13 +171,88 @@ Create a new retriever from the index.
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:211](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L211)
[indices/vectorStore/VectorStoreIndex.ts:219](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L219)
___
### deleteRefDoc
**deleteRefDoc**(`refDocId`, `deleteFromDocStore?`): `Promise`<`void`\>
#### Parameters
| Name | Type | Default value |
| :------ | :------ | :------ |
| `refDocId` | `string` | `undefined` |
| `deleteFromDocStore` | `boolean` | `true` |
#### Returns
`Promise`<`void`\>
#### Overrides
[BaseIndex](BaseIndex.md).[deleteRefDoc](BaseIndex.md#deleterefdoc)
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:259](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L259)
___
### insert
**insert**(`document`): `Promise`<`void`\>
Insert a document into the index.
#### Parameters
| Name | Type |
| :------ | :------ |
| `document` | [`Document`](Document.md) |
#### Returns
`Promise`<`void`\>
#### Inherited from
[BaseIndex](BaseIndex.md).[insert](BaseIndex.md#insert)
#### Defined in
[indices/BaseIndex.ts:159](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L159)
___
### insertNodes
**insertNodes**(`nodes`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `nodes` | [`BaseNode`](BaseNode.md)[] |
#### Returns
`Promise`<`void`\>
#### Overrides
[BaseIndex](BaseIndex.md).[insertNodes](BaseIndex.md#insertnodes)
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:234](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L234)
___
### buildIndexFromNodes
`Static` **buildIndexFromNodes**(`nodes`, `serviceContext`, `vectorStore`, `docStore`): `Promise`<[`IndexDict`](IndexDict.md)\>
`Static` **buildIndexFromNodes**(`nodes`, `serviceContext`, `vectorStore`, `docStore`, `indexDict?`): `Promise`<[`IndexDict`](IndexDict.md)\>
Get embeddings for nodes and place them into the index.
@@ -187,8 +262,9 @@ Get embeddings for nodes and place them into the index.
| :------ | :------ |
| `nodes` | [`BaseNode`](BaseNode.md)[] |
| `serviceContext` | [`ServiceContext`](../interfaces/ServiceContext.md) |
| `vectorStore` | `VectorStore` |
| `vectorStore` | [`VectorStore`](../interfaces/VectorStore.md) |
| `docStore` | `BaseDocumentStore` |
| `indexDict?` | [`IndexDict`](IndexDict.md) |
#### Returns
@@ -196,7 +272,7 @@ Get embeddings for nodes and place them into the index.
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L151)
[indices/vectorStore/VectorStoreIndex.ts:147](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L147)
___
@@ -221,7 +297,7 @@ High level API: split documents, get embeddings, and build index.
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:186](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L186)
[indices/vectorStore/VectorStoreIndex.ts:194](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L194)
___
@@ -245,7 +321,7 @@ Get the embeddings for nodes.
#### Defined in
[indices/vectorStore/VectorStoreIndex.ts:123](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L123)
[indices/vectorStore/VectorStoreIndex.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L119)
___
+13 -3
View File
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[llm/LLM.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L187)
[llm/LLM.ts:246](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L246)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[llm/LLM.ts:188](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L188)
[llm/LLM.ts:247](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L247)
___
@@ -34,4 +34,14 @@ ___
#### Defined in
[llm/LLM.ts:189](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L189)
[llm/LLM.ts:248](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L248)
___
### REPLICATE4BIT
• **REPLICATE4BIT** = ``"replicate4bit"``
#### Defined in
[llm/LLM.ts:251](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L251)
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[indices/list/ListIndex.ts:26](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L26)
[indices/list/ListIndex.ts:30](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L30)
___
@@ -24,4 +24,4 @@ ___
#### Defined in
[indices/list/ListIndex.ts:28](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L28)
[indices/list/ListIndex.ts:32](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/list/ListIndex.ts#L32)
+4 -4
View File
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[Node.ts:19](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L19)
[Node.ts:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L20)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[Node.ts:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L20)
[Node.ts:21](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L21)
___
@@ -34,7 +34,7 @@ ___
#### Defined in
[Node.ts:21](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L21)
[Node.ts:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L22)
___
@@ -44,4 +44,4 @@ ___
#### Defined in
[Node.ts:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L22)
[Node.ts:23](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L23)
+5 -5
View File
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[Node.ts:8](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L8)
[Node.ts:9](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L9)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[Node.ts:6](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L6)
[Node.ts:7](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L7)
___
@@ -34,7 +34,7 @@ ___
#### Defined in
[Node.ts:7](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L7)
[Node.ts:8](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L8)
___
@@ -44,7 +44,7 @@ ___
#### Defined in
[Node.ts:5](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L5)
[Node.ts:6](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L6)
___
@@ -54,4 +54,4 @@ ___
#### Defined in
[Node.ts:4](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L4)
[Node.ts:5](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L5)
+4 -4
View File
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[Node.ts:15](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L15)
[Node.ts:16](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L16)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[Node.ts:13](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L13)
[Node.ts:14](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L14)
___
@@ -34,7 +34,7 @@ ___
#### Defined in
[Node.ts:14](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L14)
[Node.ts:15](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L15)
___
@@ -44,4 +44,4 @@ ___
#### Defined in
[Node.ts:12](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L12)
[Node.ts:13](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L13)
+3 -3
View File
@@ -17,7 +17,7 @@ Default is cosine similarity. Dot product and negative Euclidean distance are al
#### Defined in
[Embedding.ts:10](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L10)
[Embedding.ts:17](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L17)
___
@@ -27,7 +27,7 @@ ___
#### Defined in
[Embedding.ts:11](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L11)
[Embedding.ts:18](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L18)
___
@@ -37,4 +37,4 @@ ___
#### Defined in
[Embedding.ts:12](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L12)
[Embedding.ts:19](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L19)
@@ -0,0 +1,77 @@
---
id: "VectorStoreQueryMode"
title: "Enumeration: VectorStoreQueryMode"
sidebar_label: "VectorStoreQueryMode"
sidebar_position: 0
custom_edit_url: null
---
## Enumeration Members
### DEFAULT
**DEFAULT** = ``"default"``
#### Defined in
[storage/vectorStore/types.ts:12](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L12)
___
### HYBRID
• **HYBRID** = ``"hybrid"``
#### Defined in
[storage/vectorStore/types.ts:14](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L14)
___
### LINEAR\_REGRESSION
• **LINEAR\_REGRESSION** = ``"linear_regression"``
#### Defined in
[storage/vectorStore/types.ts:18](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L18)
___
### LOGISTIC\_REGRESSION
• **LOGISTIC\_REGRESSION** = ``"logistic_regression"``
#### Defined in
[storage/vectorStore/types.ts:17](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L17)
___
### MMR
• **MMR** = ``"mmr"``
#### Defined in
[storage/vectorStore/types.ts:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L20)
___
### SPARSE
• **SPARSE** = ``"sparse"``
#### Defined in
[storage/vectorStore/types.ts:13](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L13)
___
### SVM
• **SVM** = ``"svm"``
#### Defined in
[storage/vectorStore/types.ts:16](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L16)
+27 -10
View File
@@ -8,8 +8,12 @@ custom_edit_url: null
# LlamaIndex.TS
LlamaIndex is a data framework for your LLM application.
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in Typescript and Javascript.
Documentation: https://ts.llamaindex.ai/
## What is LlamaIndex.TS?
LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data.
@@ -22,8 +26,11 @@ In a new folder:
```bash
export OPENAI_API_KEY="sk-......" # Replace with your key from https://platform.openai.com/account/api-keys
npx tsc -init # if needed
pnpm init
pnpm install typescript
pnpm exec tsc -init # if needed
pnpm install llamaindex
pnpm install @types/node
```
Create the file example.ts
@@ -62,28 +69,38 @@ main();
Then you can run it using
```bash
npx ts-node example.ts
pnpm dlx ts-node example.ts
```
## Playground
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
## Core concepts for getting started:
- [Document](packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Document](/packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Node](packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Node](/packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Embedding](packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Embedding](/packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Indices](packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [Indices](/packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [QueryEngine](packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [QueryEngine](/packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [ChatEngine](packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [ChatEngine](/packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [SimplePrompt](packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
- [SimplePrompt](/packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
## Supported LLMs:
- OpenAI GPT-3.5-turbo and GPT-4
- Anthropic Claude Instant and Claude 2
- Llama2 Chat LLMs (70B, 13B, and 7B parameters)
## Contributing:
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](CONTRIBUTING.md)
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
## Bugs? Questions?
@@ -26,7 +26,7 @@ custom_edit_url: null
#### Defined in
[indices/BaseIndex.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L104)
[indices/BaseIndex.ts:112](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L112)
___
@@ -36,7 +36,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:106](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L106)
[indices/BaseIndex.ts:114](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L114)
___
@@ -46,7 +46,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L107)
[indices/BaseIndex.ts:115](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L115)
___
@@ -56,7 +56,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:102](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L102)
[indices/BaseIndex.ts:110](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L110)
___
@@ -66,14 +66,14 @@ ___
#### Defined in
[indices/BaseIndex.ts:103](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L103)
[indices/BaseIndex.ts:111](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L111)
___
### vectorStore
`Optional` **vectorStore**: `VectorStore`
`Optional` **vectorStore**: [`VectorStore`](VectorStore.md)
#### Defined in
[indices/BaseIndex.ts:105](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L105)
[indices/BaseIndex.ts:113](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L113)
+2 -2
View File
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[llm/LLM.ts:21](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L21)
[llm/LLM.ts:28](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L28)
___
@@ -24,4 +24,4 @@ ___
#### Defined in
[llm/LLM.ts:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L22)
[llm/LLM.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L29)
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[llm/LLM.ts:28](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L28)
[llm/LLM.ts:35](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L35)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[llm/LLM.ts:26](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L26)
[llm/LLM.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L33)
___
@@ -34,4 +34,4 @@ ___
#### Defined in
[llm/LLM.ts:27](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L27)
[llm/LLM.ts:34](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L34)
@@ -0,0 +1,37 @@
---
id: "ExactMatchFilter"
title: "Interface: ExactMatchFilter"
sidebar_label: "ExactMatchFilter"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### filterType
**filterType**: ``"ExactMatch"``
#### Defined in
[storage/vectorStore/types.ts:24](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L24)
___
### key
• **key**: `string`
#### Defined in
[storage/vectorStore/types.ts:25](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L25)
___
### value
• **value**: `string` \| `number`
#### Defined in
[storage/vectorStore/types.ts:26](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L26)
+2 -2
View File
@@ -35,7 +35,7 @@ Get a chat response from the LLM
#### Defined in
[llm/LLM.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L42)
[llm/LLM.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L49)
___
@@ -58,4 +58,4 @@ Get a prompt completion from the LLM
#### Defined in
[llm/LLM.ts:48](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L48)
[llm/LLM.ts:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L55)
@@ -0,0 +1,17 @@
---
id: "MetadataFilters"
title: "Interface: MetadataFilters"
sidebar_label: "MetadataFilters"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### filters
**filters**: [`ExactMatchFilter`](ExactMatchFilter.md)[]
#### Defined in
[storage/vectorStore/types.ts:30](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L30)
@@ -0,0 +1,37 @@
---
id: "MetadataInfo"
title: "Interface: MetadataInfo"
sidebar_label: "MetadataInfo"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### description
**description**: `string`
#### Defined in
[storage/vectorStore/types.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L42)
___
### name
**name**: `string`
#### Defined in
[storage/vectorStore/types.ts:40](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L40)
___
### type
**type**: `string`
#### Defined in
[storage/vectorStore/types.ts:41](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L41)
@@ -16,7 +16,7 @@ A node with an embedding
#### Defined in
[Node.ts:247](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L247)
[Node.ts:305](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L305)
___
@@ -26,4 +26,4 @@ ___
#### Defined in
[Node.ts:246](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L246)
[Node.ts:304](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L304)
@@ -16,7 +16,7 @@ A node with a similarity score
#### Defined in
[Node.ts:238](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L238)
[Node.ts:296](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L296)
___
@@ -26,4 +26,4 @@ ___
#### Defined in
[Node.ts:239](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L239)
[Node.ts:297](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L297)
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[Node.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L29)
[Node.ts:30](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L30)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[Node.ts:28](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L28)
[Node.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L29)
___
@@ -34,7 +34,7 @@ ___
#### Defined in
[Node.ts:26](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L26)
[Node.ts:27](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L27)
___
@@ -44,4 +44,4 @@ ___
#### Defined in
[Node.ts:27](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L27)
[Node.ts:28](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L28)
@@ -30,7 +30,7 @@ ___
### vectorStore
**vectorStore**: `VectorStore`
**vectorStore**: [`VectorStore`](VectorStore.md)
#### Defined in
@@ -24,7 +24,7 @@ custom_edit_url: null
#### Defined in
[indices/BaseIndex.ts:104](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L104)
[indices/BaseIndex.ts:112](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L112)
___
@@ -38,7 +38,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:106](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L106)
[indices/BaseIndex.ts:114](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L114)
___
@@ -52,7 +52,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:107](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L107)
[indices/BaseIndex.ts:115](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L115)
___
@@ -66,7 +66,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:102](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L102)
[indices/BaseIndex.ts:110](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L110)
___
@@ -80,13 +80,13 @@ ___
#### Defined in
[indices/BaseIndex.ts:103](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L103)
[indices/BaseIndex.ts:111](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L111)
___
### vectorStore
**vectorStore**: `VectorStore`
**vectorStore**: [`VectorStore`](VectorStore.md)
#### Overrides
@@ -94,4 +94,4 @@ ___
#### Defined in
[indices/BaseIndex.ts:157](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L157)
[indices/BaseIndex.ts:183](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L183)
@@ -14,7 +14,7 @@ custom_edit_url: null
#### Defined in
[indices/BaseIndex.ts:151](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L151)
[indices/BaseIndex.ts:177](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L177)
___
@@ -24,7 +24,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:150](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L150)
[indices/BaseIndex.ts:176](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L176)
___
@@ -34,7 +34,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:149](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L149)
[indices/BaseIndex.ts:175](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L175)
___
@@ -44,7 +44,7 @@ ___
#### Defined in
[indices/BaseIndex.ts:152](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L152)
[indices/BaseIndex.ts:178](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L178)
___
@@ -54,4 +54,4 @@ ___
#### Defined in
[indices/BaseIndex.ts:153](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L153)
[indices/BaseIndex.ts:179](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L179)
@@ -0,0 +1,128 @@
---
id: "VectorStore"
title: "Interface: VectorStore"
sidebar_label: "VectorStore"
sidebar_position: 0
custom_edit_url: null
---
## Implemented by
- [`SimpleVectorStore`](../classes/SimpleVectorStore.md)
## Properties
### isEmbeddingQuery
`Optional` **isEmbeddingQuery**: `boolean`
#### Defined in
[storage/vectorStore/types.ts:63](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L63)
___
### storesText
**storesText**: `boolean`
#### Defined in
[storage/vectorStore/types.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L62)
## Methods
### add
**add**(`embeddingResults`): `Promise`<`string`[]\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `embeddingResults` | [`NodeWithEmbedding`](NodeWithEmbedding.md)[] |
#### Returns
`Promise`<`string`[]\>
#### Defined in
[storage/vectorStore/types.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L65)
___
### client
**client**(): `any`
#### Returns
`any`
#### Defined in
[storage/vectorStore/types.ts:64](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L64)
___
### delete
**delete**(`refDocId`, `deleteKwargs?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `refDocId` | `string` |
| `deleteKwargs?` | `any` |
#### Returns
`Promise`<`void`\>
#### Defined in
[storage/vectorStore/types.ts:66](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L66)
___
### persist
**persist**(`persistPath`, `fs?`): `Promise`<`void`\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `persistPath` | `string` |
| `fs?` | [`GenericFileSystem`](GenericFileSystem.md) |
#### Returns
`Promise`<`void`\>
#### Defined in
[storage/vectorStore/types.ts:68](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L68)
___
### query
**query**(`query`, `kwargs?`): `Promise`<[`VectorStoreQueryResult`](VectorStoreQueryResult.md)\>
#### Parameters
| Name | Type |
| :------ | :------ |
| `query` | [`VectorStoreQuery`](VectorStoreQuery.md) |
| `kwargs?` | `any` |
#### Returns
`Promise`<[`VectorStoreQueryResult`](VectorStoreQueryResult.md)\>
#### Defined in
[storage/vectorStore/types.ts:67](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L67)
@@ -0,0 +1,27 @@
---
id: "VectorStoreInfo"
title: "Interface: VectorStoreInfo"
sidebar_label: "VectorStoreInfo"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### contentInfo
**contentInfo**: `string`
#### Defined in
[storage/vectorStore/types.ts:47](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L47)
___
### metadataInfo
**metadataInfo**: [`MetadataInfo`](MetadataInfo.md)[]
#### Defined in
[storage/vectorStore/types.ts:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L46)
@@ -0,0 +1,87 @@
---
id: "VectorStoreQuery"
title: "Interface: VectorStoreQuery"
sidebar_label: "VectorStoreQuery"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### alpha
`Optional` **alpha**: `number`
#### Defined in
[storage/vectorStore/types.ts:56](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L56)
___
### docIds
`Optional` **docIds**: `string`[]
#### Defined in
[storage/vectorStore/types.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L53)
___
### filters
`Optional` **filters**: [`MetadataFilters`](MetadataFilters.md)
#### Defined in
[storage/vectorStore/types.ts:57](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L57)
___
### mmrThreshold
`Optional` **mmrThreshold**: `number`
#### Defined in
[storage/vectorStore/types.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L58)
___
### mode
**mode**: [`VectorStoreQueryMode`](../enums/VectorStoreQueryMode.md)
#### Defined in
[storage/vectorStore/types.ts:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L55)
___
### queryEmbedding
`Optional` **queryEmbedding**: `number`[]
#### Defined in
[storage/vectorStore/types.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L51)
___
### queryStr
`Optional` **queryStr**: `string`
#### Defined in
[storage/vectorStore/types.ts:54](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L54)
___
### similarityTopK
**similarityTopK**: `number`
#### Defined in
[storage/vectorStore/types.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L52)
@@ -0,0 +1,37 @@
---
id: "VectorStoreQueryResult"
title: "Interface: VectorStoreQueryResult"
sidebar_label: "VectorStoreQueryResult"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### ids
**ids**: `string`[]
#### Defined in
[storage/vectorStore/types.ts:8](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L8)
___
### nodes
`Optional` **nodes**: [`BaseNode`](../classes/BaseNode.md)[]
#### Defined in
[storage/vectorStore/types.ts:6](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L6)
___
### similarities
**similarities**: `number`[]
#### Defined in
[storage/vectorStore/types.ts:7](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L7)
@@ -0,0 +1,37 @@
---
id: "VectorStoreQuerySpec"
title: "Interface: VectorStoreQuerySpec"
sidebar_label: "VectorStoreQuerySpec"
sidebar_position: 0
custom_edit_url: null
---
## Properties
### filters
**filters**: [`ExactMatchFilter`](ExactMatchFilter.md)[]
#### Defined in
[storage/vectorStore/types.ts:35](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L35)
___
### query
**query**: `string`
#### Defined in
[storage/vectorStore/types.ts:34](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L34)
___
### topK
`Optional` **topK**: `number`
#### Defined in
[storage/vectorStore/types.ts:36](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L36)
+58 -17
View File
@@ -15,6 +15,7 @@ custom_edit_url: null
- [NodeRelationship](enums/NodeRelationship.md)
- [ObjectType](enums/ObjectType.md)
- [SimilarityType](enums/SimilarityType.md)
- [VectorStoreQueryMode](enums/VectorStoreQueryMode.md)
## Classes
@@ -47,8 +48,11 @@ custom_edit_url: null
- [SentenceSplitter](classes/SentenceSplitter.md)
- [SimpleChatEngine](classes/SimpleChatEngine.md)
- [SimpleDirectoryReader](classes/SimpleDirectoryReader.md)
- [SimpleDocumentStore](classes/SimpleDocumentStore.md)
- [SimpleIndexStore](classes/SimpleIndexStore.md)
- [SimpleNodeParser](classes/SimpleNodeParser.md)
- [SimpleResponseBuilder](classes/SimpleResponseBuilder.md)
- [SimpleVectorStore](classes/SimpleVectorStore.md)
- [SubQuestionOutputParser](classes/SubQuestionOutputParser.md)
- [SubQuestionQueryEngine](classes/SubQuestionQueryEngine.md)
- [TextFileReader](classes/TextFileReader.md)
@@ -70,8 +74,11 @@ custom_edit_url: null
- [ChatMessage](interfaces/ChatMessage.md)
- [ChatResponse](interfaces/ChatResponse.md)
- [Event](interfaces/Event.md)
- [ExactMatchFilter](interfaces/ExactMatchFilter.md)
- [GenericFileSystem](interfaces/GenericFileSystem.md)
- [LLM](interfaces/LLM.md)
- [MetadataFilters](interfaces/MetadataFilters.md)
- [MetadataInfo](interfaces/MetadataInfo.md)
- [NodeParser](interfaces/NodeParser.md)
- [NodeWithEmbedding](interfaces/NodeWithEmbedding.md)
- [NodeWithScore](interfaces/NodeWithScore.md)
@@ -88,6 +95,11 @@ custom_edit_url: null
- [ToolMetadata](interfaces/ToolMetadata.md)
- [VectorIndexConstructorProps](interfaces/VectorIndexConstructorProps.md)
- [VectorIndexOptions](interfaces/VectorIndexOptions.md)
- [VectorStore](interfaces/VectorStore.md)
- [VectorStoreInfo](interfaces/VectorStoreInfo.md)
- [VectorStoreQuery](interfaces/VectorStoreQuery.md)
- [VectorStoreQueryResult](interfaces/VectorStoreQueryResult.md)
- [VectorStoreQuerySpec](interfaces/VectorStoreQuerySpec.md)
- [WalkableFileSystem](interfaces/WalkableFileSystem.md)
## Type Aliases
@@ -108,7 +120,7 @@ ___
#### Defined in
[llm/LLM.ts:32](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L32)
[llm/LLM.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L39)
___
@@ -138,7 +150,7 @@ ___
#### Defined in
[llm/LLM.ts:13](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L13)
[llm/LLM.ts:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L20)
___
@@ -148,7 +160,7 @@ ___
#### Defined in
[Node.ts:32](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L32)
[Node.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L33)
___
@@ -210,16 +222,25 @@ NOTE 2: we default to empty string to make it easy to calculate prompt sizes
| `Llama-2-13b-chat` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5" } |
| `Llama-2-13b-chat.contextWindow` | `number` |
| `Llama-2-13b-chat.replicateApi` | `string` |
| `Llama-2-70b-chat` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "replicate/llama70b-v2-chat:e951f18578850b652510200860fc4ea62b3b16fac280f83ff32282f87bbd2e48" } |
| `Llama-2-70b-chat.contextWindow` | `number` |
| `Llama-2-70b-chat.replicateApi` | `string` |
| `Llama-2-13b-chat-4bit` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "a16z-infra/llama13b-v2-chat:2a7f981751ec7fdf87b5b91ad4db53683a98082e9ff7bfd12c8cd5ea85980a52" } |
| `Llama-2-13b-chat-4bit.contextWindow` | `number` |
| `Llama-2-13b-chat-4bit.replicateApi` | `string` |
| `Llama-2-70b-chat-4bit` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "replicate/llama70b-v2-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1" } |
| `Llama-2-70b-chat-4bit.contextWindow` | `number` |
| `Llama-2-70b-chat-4bit.replicateApi` | `string` |
| `Llama-2-70b-chat-old` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "replicate/llama70b-v2-chat:e951f18578850b652510200860fc4ea62b3b16fac280f83ff32282f87bbd2e48" } |
| `Llama-2-70b-chat-old.contextWindow` | `number` |
| `Llama-2-70b-chat-old.replicateApi` | `string` |
| `Llama-2-7b-chat` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "a16z-infra/llama7b-v2-chat:4f0a4744c7295c024a1de15e1a63c880d3da035fa1f49bfd344fe076074c8eea" } |
| `Llama-2-7b-chat.contextWindow` | `number` |
| `Llama-2-7b-chat.replicateApi` | `string` |
| `Llama-2-7b-chat-4bit` | { `contextWindow`: `number` = 4096; `replicateApi`: `string` = "a16z-infra/llama7b-v2-chat:4f0b260b6a13eb53a6b1891f089d57c08f41003ae79458be5011303d81a394dc" } |
| `Llama-2-7b-chat-4bit.contextWindow` | `number` |
| `Llama-2-7b-chat-4bit.replicateApi` | `string` |
#### Defined in
[llm/LLM.ts:168](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L168)
[llm/LLM.ts:205](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L205)
___
@@ -244,7 +265,7 @@ We currently support GPT-3.5 and GPT-4 models
#### Defined in
[llm/LLM.ts:64](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L64)
[llm/LLM.ts:71](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L71)
___
@@ -300,7 +321,7 @@ ___
### DEFAULT\_DOC\_STORE\_PERSIST\_FILENAME
• `Const` **DEFAULT\_DOC\_STORE\_PERSIST\_FILENAME**: ``"docstore.json"``
• `Const` **DEFAULT\_DOC\_STORE\_PERSIST\_FILENAME**: ``"doc_store.json"``
#### Defined in
@@ -423,7 +444,7 @@ ___
#### Defined in
[llm/LLM.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L51)
[llm/LLM.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L58)
___
@@ -442,7 +463,7 @@ ___
#### Defined in
[llm/LLM.ts:56](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L56)
[llm/LLM.ts:63](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L63)
___
@@ -779,7 +800,7 @@ Get the top K embeddings from a list of embeddings ordered by similarity to the
#### Defined in
[Embedding.ts:77](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L77)
[Embedding.ts:84](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L84)
___
@@ -795,7 +816,7 @@ ___
| `embeddings` | `number`[][] | `undefined` |
| `similarityTopK?` | `number` | `undefined` |
| `embeddingsIds?` | `any`[] | `undefined` |
| `queryMode` | `VectorStoreQueryMode` | `VectorStoreQueryMode.SVM` |
| `queryMode` | [`VectorStoreQueryMode`](enums/VectorStoreQueryMode.md) | `VectorStoreQueryMode.SVM` |
#### Returns
@@ -803,7 +824,7 @@ ___
#### Defined in
[Embedding.ts:119](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L119)
[Embedding.ts:126](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L126)
___
@@ -829,7 +850,7 @@ ___
#### Defined in
[Embedding.ts:131](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L131)
[Embedding.ts:138](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L138)
___
@@ -849,7 +870,27 @@ ___
#### Defined in
[indices/BaseIndex.ts:70](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L70)
[indices/BaseIndex.ts:73](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/BaseIndex.ts#L73)
___
### jsonToNode
▸ **jsonToNode**(`json`): [`TextNode`](classes/TextNode.md)
#### Parameters
| Name | Type |
| :------ | :------ |
| `json` | `any` |
#### Returns
[`TextNode`](classes/TextNode.md)
#### Defined in
[Node.ts:271](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L271)
___
@@ -944,7 +985,7 @@ similartiy score with higher numbers meaning the two embeddings are more similar
#### Defined in
[Embedding.ts:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L22)
[Embedding.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Embedding.ts#L29)
___
-12839
View File
File diff suppressed because it is too large Load Diff
+27
View File
@@ -1,5 +1,32 @@
# simple
## 0.0.15
### Patch Changes
- Updated dependencies [f80b062]
- Updated dependencies [b3fec86]
- Updated dependencies [b3fec86]
- llamaindex@0.0.17
## 0.0.14
### Patch Changes
- Updated dependencies [ec12633]
- Updated dependencies [9214b06]
- Updated dependencies [3316c6b]
- Updated dependencies [3316c6b]
- llamaindex@0.0.16
## 0.0.13
### Patch Changes
- Updated dependencies [b501eb5]
- Updated dependencies [f9d1a6e]
- llamaindex@0.0.15
## 0.0.12
### Patch Changes
+10 -9
View File
@@ -1,22 +1,23 @@
// @ts-ignore
import * as readline from "node:readline/promises";
// @ts-ignore
import { stdin as input, stdout as output } from "node:process";
// readline/promises is still experimental so not in @types/node yet
// @ts-ignore
import readline from "node:readline/promises";
import {
Document,
VectorStoreIndex,
ContextChatEngine,
Document,
serviceContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
async function main() {
const document = new Document({ text: essay });
const serviceContext = serviceContextFromDefaults({ chunkSize: 512 });
const index = await VectorStoreIndex.fromDocuments(
[document],
{ serviceContext }
);
const index = await VectorStoreIndex.fromDocuments([document], {
serviceContext,
});
const retriever = index.asRetriever();
retriever.similarityTopK = 5;
const chatEngine = new ContextChatEngine({ retriever });
+40
View File
@@ -0,0 +1,40 @@
import { stdin as input, stdout as output } from "node:process";
// readline/promises is still experimental so not in @types/node yet
// @ts-ignore
import readline from "node:readline/promises";
import { ChatMessage, LlamaDeuce, OpenAI } from "llamaindex";
(async () => {
const gpt4 = new OpenAI({ model: "gpt-4", temperature: 0.9 });
const l2 = new LlamaDeuce({
model: "Llama-2-70b-chat-4bit",
temperature: 0.9,
});
const rl = readline.createInterface({ input, output });
const start = await rl.question("Start: ");
const history: ChatMessage[] = [
{
content:
"Prefer shorter answers. Keep your response to 100 words or less.",
role: "system",
},
{ content: start, role: "user" },
];
while (true) {
const next = history.length % 2 === 1 ? gpt4 : l2;
const r = await next.chat(
history.map(({ content, role }) => ({
content,
role: next === l2 ? role : role === "user" ? "assistant" : "user",
})),
);
history.push({
content: r.message.content,
role: next === l2 ? "assistant" : "user",
});
await rl.question((next === l2 ? "Llama: " : "GPT: ") + r.message.content);
}
})();
+3 -6
View File
@@ -13,16 +13,13 @@ async function main() {
chunkSize: 40,
}),
});
const document = new Document({ text: essay });
const index = await ListIndex.fromDocuments(
[document],
{ serviceContext }
);
const document = new Document({ text: essay, id_: "essay" });
const index = await ListIndex.fromDocuments([document], { serviceContext });
const queryEngine = index.asQueryEngine({
retriever: index.asRetriever({ mode: ListRetrieverMode.LLM }),
});
const response = await queryEngine.query(
"What did the author do growing up?"
"What did the author do growing up?",
);
console.log(response.toString());
}
+1 -1
View File
@@ -1,5 +1,5 @@
{
"version": "0.0.12",
"version": "0.0.15",
"private": true,
"name": "simple",
"dependencies": {
-1
View File
@@ -1,4 +1,3 @@
import fs from "fs/promises";
import { PDFReader, VectorStoreIndex } from "llamaindex";
async function main() {
-36
View File
@@ -1,36 +0,0 @@
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 with persistence
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());
}
main().catch(console.error);
+4 -5
View File
@@ -1,11 +1,10 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import { SentenceSplitter } from "llamaindex";
async function main() {
const essay = await fs.readFile(
"node_modules/llamaindex/examples/abramov.txt",
"utf-8"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
const textSplitter = new SentenceSplitter();
+22 -10
View File
@@ -1,30 +1,42 @@
import { Document, VectorStoreIndex, storageContextFromDefaults } from "llamaindex";
import {
Document,
storageContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
async function main() {
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: "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 });
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?"
"What did the author do in college?",
);
// Output response
console.log(response.toString());
// load the index
const loadedIndex = await VectorStoreIndex.init({ storageContext });
const laodedQueryEngine = loadedIndex.asQueryEngine();
const loadedResponse = await laodedQueryEngine.query(
"What did the author do growing up?"
const secondStorageContext = await storageContextFromDefaults({
persistDir: "./storage",
});
const loadedIndex = await VectorStoreIndex.init({
storageContext: secondStorageContext,
});
const loadedQueryEngine = loadedIndex.asQueryEngine();
const loadedResponse = await loadedQueryEngine.query(
"What did the author do growing up?",
);
console.log(loadedResponse.toString());
}
+3 -3
View File
@@ -1,9 +1,9 @@
import { Document, VectorStoreIndex, SubQuestionQueryEngine } from "llamaindex";
import { Document, SubQuestionQueryEngine, VectorStoreIndex } from "llamaindex";
import essay from "./essay";
(async () => {
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: essay });
const index = await VectorStoreIndex.fromDocuments([document]);
const queryEngine = SubQuestionQueryEngine.fromDefaults({
@@ -19,7 +19,7 @@ import essay from "./essay";
});
const response = await queryEngine.query(
"How was Paul Grahams life different before and after YC?"
"How was Paul Grahams life different before and after YC?",
);
console.log(response.toString());
+7 -7
View File
@@ -1,15 +1,15 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import { Document, VectorStoreIndex } 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments([document]);
@@ -17,7 +17,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+8 -8
View File
@@ -1,20 +1,20 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import {
Anthropic,
Document,
VectorStoreIndex,
serviceContextFromDefaults,
VectorStoreIndex,
} 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const serviceContext = serviceContextFromDefaults({ llm: new Anthropic() });
@@ -25,7 +25,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+17 -9
View File
@@ -1,23 +1,31 @@
import { Document, VectorStoreIndex, RetrieverQueryEngine, OpenAI, serviceContextFromDefaults } from "llamaindex";
import {
Document,
OpenAI,
RetrieverQueryEngine,
serviceContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
// Customize retrieval and query args
async function main() {
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: "essay" });
const serviceContext = serviceContextFromDefaults(
{ llm: new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.0 }) }
);
const serviceContext = serviceContextFromDefaults({
llm: new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.0 }),
});
const index = await VectorStoreIndex.fromDocuments([document], {
serviceContext,
});
const index = await VectorStoreIndex.fromDocuments([document], { serviceContext });
const retriever = index.asRetriever();
retriever.similarityTopK = 5;
// TODO: cannot pass responseSynthesizer into retriever query engine
const queryEngine = new RetrieverQueryEngine(retriever);
const response = await queryEngine.query(
"What did the author do growing up?"
"What did the author do growing up?",
);
console.log(response.response);
}
+8 -9
View File
@@ -1,20 +1,19 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import {
OpenAI,
Document,
VectorStoreIndex,
OpenAI,
serviceContextFromDefaults,
VectorStoreIndex,
} 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const serviceContext = serviceContextFromDefaults({
@@ -27,7 +26,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+10 -9
View File
@@ -1,22 +1,23 @@
// @ts-ignore
import * as readline from "node:readline/promises";
// @ts-ignore
import { stdin as input, stdout as output } from "node:process";
// readline/promises is still experimental so not in @types/node yet
// @ts-ignore
import readline from "node:readline/promises";
import {
Document,
VectorStoreIndex,
ContextChatEngine,
Document,
serviceContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
async function main() {
const document = new Document({ text: essay });
const serviceContext = serviceContextFromDefaults({ chunkSize: 512 });
const index = await VectorStoreIndex.fromDocuments(
[document],
{ serviceContext }
);
const index = await VectorStoreIndex.fromDocuments([document], {
serviceContext,
});
const retriever = index.asRetriever();
retriever.similarityTopK = 5;
const chatEngine = new ContextChatEngine({ retriever });
+40
View File
@@ -0,0 +1,40 @@
import { stdin as input, stdout as output } from "node:process";
// readline/promises is still experimental so not in @types/node yet
// @ts-ignore
import readline from "node:readline/promises";
import { ChatMessage, LlamaDeuce, OpenAI } from "llamaindex";
(async () => {
const gpt4 = new OpenAI({ model: "gpt-4", temperature: 0.9 });
const l2 = new LlamaDeuce({
model: "Llama-2-70b-chat-4bit",
temperature: 0.9,
});
const rl = readline.createInterface({ input, output });
const start = await rl.question("Start: ");
const history: ChatMessage[] = [
{
content:
"Prefer shorter answers. Keep your response to 100 words or less.",
role: "system",
},
{ content: start, role: "user" },
];
while (true) {
const next = history.length % 2 === 1 ? gpt4 : l2;
const r = await next.chat(
history.map(({ content, role }) => ({
content,
role: next === l2 ? role : role === "user" ? "assistant" : "user",
})),
);
history.push({
content: r.message.content,
role: next === l2 ? "assistant" : "user",
});
await rl.question((next === l2 ? "Llama: " : "GPT: ") + r.message.content);
}
})();
+3 -6
View File
@@ -13,16 +13,13 @@ async function main() {
chunkSize: 40,
}),
});
const document = new Document({ text: essay });
const index = await ListIndex.fromDocuments(
[document],
{ serviceContext }
);
const document = new Document({ text: essay, id_: "essay" });
const index = await ListIndex.fromDocuments([document], { serviceContext });
const queryEngine = index.asQueryEngine({
retriever: index.asRetriever({ mode: ListRetrieverMode.LLM }),
});
const response = await queryEngine.query(
"What did the author do growing up?"
"What did the author do growing up?",
);
console.log(response.toString());
}
+2 -2
View File
@@ -1,7 +1,7 @@
import { LlamaDeuce } from "llamaindex";
import { DeuceChatStrategy, LlamaDeuce } from "llamaindex";
(async () => {
const deuce = new LlamaDeuce();
const deuce = new LlamaDeuce({ chatStrategy: DeuceChatStrategy.META });
const result = await deuce.chat([{ content: "Hello, world!", role: "user" }]);
console.log(result);
})();
+22 -81
View File
@@ -8,16 +8,16 @@
"name": "simple",
"version": "0.0.3",
"dependencies": {
"llamaindex": "^0.0.0-20230730023617"
"llamaindex": "latest"
},
"devDependencies": {
"@types/node": "^18"
}
},
"node_modules/@anthropic-ai/sdk": {
"version": "0.5.8",
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.5.8.tgz",
"integrity": "sha512-iHenjcE2Q/az6VZiP1DueOSvKNRmxsly6Rx2yjJBoy7OBYVFGVjEdgs2mPQHtTX0ibKAR7tPq6F6MQbKDPWcKg==",
"version": "0.5.10",
"resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.5.10.tgz",
"integrity": "sha512-P8xrIuTUO/6wDzcjQRUROXp4WSqtngbXaE4GpEu0PhEmnq/1Q8vbF1s0o7W07EV3j8zzRoyJxAKovUJtNXH7ew==",
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
@@ -30,9 +30,9 @@
}
},
"node_modules/@types/node": {
"version": "18.17.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.0.tgz",
"integrity": "sha512-GXZxEtOxYGFchyUzxvKI14iff9KZ2DI+A6a37o6EQevtg6uO9t+aUZKcaC1Te5Ng1OnLM7K9NVVj+FbecD9cJg=="
"version": "18.17.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.17.3.tgz",
"integrity": "sha512-2x8HWtFk0S99zqVQABU9wTpr8wPoaDHZUcAkoTKH+nL7kPv3WUI9cRi/Kk5Mz4xdqXSqTkKP7IWNoQQYCnDsTA=="
},
"node_modules/@types/node-fetch": {
"version": "2.6.4",
@@ -55,39 +55,16 @@
}
},
"node_modules/agentkeepalive": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.3.0.tgz",
"integrity": "sha512-7Epl1Blf4Sy37j4v9f9FjICCh4+KAQOyXgHEwlyBiAQLbhKdq/i2QQU3amQalS/wPhdPzDXPL5DMR5bkn+YeWg==",
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.5.0.tgz",
"integrity": "sha512-5GG/5IbQQpC9FpkRGsSvZI5QYeSCzlJHdpBQntCsuTOxhKD8lqKhrleg2Yi7yvMIf82Ycmmqln9U8V9qwEiJew==",
"dependencies": {
"debug": "^4.1.0",
"depd": "^2.0.0",
"humanize-ms": "^1.2.1"
},
"engines": {
"node": ">= 8.0.0"
}
},
"node_modules/agentkeepalive/node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
"dependencies": {
"ms": "2.1.2"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/agentkeepalive/node_modules/ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@@ -98,25 +75,6 @@
"resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
"integrity": "sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA=="
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/charenc": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
@@ -160,14 +118,6 @@
"node": ">=0.4.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/digest-fetch": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/digest-fetch/-/digest-fetch-1.3.0.tgz",
@@ -228,25 +178,16 @@
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
},
"node_modules/js-tiktoken": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.7.tgz",
"integrity": "sha512-biba8u/clw7iesNEWLOLwrNGoBP2lA+hTaBLs/D45pJdUPFXyxD6nhcDVtADChghv4GgyAiMKYMiRx7x6h7Biw==",
"dependencies": {
"base64-js": "^1.5.1"
}
},
"node_modules/llamaindex": {
"version": "0.0.0-20230730023617",
"resolved": "https://registry.npmjs.org/llamaindex/-/llamaindex-0.0.0-20230730023617.tgz",
"integrity": "sha512-scBB8s0iboM6LS9zsStxom3UaWd4gBYoC2pbPnX7gZRzgRI3ErFn1cke2tJWG3pqKGg8RYSUus4jltemGHMs/A==",
"version": "0.0.17",
"resolved": "https://registry.npmjs.org/llamaindex/-/llamaindex-0.0.17.tgz",
"integrity": "sha512-2XrKEBUaEfATYmMcW4AkX0B4EiVpp6Gcg3aeWZ+gJZVYc5iMsApReH1gy5T/+XstJWz6lNYOP/DJnVRfkVj0Lg==",
"dependencies": {
"@anthropic-ai/sdk": "^0.5.8",
"js-tiktoken": "^1.0.7",
"@anthropic-ai/sdk": "^0.5.9",
"lodash": "^4.17.21",
"openai": "4.0.0-beta.6",
"openai": "4.0.0-beta.8",
"pdf-parse": "^1.1.1",
"replicate": "^0.12.3",
"replicate": "^0.14.1",
"tiktoken-node": "^0.0.6",
"uuid": "^9.0.0",
"wink-nlp": "^1.14.3"
@@ -337,9 +278,9 @@
}
},
"node_modules/openai": {
"version": "4.0.0-beta.6",
"resolved": "https://registry.npmjs.org/openai/-/openai-4.0.0-beta.6.tgz",
"integrity": "sha512-sZscRgs6nhBgIt0qcK8XB2PGga6V0Qy9rQn/vKesox/laQDs9tMaOi6rsDhHq15aXQJPROfEB0K9SZoCuyWbSw==",
"version": "4.0.0-beta.8",
"resolved": "https://registry.npmjs.org/openai/-/openai-4.0.0-beta.8.tgz",
"integrity": "sha512-bXBxUK2B288GlLckjnpT+UgyyddP+f4JIT5/df95C6eeqQhf5UkuN41Z3uf/6unPvR8Tthm4jJje1fA0OgsDEw==",
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
@@ -364,9 +305,9 @@
}
},
"node_modules/replicate": {
"version": "0.12.3",
"resolved": "https://registry.npmjs.org/replicate/-/replicate-0.12.3.tgz",
"integrity": "sha512-HVWKPoVhWVTONlWk+lUXmq9Vy2J8MxBJMtDBQq3dA5uq71ZzKTh0xvJfvzW4+VLBjhBeL7tkdua6hZJmKfzAPQ==",
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/replicate/-/replicate-0.14.1.tgz",
"integrity": "sha512-3NpuNRbvXoEjY+n/ra24VfQyIRCdLub9GCrU51fFTrMaa6OjRvMC9jGDJSpGRXOLvID75mFgN577HEhA3XEFtg==",
"engines": {
"git": ">=2.11.0",
"node": ">=16.6.0",
-1
View File
@@ -1,4 +1,3 @@
import fs from "fs/promises";
import { PDFReader, VectorStoreIndex } from "llamaindex";
async function main() {
+16
View File
@@ -0,0 +1,16 @@
import fs from "node:fs/promises";
import { SentenceSplitter } from "llamaindex";
async function main() {
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
const textSplitter = new SentenceSplitter();
const chunks = textSplitter.splitTextWithOverlaps(essay);
console.log(chunks);
}
main();
+22 -10
View File
@@ -1,30 +1,42 @@
import { Document, VectorStoreIndex, storageContextFromDefaults } from "llamaindex";
import {
Document,
storageContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
async function main() {
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: "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 });
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?"
"What did the author do in college?",
);
// Output response
console.log(response.toString());
// load the index
const loadedIndex = await VectorStoreIndex.init({ storageContext });
const laodedQueryEngine = loadedIndex.asQueryEngine();
const loadedResponse = await laodedQueryEngine.query(
"What did the author do growing up?"
const secondStorageContext = await storageContextFromDefaults({
persistDir: "./storage",
});
const loadedIndex = await VectorStoreIndex.init({
storageContext: secondStorageContext,
});
const loadedQueryEngine = loadedIndex.asQueryEngine();
const loadedResponse = await loadedQueryEngine.query(
"What did the author do growing up?",
);
console.log(loadedResponse.toString());
}
+3 -3
View File
@@ -1,9 +1,9 @@
import { Document, VectorStoreIndex, SubQuestionQueryEngine } from "llamaindex";
import { Document, SubQuestionQueryEngine, VectorStoreIndex } from "llamaindex";
import essay from "./essay";
(async () => {
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: essay });
const index = await VectorStoreIndex.fromDocuments([document]);
const queryEngine = SubQuestionQueryEngine.fromDefaults({
@@ -19,7 +19,7 @@ import essay from "./essay";
});
const response = await queryEngine.query(
"How was Paul Grahams life different before and after YC?"
"How was Paul Grahams life different before and after YC?",
);
console.log(response.toString());
+7 -7
View File
@@ -1,15 +1,15 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import { Document, VectorStoreIndex } 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const index = await VectorStoreIndex.fromDocuments([document]);
@@ -17,7 +17,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+8 -8
View File
@@ -1,20 +1,20 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import {
Anthropic,
Document,
VectorStoreIndex,
serviceContextFromDefaults,
VectorStoreIndex,
} 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const serviceContext = serviceContextFromDefaults({ llm: new Anthropic() });
@@ -25,7 +25,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+17 -9
View File
@@ -1,23 +1,31 @@
import { Document, VectorStoreIndex, RetrieverQueryEngine, OpenAI, serviceContextFromDefaults } from "llamaindex";
import {
Document,
OpenAI,
RetrieverQueryEngine,
serviceContextFromDefaults,
VectorStoreIndex,
} from "llamaindex";
import essay from "./essay";
// Customize retrieval and query args
async function main() {
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: "essay" });
const serviceContext = serviceContextFromDefaults(
{ llm: new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.0 }) }
);
const serviceContext = serviceContextFromDefaults({
llm: new OpenAI({ model: "gpt-3.5-turbo", temperature: 0.0 }),
});
const index = await VectorStoreIndex.fromDocuments([document], {
serviceContext,
});
const index = await VectorStoreIndex.fromDocuments([document], { serviceContext });
const retriever = index.asRetriever();
retriever.similarityTopK = 5;
// TODO: cannot pass responseSynthesizer into retriever query engine
const queryEngine = new RetrieverQueryEngine(retriever);
const response = await queryEngine.query(
"What did the author do growing up?"
"What did the author do growing up?",
);
console.log(response.response);
}
+8 -9
View File
@@ -1,20 +1,19 @@
import fs from "fs/promises";
import fs from "node:fs/promises";
import {
OpenAI,
Document,
VectorStoreIndex,
OpenAI,
serviceContextFromDefaults,
VectorStoreIndex,
} 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"
);
const path = "node_modules/llamaindex/examples/abramov.txt";
const essay = await fs.readFile(path, "utf-8");
// Create Document object with essay
const document = new Document({ text: essay });
const document = new Document({ text: essay, id_: path });
// Split text and create embeddings. Store them in a VectorStoreIndex
const serviceContext = serviceContextFromDefaults({
@@ -27,7 +26,7 @@ async function main() {
// Query the index
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query(
"What did the author do in college?"
"What did the author do in college?",
);
// Output response
+8 -3
View File
@@ -16,14 +16,19 @@
"eslint": "^7.32.0",
"eslint-config-custom": "workspace:*",
"husky": "^8.0.3",
"jest": "^29.6.1",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.3.0",
"jest": "^29.6.2",
"prettier": "^3.0.1",
"prettier-plugin-organize-imports": "^3.2.3",
"ts-jest": "^29.1.1",
"turbo": "^1.10.12"
},
"packageManager": "pnpm@7.15.0",
"dependencies": {
"@changesets/cli": "^2.26.2"
},
"pnpm": {
"overrides": {
"trim": "1.0.1"
}
}
}
+25
View File
@@ -1,5 +1,30 @@
# llamaindex
## 0.0.17
### Patch Changes
- f80b062: Breaking: changed default temp to 0.1 matching new Python change by @logan-markewich
- b3fec86: Add support for new Replicate 4 bit Llama2 models
- b3fec86: Bug fixes for Llama2 Replicate
## 0.0.16
### Patch Changes
- ec12633: Breaking: make vector store abstraction async (thank you @tyre for the PR)
- 9214b06: Fix persistence bug (thanks @HenryHengZJ)
- 3e52972: Fix Node initializer bug (thank you @tyre for the PR)
- 3316c6b: Add Azure OpenAI support
- 3316c6b: OpenAI Node v4-beta.8
## 0.0.15
### Patch Changes
- b501eb5: Added Anthropic Claude support
- f9d1a6e: Add Top P
## 0.0.14
### Patch Changes
+4 -2
View File
@@ -12,7 +12,7 @@ apps/simple is where the demo code lives
### Turborepo docs
You can checkout how Turborepo works using the built in [README-turborepo.md](README-turborepo.md)
You can checkout how Turborepo works using the default [README-turborepo.md](/README-turborepo.md)
## Getting Started
@@ -41,12 +41,14 @@ To run them, run
pnpm run test
```
To write new test cases write them in packages/core/src/tests
To write new test cases write them in [packages/core/src/tests](/packages/core/src/tests)
We use Jest https://jestjs.io/ to write our test cases. Jest comes with a bunch of built in assertions using the expect function: https://jestjs.io/docs/expect
### Demo applications
There is an existing ["simple"](/apps/simple/README.md) demos folder with mainly NodeJS scripts. Feel free to add additional demos to that folder. If you would like to try out your changes in the core package with a new demo, you need to run the build command in the README.
You can create new demo applications in the apps folder. Just run pnpm init in the folder after you create it to create its own package.json
### Installing packages
+27 -10
View File
@@ -1,7 +1,11 @@
# LlamaIndex.TS
LlamaIndex is a data framework for your LLM application.
Use your own data with large language models (LLMs, OpenAI ChatGPT and others) in Typescript and Javascript.
Documentation: https://ts.llamaindex.ai/
## What is LlamaIndex.TS?
LlamaIndex.TS aims to be a lightweight, easy to use set of libraries to help you integrate large language models into your applications with your own data.
@@ -14,8 +18,11 @@ In a new folder:
```bash
export OPENAI_API_KEY="sk-......" # Replace with your key from https://platform.openai.com/account/api-keys
npx tsc -init # if needed
pnpm init
pnpm install typescript
pnpm exec tsc -init # if needed
pnpm install llamaindex
pnpm install @types/node
```
Create the file example.ts
@@ -54,28 +61,38 @@ main();
Then you can run it using
```bash
npx ts-node example.ts
pnpm dlx ts-node example.ts
```
## Playground
Check out our NextJS playground at https://llama-playground.vercel.app/. The source is available at https://github.com/run-llama/ts-playground
## Core concepts for getting started:
- [Document](packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Document](/packages/core/src/Node.ts): A document represents a text file, PDF file or other contiguous piece of data.
- [Node](packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Node](/packages/core/src/Node.ts): The basic data building block. Most commonly, these are parts of the document split into manageable pieces that are small enough to be fed into an embedding model and LLM.
- [Embedding](packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Embedding](/packages/core/src/Embedding.ts): Embeddings are sets of floating point numbers which represent the data in a Node. By comparing the similarity of embeddings, we can derive an understanding of the similarity of two pieces of data. One use case is to compare the embedding of a question with the embeddings of our Nodes to see which Nodes may contain the data needed to answer that quesiton.
- [Indices](packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [Indices](/packages/core/src/indices/): Indices store the Nodes and the embeddings of those nodes. QueryEngines retrieve Nodes from these Indices using embedding similarity.
- [QueryEngine](packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [QueryEngine](/packages/core/src/QueryEngine.ts): Query engines are what generate the query you put in and give you back the result. Query engines generally combine a pre-built prompt with selected Nodes from your Index to give the LLM the context it needs to answer your query.
- [ChatEngine](packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [ChatEngine](/packages/core/src/ChatEngine.ts): A ChatEngine helps you build a chatbot that will interact with your Indices.
- [SimplePrompt](packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
- [SimplePrompt](/packages/core/src/Prompt.ts): A simple standardized function call definition that takes in inputs and formats them in a template literal. SimplePrompts can be specialized using currying and combined using other SimplePrompt functions.
## Supported LLMs:
- OpenAI GPT-3.5-turbo and GPT-4
- Anthropic Claude Instant and Claude 2
- Llama2 Chat LLMs (70B, 13B, and 7B parameters)
## Contributing:
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](CONTRIBUTING.md)
We are in the very early days of LlamaIndex.TS. If youre interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
## Bugs? Questions?
+4 -5
View File
@@ -1,13 +1,12 @@
{
"name": "llamaindex",
"version": "0.0.14",
"version": "0.0.17",
"dependencies": {
"@anthropic-ai/sdk": "^0.5.8",
"js-tiktoken": "^1.0.7",
"@anthropic-ai/sdk": "^0.5.9",
"lodash": "^4.17.21",
"openai": "4.0.0-beta.6",
"openai": "4.0.0-beta.8",
"pdf-parse": "^1.1.1",
"replicate": "^0.12.3",
"replicate": "^0.14.1",
"tiktoken-node": "^0.0.6",
"uuid": "^9.0.0",
"wink-nlp": "^1.14.3"
+40 -7
View File
@@ -1,4 +1,11 @@
import { DEFAULT_SIMILARITY_TOP_K } from "./constants";
import {
AzureOpenAIConfig,
getAzureConfigFromEnv,
getAzureModel,
getAzureBaseUrl,
shouldUseAzure,
} from "./llm/azure";
import { OpenAISession, getOpenAISession } from "./llm/openai";
import { VectorStoreQueryMode } from "./storage/vectorStore/types";
@@ -219,19 +226,45 @@ export class OpenAIEmbedding extends BaseEmbedding {
timeout?: number;
session: OpenAISession;
constructor(init?: Partial<OpenAIEmbedding>) {
constructor(init?: Partial<OpenAIEmbedding> & { azure?: AzureOpenAIConfig }) {
super();
this.model = OpenAIEmbeddingModelType.TEXT_EMBED_ADA_002;
this.apiKey = init?.apiKey ?? undefined;
this.maxRetries = init?.maxRetries ?? 10;
this.timeout = init?.timeout ?? undefined;
this.session = getOpenAISession({
apiKey: this.apiKey,
maxRetries: this.maxRetries,
timeout: this.timeout,
});
if (init?.azure || shouldUseAzure()) {
const azureConfig = getAzureConfigFromEnv({
...init?.azure,
model: getAzureModel(this.model),
});
if (!azureConfig.apiKey) {
throw new Error(
"Azure API key is required for OpenAI Azure models. Please set the AZURE_OPENAI_KEY environment variable."
);
}
this.apiKey = azureConfig.apiKey;
this.session =
init?.session ??
getOpenAISession({
azure: true,
apiKey: this.apiKey,
baseURL: getAzureBaseUrl(azureConfig),
maxRetries: this.maxRetries,
timeout: this.timeout,
defaultQuery: { "api-version": azureConfig.apiVersion },
});
} else {
this.apiKey = init?.apiKey ?? undefined;
this.session = getOpenAISession({
apiKey: this.apiKey,
maxRetries: this.maxRetries,
timeout: this.timeout,
});
}
}
private async getOpenAIEmbedding(input: string) {
+68 -10
View File
@@ -1,3 +1,4 @@
import crypto from "crypto"; // TODO Node dependency
import { v4 as uuidv4 } from "uuid";
export enum NodeRelationship {
@@ -35,6 +36,12 @@ export type RelatedNodeType = RelatedNodeInfo | RelatedNodeInfo[];
* Generic abstract class for retrievable nodes
*/
export abstract class BaseNode {
/**
* The unique ID of the Node/Document. The trailing underscore is here
* to avoid collisions with the id keyword in Python.
*
* Set to a UUID by default.
*/
id_: string = uuidv4();
embedding?: number[];
@@ -55,10 +62,6 @@ export abstract class BaseNode {
abstract getMetadataStr(metadataMode: MetadataMode): string;
abstract setContent(value: any): void;
get nodeId(): string {
return this.id_;
}
get sourceNode(): RelatedNodeInfo | undefined {
const relationship = this.relationships[NodeRelationship.SOURCE];
@@ -74,7 +77,7 @@ export abstract class BaseNode {
if (Array.isArray(relationship)) {
throw new Error(
"Previous object must be a single RelatedNodeInfo object"
"Previous object must be a single RelatedNodeInfo object",
);
}
@@ -106,13 +109,15 @@ export abstract class BaseNode {
if (!Array.isArray(relationship)) {
throw new Error(
"Child object must be a an array of RelatedNodeInfo objects"
"Child object must be a an array of RelatedNodeInfo objects",
);
}
return relationship;
}
abstract generateHash(): string;
getEmbedding(): number[] {
if (this.embedding === undefined) {
throw new Error("Embedding not set");
@@ -123,11 +128,19 @@ export abstract class BaseNode {
asRelatedNodeInfo(): RelatedNodeInfo {
return {
nodeId: this.nodeId,
nodeId: this.id_,
metadata: this.metadata,
hash: this.hash,
};
}
/**
* Used with built in JSON.stringify
* @returns
*/
toJSON(): Record<string, any> {
return { ...this, type: this.getType() };
}
}
/**
@@ -144,10 +157,27 @@ export class TextNode extends BaseNode {
constructor(init?: Partial<TextNode>) {
super(init);
Object.assign(this, init);
if (new.target === TextNode) {
// Don't generate the hash repeatedly so only do it if this is
// constructing the derived class
this.hash = this.generateHash();
}
}
/**
* Generate a hash of the text node.
* The ID is not part of the hash as it can change independent of content.
* @returns
*/
generateHash() {
throw new Error("Not implemented");
const hashFunction = crypto.createHash("sha256");
hashFunction.update(`type=${this.getType()}`);
hashFunction.update(
`startCharIdx=${this.startCharIdx} endCharIdx=${this.endCharIdx}`,
);
hashFunction.update(this.getContent(MetadataMode.ALL));
return hashFunction.digest("base64");
}
getType(): ObjectType {
@@ -182,6 +212,8 @@ export class TextNode extends BaseNode {
setContent(value: string) {
this.text = value;
this.hash = this.generateHash();
}
getNodeInfo() {
@@ -204,6 +236,15 @@ export class TextNode extends BaseNode {
export class IndexNode extends TextNode {
indexId: string = "";
constructor(init?: Partial<IndexNode>) {
super(init);
Object.assign(this, init);
if (new.target === IndexNode) {
this.hash = this.generateHash();
}
}
getType(): ObjectType {
return ObjectType.INDEX;
}
@@ -216,14 +257,31 @@ export class Document extends TextNode {
constructor(init?: Partial<Document>) {
super(init);
Object.assign(this, init);
if (new.target === Document) {
this.hash = this.generateHash();
}
}
getType() {
return ObjectType.DOCUMENT;
}
}
get docId() {
return this.id_;
export function jsonToNode(json: any) {
if (!json.type) {
throw new Error("Node type not found");
}
switch (json.type) {
case ObjectType.TEXT:
return new TextNode(json);
case ObjectType.INDEX:
return new IndexNode(json);
case ObjectType.DOCUMENT:
return new Document(json);
default:
throw new Error(`Invalid node type: ${json.type}`);
}
}
+1 -3
View File
@@ -24,6 +24,4 @@ export * from "./readers/base";
export * from "./readers/PDFReader";
export * from "./readers/SimpleDirectoryReader";
export * from "./storage/constants";
export * from "./storage/FileSystem";
export * from "./storage/StorageContext";
export * from "./storage";
+35 -9
View File
@@ -1,13 +1,13 @@
import { Document, BaseNode } from "../Node";
import { v4 as uuidv4 } from "uuid";
import { BaseRetriever } from "../Retriever";
import { ServiceContext } from "../ServiceContext";
import { StorageContext } from "../storage/StorageContext";
import { BaseDocumentStore } from "../storage/docStore/types";
import { VectorStore } from "../storage/vectorStore/types";
import { BaseIndexStore } from "../storage/indexStore/types";
import { BaseNode, Document, jsonToNode } from "../Node";
import { BaseQueryEngine } from "../QueryEngine";
import { ResponseSynthesizer } from "../ResponseSynthesizer";
import { BaseRetriever } from "../Retriever";
import { ServiceContext } from "../ServiceContext";
import { BaseDocumentStore } from "../storage/docStore/types";
import { BaseIndexStore } from "../storage/indexStore/types";
import { StorageContext } from "../storage/StorageContext";
import { VectorStore } from "../storage/vectorStore/types";
/**
* The underlying structure of each index.
@@ -43,7 +43,6 @@ export enum IndexStructType {
export class IndexDict extends IndexStruct {
nodesDict: Record<string, BaseNode> = {};
docStore: Record<string, Document> = {}; // FIXME: this should be implemented in storageContext
type: IndexStructType = IndexStructType.SIMPLE_DICT;
getSummary(): string {
@@ -65,6 +64,10 @@ export class IndexDict extends IndexStruct {
type: this.type,
};
}
delete(nodeId: string) {
delete this.nodesDict[nodeId];
}
}
export function jsonToIndexStruct(json: any): IndexStruct {
@@ -74,7 +77,12 @@ export function jsonToIndexStruct(json: any): IndexStruct {
return indexList;
} else if (json.type === IndexStructType.SIMPLE_DICT) {
const indexDict = new IndexDict(json.indexId, json.summary);
indexDict.nodesDict = json.nodesDict;
indexDict.nodesDict = Object.entries(json.nodesDict).reduce<
Record<string, BaseNode>
>((acc, [key, value]) => {
acc[key] = jsonToNode(value);
return acc;
}, {});
return indexDict;
} else {
throw new Error(`Unknown index struct type: ${json.type}`);
@@ -143,6 +151,24 @@ export abstract class BaseIndex<T> {
retriever?: BaseRetriever;
responseSynthesizer?: ResponseSynthesizer;
}): BaseQueryEngine;
/**
* Insert a document into the index.
* @param document
*/
async insert(document: Document) {
const nodes = this.serviceContext.nodeParser.getNodesFromDocuments([
document,
]);
await this.insertNodes(nodes);
this.docStore.setDocumentHash(document.id_, document.hash);
}
abstract insertNodes(nodes: BaseNode[]): Promise<void>;
abstract deleteRefDoc(
refDocId: string,
deleteFromDocStore?: boolean,
): Promise<void>;
}
export interface VectorIndexOptions {
+57 -26
View File
@@ -1,26 +1,30 @@
import _ from "lodash";
import { BaseNode, Document } from "../../Node";
import { BaseIndex, BaseIndexInit, IndexList } from "../BaseIndex";
import { BaseQueryEngine, RetrieverQueryEngine } from "../../QueryEngine";
import {
StorageContext,
storageContextFromDefaults,
} from "../../storage/StorageContext";
CompactAndRefine,
ResponseSynthesizer,
} from "../../ResponseSynthesizer";
import { BaseRetriever } from "../../Retriever";
import {
ListIndexRetriever,
ListIndexLLMRetriever,
} from "./ListIndexRetriever";
import {
ServiceContext,
serviceContextFromDefaults,
} from "../../ServiceContext";
import { BaseDocumentStore, RefDocInfo } from "../../storage/docStore/types";
import _ from "lodash";
import {
ResponseSynthesizer,
CompactAndRefine,
} from "../../ResponseSynthesizer";
import { IndexStructType } from "../BaseIndex";
StorageContext,
storageContextFromDefaults,
} from "../../storage/StorageContext";
import {
BaseIndex,
BaseIndexInit,
IndexList,
IndexStructType,
} from "../BaseIndex";
import {
ListIndexLLMRetriever,
ListIndexRetriever,
} from "./ListIndexRetriever";
export enum ListRetrieverMode {
DEFAULT = "default",
@@ -57,7 +61,7 @@ export class ListIndex extends BaseIndex<IndexList> {
if (options.indexStruct && indexStructs.length > 0) {
throw new Error(
"Cannot initialize index with both indexStruct and indexStore"
"Cannot initialize index with both indexStruct and indexStore",
);
}
@@ -67,7 +71,7 @@ export class ListIndex extends BaseIndex<IndexList> {
indexStruct = indexStructs[0];
} else if (indexStructs.length > 1 && options.indexId) {
indexStruct = (await indexStore.getIndexStruct(
options.indexId
options.indexId,
)) as IndexList;
} else {
indexStruct = null;
@@ -76,25 +80,25 @@ export class ListIndex extends BaseIndex<IndexList> {
// check indexStruct type
if (indexStruct && indexStruct.type !== IndexStructType.LIST) {
throw new Error(
"Attempting to initialize ListIndex with non-list indexStruct"
"Attempting to initialize ListIndex with non-list indexStruct",
);
}
if (indexStruct) {
if (options.nodes) {
throw new Error(
"Cannot initialize VectorStoreIndex with both nodes and indexStruct"
"Cannot initialize VectorStoreIndex with both nodes and indexStruct",
);
}
} else {
if (!options.nodes) {
throw new Error(
"Cannot initialize VectorStoreIndex without nodes or indexStruct"
"Cannot initialize VectorStoreIndex without nodes or indexStruct",
);
}
indexStruct = await ListIndex._buildIndexFromNodes(
indexStruct = await ListIndex.buildIndexFromNodes(
options.nodes,
storageContext.docStore
storageContext.docStore,
);
await indexStore.addIndexStruct(indexStruct);
@@ -114,7 +118,7 @@ export class ListIndex extends BaseIndex<IndexList> {
args: {
storageContext?: StorageContext;
serviceContext?: ServiceContext;
} = {}
} = {},
): Promise<ListIndex> {
let { storageContext, serviceContext } = args;
storageContext = storageContext ?? (await storageContextFromDefaults({}));
@@ -169,10 +173,10 @@ export class ListIndex extends BaseIndex<IndexList> {
return new RetrieverQueryEngine(retriever, responseSynthesizer);
}
static async _buildIndexFromNodes(
static async buildIndexFromNodes(
nodes: BaseNode[],
docStore: BaseDocumentStore,
indexStruct?: IndexList
indexStruct?: IndexList,
): Promise<IndexList> {
indexStruct = indexStruct || new IndexList();
@@ -184,16 +188,43 @@ export class ListIndex extends BaseIndex<IndexList> {
return indexStruct;
}
protected _insert(nodes: BaseNode[]): void {
async insertNodes(nodes: BaseNode[]): Promise<void> {
for (const node of nodes) {
this.indexStruct.addNode(node);
}
}
protected _deleteNode(nodeId: string): void {
async deleteRefDoc(
refDocId: string,
deleteFromDocStore?: boolean,
): Promise<void> {
const refDocInfo = await this.docStore.getRefDocInfo(refDocId);
if (!refDocInfo) {
return;
}
await this.deleteNodes(refDocInfo.nodeIds, false);
if (deleteFromDocStore) {
await this.docStore.deleteRefDoc(refDocId, false);
}
return;
}
async deleteNodes(nodeIds: string[], deleteFromDocStore: boolean) {
this.indexStruct.nodes = this.indexStruct.nodes.filter(
(existingNodeId: string) => existingNodeId !== nodeId
(existingNodeId: string) => !nodeIds.includes(existingNodeId),
);
if (deleteFromDocStore) {
for (const nodeId of nodeIds) {
await this.docStore.deleteDocument(nodeId, false);
}
}
await this.storageContext.indexStore.addIndexStruct(this.indexStruct);
}
async getRefDocInfo(): Promise<Record<string, RefDocInfo>> {
@@ -41,7 +41,7 @@ export class VectorIndexRetriever implements BaseRetriever {
mode: VectorStoreQueryMode.DEFAULT,
similarityTopK: this.similarityTopK,
};
const result = this.index.vectorStore.query(q);
const result = await this.index.vectorStore.query(q);
let nodesWithScores: NodeWithScore[] = [];
for (let i = 0; i < result.ids.length; i++) {
@@ -1,15 +1,17 @@
import {
Document,
BaseNode,
Document,
MetadataMode,
NodeWithEmbedding,
} from "../../Node";
import { BaseQueryEngine, RetrieverQueryEngine } from "../../QueryEngine";
import { VectorIndexRetriever } from "./VectorIndexRetriever";
import { ResponseSynthesizer } from "../../ResponseSynthesizer";
import { BaseRetriever } from "../../Retriever";
import {
ServiceContext,
serviceContextFromDefaults,
} from "../../ServiceContext";
import { BaseDocumentStore } from "../../storage/docStore/types";
import {
StorageContext,
storageContextFromDefaults,
@@ -18,13 +20,11 @@ import { VectorStore } from "../../storage/vectorStore/types";
import {
BaseIndex,
IndexDict,
IndexStructType,
VectorIndexConstructorProps,
VectorIndexOptions,
IndexStructType
} from "../BaseIndex";
import { BaseRetriever } from "../../Retriever";
import { ResponseSynthesizer } from "../../ResponseSynthesizer";
import { BaseDocumentStore } from "../../storage/docStore/types";
import { VectorIndexRetriever } from "./VectorIndexRetriever";
/**
* The VectorStoreIndex, an index that stores the nodes only according to their vector embedings.
@@ -55,11 +55,11 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
// Setup IndexStruct from storage
let indexStructs = (await indexStore.getIndexStructs()) as IndexDict[];
let indexStruct: IndexDict | null;
let indexStruct: IndexDict | undefined;
if (options.indexStruct && indexStructs.length > 0) {
throw new Error(
"Cannot initialize index with both indexStruct and indexStore"
"Cannot initialize index with both indexStruct and indexStore",
);
}
@@ -69,41 +69,37 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
indexStruct = indexStructs[0];
} else if (indexStructs.length > 1 && options.indexId) {
indexStruct = (await indexStore.getIndexStruct(
options.indexId
options.indexId,
)) as IndexDict;
} else {
indexStruct = null;
indexStruct = undefined;
}
// check indexStruct type
if (indexStruct && indexStruct.type !== IndexStructType.SIMPLE_DICT) {
throw new Error(
"Attempting to initialize VectorStoreIndex with non-vector indexStruct"
"Attempting to initialize VectorStoreIndex with non-vector indexStruct",
);
}
if (indexStruct) {
if (options.nodes) {
throw new Error(
"Cannot initialize VectorStoreIndex with both nodes and indexStruct"
);
}
} else {
if (!options.nodes) {
throw new Error(
"Cannot initialize VectorStoreIndex without nodes or indexStruct"
);
}
indexStruct = await VectorStoreIndex.buildIndexFromNodes(
options.nodes,
serviceContext,
vectorStore,
docStore
if (!indexStruct && !options.nodes) {
throw new Error(
"Cannot initialize VectorStoreIndex without nodes or indexStruct",
);
await indexStore.addIndexStruct(indexStruct);
}
const nodes = options.nodes ?? [];
indexStruct = await VectorStoreIndex.buildIndexFromNodes(
nodes,
serviceContext,
vectorStore,
docStore,
indexStruct,
);
await indexStore.addIndexStruct(indexStruct);
return new VectorStoreIndex({
storageContext,
serviceContext,
@@ -123,7 +119,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
static async getNodeEmbeddingResults(
nodes: BaseNode[],
serviceContext: ServiceContext,
logProgress = false
logProgress = false,
) {
const nodesWithEmbeddings: NodeWithEmbedding[] = [];
@@ -133,7 +129,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
console.log(`getting embedding for node ${i}/${nodes.length}`);
}
const embedding = await serviceContext.embedModel.getTextEmbedding(
node.getContent(MetadataMode.EMBED)
node.getContent(MetadataMode.EMBED),
);
nodesWithEmbeddings.push({ node, embedding });
}
@@ -152,23 +148,35 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
nodes: BaseNode[],
serviceContext: ServiceContext,
vectorStore: VectorStore,
docStore: BaseDocumentStore
docStore: BaseDocumentStore,
indexDict?: IndexDict,
): Promise<IndexDict> {
const embeddingResults = await this.getNodeEmbeddingResults(
nodes,
serviceContext
indexDict = indexDict ?? new IndexDict();
// Check if the index already has nodes with the same hash
const newNodes = nodes.filter((node) =>
Object.entries(indexDict!.nodesDict).reduce((acc, [key, value]) => {
if (value.hash === node.hash) {
acc = false;
}
return acc;
}, true),
);
vectorStore.add(embeddingResults);
const embeddingResults = await this.getNodeEmbeddingResults(
newNodes,
serviceContext,
);
await vectorStore.add(embeddingResults);
if (!vectorStore.storesText) {
await docStore.addDocuments(
embeddingResults.map((result) => result.node),
true
true,
);
}
const indexDict = new IndexDict();
for (const { node } of embeddingResults) {
indexDict.addNode(node);
}
@@ -188,7 +196,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
args: {
storageContext?: StorageContext;
serviceContext?: ServiceContext;
} = {}
} = {},
): Promise<VectorStoreIndex> {
let { storageContext, serviceContext } = args;
storageContext = storageContext ?? (await storageContextFromDefaults({}));
@@ -217,6 +225,57 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
responseSynthesizer?: ResponseSynthesizer;
}): BaseQueryEngine {
const { retriever, responseSynthesizer } = options ?? {};
return new RetrieverQueryEngine(retriever ?? this.asRetriever(), responseSynthesizer);
return new RetrieverQueryEngine(
retriever ?? this.asRetriever(),
responseSynthesizer,
);
}
async insertNodes(nodes: BaseNode[]): Promise<void> {
const embeddingResults = await VectorStoreIndex.getNodeEmbeddingResults(
nodes,
this.serviceContext,
);
const newIds = await this.vectorStore.add(embeddingResults);
if (!this.vectorStore.storesText) {
for (let i = 0; i < nodes.length; ++i) {
this.indexStruct.addNode(nodes[i], newIds[i]);
this.docStore.addDocuments([nodes[i]], true);
}
} else {
for (let i = 0; i < nodes.length; ++i) {
if (nodes[i].getType() === "INDEX") {
this.indexStruct.addNode(nodes[i], newIds[i]);
this.docStore.addDocuments([nodes[i]], true);
}
}
}
await this.storageContext.indexStore.addIndexStruct(this.indexStruct);
}
async deleteRefDoc(
refDocId: string,
deleteFromDocStore: boolean = true,
): Promise<void> {
this.vectorStore.delete(refDocId);
if (!this.vectorStore.storesText) {
const refDocInfo = await this.docStore.getRefDocInfo(refDocId);
if (refDocInfo) {
for (const nodeId of refDocInfo.nodeIds) {
this.indexStruct.delete(nodeId);
}
}
await this.storageContext.indexStore.addIndexStruct(this.indexStruct);
}
if (deleteFromDocStore) {
await this.docStore.deleteDocument(refDocId, false);
}
}
}
+165 -69
View File
@@ -1,14 +1,21 @@
import OpenAILLM from "openai";
import { CallbackManager, Event } from "../callbacks/CallbackManager";
import { handleOpenAIStream } from "../callbacks/utility/handleOpenAIStream";
import { OpenAISession, getOpenAISession } from "./openai";
import OpenAILLM from "openai";
import { ReplicateSession } from "./replicate";
import {
AnthropicSession,
ANTHROPIC_AI_PROMPT,
ANTHROPIC_HUMAN_PROMPT,
AnthropicSession,
getAnthropicSession,
} from "./anthropic";
import {
AzureOpenAIConfig,
getAzureBaseUrl,
getAzureConfigFromEnv,
getAzureModel,
shouldUseAzure,
} from "./azure";
import { getOpenAISession, OpenAISession } from "./openai";
import { ReplicateSession } from "./replicate";
export type MessageType =
| "user"
@@ -84,28 +91,54 @@ export class OpenAI implements LLM {
callbackManager?: CallbackManager;
constructor(init?: Partial<OpenAI>) {
constructor(init?: Partial<OpenAI> & { azure?: AzureOpenAIConfig }) {
this.model = init?.model ?? "gpt-3.5-turbo";
this.temperature = init?.temperature ?? 0;
this.temperature = init?.temperature ?? 0.1;
this.topP = init?.topP ?? 1;
this.maxTokens = init?.maxTokens ?? undefined;
this.apiKey = init?.apiKey ?? undefined;
this.maxRetries = init?.maxRetries ?? 10;
this.timeout = init?.timeout ?? undefined; // Default is 60 seconds
this.session =
init?.session ??
getOpenAISession({
apiKey: this.apiKey,
maxRetries: this.maxRetries,
timeout: this.timeout,
if (init?.azure || shouldUseAzure()) {
const azureConfig = getAzureConfigFromEnv({
...init?.azure,
model: getAzureModel(this.model),
});
if (!azureConfig.apiKey) {
throw new Error(
"Azure API key is required for OpenAI Azure models. Please set the AZURE_OPENAI_KEY environment variable.",
);
}
this.apiKey = azureConfig.apiKey;
this.session =
init?.session ??
getOpenAISession({
azure: true,
apiKey: this.apiKey,
baseURL: getAzureBaseUrl(azureConfig),
maxRetries: this.maxRetries,
timeout: this.timeout,
defaultQuery: { "api-version": azureConfig.apiVersion },
});
} else {
this.apiKey = init?.apiKey ?? undefined;
this.session =
init?.session ??
getOpenAISession({
apiKey: this.apiKey,
maxRetries: this.maxRetries,
timeout: this.timeout,
});
}
this.callbackManager = init?.callbackManager;
}
mapMessageType(
messageType: MessageType
messageType: MessageType,
): "user" | "assistant" | "system" | "function" {
switch (messageType) {
case "user":
@@ -123,7 +156,7 @@ export class OpenAI implements LLM {
async chat(
messages: ChatMessage[],
parentEvent?: Event
parentEvent?: Event,
): Promise<ChatResponse> {
const baseRequestParams: OpenAILLM.Chat.CompletionCreateParams = {
model: this.model,
@@ -151,9 +184,10 @@ export class OpenAI implements LLM {
return { message: { content: message, role } };
} else {
// Non-streaming
const response = await this.session.openai.chat.completions.create(
baseRequestParams
);
const response = await this.session.openai.chat.completions.create({
...baseRequestParams,
stream: false,
});
const content = response.choices[0].message?.content ?? "";
return { message: { content, role: response.choices[0].message.role } };
@@ -162,27 +196,49 @@ export class OpenAI implements LLM {
async complete(
prompt: string,
parentEvent?: Event
parentEvent?: Event,
): Promise<CompletionResponse> {
return this.chat([{ content: prompt, role: "user" }], parentEvent);
}
}
export const ALL_AVAILABLE_LLAMADEUCE_MODELS = {
"Llama-2-70b-chat": {
"Llama-2-70b-chat-old": {
contextWindow: 4096,
replicateApi:
"replicate/llama70b-v2-chat:e951f18578850b652510200860fc4ea62b3b16fac280f83ff32282f87bbd2e48",
//^ Previous 70b model. This is also actually 4 bit, although not exllama.
},
"Llama-2-70b-chat-4bit": {
contextWindow: 4096,
replicateApi:
"replicate/llama70b-v2-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1",
//^ Model is based off of exllama 4bit.
},
"Llama-2-13b-chat": {
contextWindow: 4096,
replicateApi:
"a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5",
},
//^ Last known good 13b non-quantized model. In future versions they add the SYS and INST tags themselves
"Llama-2-13b-chat-4bit": {
contextWindow: 4096,
replicateApi:
"a16z-infra/llama13b-v2-chat:2a7f981751ec7fdf87b5b91ad4db53683a98082e9ff7bfd12c8cd5ea85980a52",
},
"Llama-2-7b-chat": {
contextWindow: 4096,
replicateApi:
"a16z-infra/llama7b-v2-chat:4f0a4744c7295c024a1de15e1a63c880d3da035fa1f49bfd344fe076074c8eea",
//^ Last (somewhat) known good 7b non-quantized model. In future versions they add the SYS and INST
// tags themselves
// https://github.com/replicate/cog-llama-template/commit/fa5ce83912cf82fc2b9c01a4e9dc9bff6f2ef137
// Problem is that they fix the max_new_tokens issue in the same commit. :-(
},
"Llama-2-7b-chat-4bit": {
contextWindow: 4096,
replicateApi:
"a16z-infra/llama7b-v2-chat:4f0b260b6a13eb53a6b1891f089d57c08f41003ae79458be5011303d81a394dc",
},
};
@@ -192,6 +248,8 @@ export enum DeuceChatStrategy {
METAWBOS = "metawbos",
//^ This is not exactly right because SentencePiece puts the BOS and EOS token IDs in after tokenization
// Unfortunately any string only API won't support these properly.
REPLICATE4BIT = "replicate4bit",
//^ To satisfy Replicate's 4 bit models' requirements where they also insert some INST tags
}
/**
@@ -206,35 +264,46 @@ export class LlamaDeuce implements LLM {
replicateSession: ReplicateSession;
constructor(init?: Partial<LlamaDeuce>) {
this.model = init?.model ?? "Llama-2-70b-chat";
this.chatStrategy = init?.chatStrategy ?? DeuceChatStrategy.META;
this.temperature = init?.temperature ?? 0.01; // minimum temperature is 0.01 for Replicate endpoint
this.model = init?.model ?? "Llama-2-70b-chat-4bit";
this.chatStrategy =
init?.chatStrategy ??
(this.model.endsWith("4bit")
? DeuceChatStrategy.REPLICATE4BIT // With the newer A16Z/Replicate models they do the system message themselves.
: DeuceChatStrategy.METAWBOS); // With BOS and EOS seems to work best, although they all have problems past a certain point
this.temperature = init?.temperature ?? 0.1; // minimum temperature is 0.01 for Replicate endpoint
this.topP = init?.topP ?? 1;
this.maxTokens = init?.maxTokens ?? undefined; // By default this means it's 500 tokens according to Replicate docs
this.maxTokens =
init?.maxTokens ??
ALL_AVAILABLE_LLAMADEUCE_MODELS[this.model].contextWindow; // For Replicate, the default is 500 tokens which is too low.
this.replicateSession = init?.replicateSession ?? new ReplicateSession();
}
mapMessagesToPrompt(messages: ChatMessage[]): string {
mapMessagesToPrompt(messages: ChatMessage[]) {
if (this.chatStrategy === DeuceChatStrategy.A16Z) {
return this.mapMessagesToPromptA16Z(messages);
} else if (this.chatStrategy === DeuceChatStrategy.META) {
return this.mapMessagesToPromptMeta(messages);
} else if (this.chatStrategy === DeuceChatStrategy.METAWBOS) {
return this.mapMessagesToPromptMeta(messages, true);
return this.mapMessagesToPromptMeta(messages, { withBos: true });
} else if (this.chatStrategy === DeuceChatStrategy.REPLICATE4BIT) {
return this.mapMessagesToPromptMeta(messages, { replicate4Bit: true });
} else {
return this.mapMessagesToPromptMeta(messages);
}
}
mapMessagesToPromptA16Z(messages: ChatMessage[]): string {
return (
messages.reduce((acc, message) => {
return (
(acc && `${acc}\n\n`) +
`${this.mapMessageTypeA16Z(message.role)}${message.content}`
);
}, "") + "\n\nAssistant:"
); // Here we're differing from A16Z by omitting the space. Generally spaces at the end of prompts decrease performance due to tokenization
mapMessagesToPromptA16Z(messages: ChatMessage[]) {
return {
prompt:
messages.reduce((acc, message) => {
return (
(acc && `${acc}\n\n`) +
`${this.mapMessageTypeA16Z(message.role)}${message.content}`
);
}, "") + "\n\nAssistant:",
//^ Here we're differing from A16Z by omitting the space. Generally spaces at the end of prompts decrease performance due to tokenization
systemPrompt: undefined,
};
}
mapMessageTypeA16Z(messageType: MessageType): string {
@@ -250,7 +319,11 @@ export class LlamaDeuce implements LLM {
}
}
mapMessagesToPromptMeta(messages: ChatMessage[], withBos = false): string {
mapMessagesToPromptMeta(
messages: ChatMessage[],
opts?: { withBos?: boolean; replicate4Bit?: boolean },
) {
const { withBos = false, replicate4Bit = false } = opts ?? {};
const DEFAULT_SYSTEM_PROMPT = `You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.`;
@@ -263,61 +336,84 @@ If a question does not make any sense, or is not factually coherent, explain why
const EOS = "</s>";
if (messages.length === 0) {
return "";
return { prompt: "", systemPrompt: undefined };
}
messages = [...messages]; // so we can use shift without mutating the original array
let systemPrompt = undefined;
if (messages[0].role === "system") {
const systemMessage = messages.shift()!;
const systemStr = `${B_SYS}${systemMessage.content}${E_SYS}`;
if (replicate4Bit) {
systemPrompt = systemMessage.content;
} else {
const systemStr = `${B_SYS}${systemMessage.content}${E_SYS}`;
if (messages[1].role !== "user") {
throw new Error(
"LlamaDeuce: if there is a system message, the second message must be a user message."
);
// TS Bug: https://github.com/microsoft/TypeScript/issues/9998
// @ts-ignore
if (messages[0].role !== "user") {
throw new Error(
"LlamaDeuce: if there is a system message, the second message must be a user message.",
);
}
const userContent = messages[0].content;
messages[0].content = `${systemStr}${userContent}`;
}
const userContent = messages[0].content;
messages[0].content = `${systemStr}${userContent}`;
} else {
messages[0].content = `${B_SYS}${DEFAULT_SYSTEM_PROMPT}${E_SYS}${messages[0].content}`;
if (!replicate4Bit) {
messages[0].content = `${B_SYS}${DEFAULT_SYSTEM_PROMPT}${E_SYS}${messages[0].content}`;
}
}
return messages.reduce((acc, message, index) => {
if (index % 2 === 0) {
return (
(withBos ? BOS : "") +
`${acc}${B_INST} ${message.content.trim()} ${E_INST}`
);
} else {
return `${acc} ${message.content.trim()} ` + (withBos ? EOS : ""); // Yes, the EOS comes after the space. This is not a mistake.
}
}, "");
return {
prompt: messages.reduce((acc, message, index) => {
if (index % 2 === 0) {
return `${acc}${
withBos ? BOS : ""
}${B_INST} ${message.content.trim()} ${E_INST}`;
} else {
return `${acc} ${message.content.trim()} ` + (withBos ? EOS : ""); // Yes, the EOS comes after the space. This is not a mistake.
}
}, ""),
systemPrompt,
};
}
async chat(
messages: ChatMessage[],
_parentEvent?: Event
_parentEvent?: Event,
): Promise<ChatResponse> {
const api = ALL_AVAILABLE_LLAMADEUCE_MODELS[this.model]
.replicateApi as `${string}/${string}:${string}`;
const prompt = this.mapMessagesToPrompt(messages);
const { prompt, systemPrompt } = this.mapMessagesToPrompt(messages);
const response = await this.replicateSession.replicate.run(api, {
const replicateOptions: any = {
input: {
prompt,
system_prompt: "", // We are already sending the system prompt so set system prompt to empty.
max_new_tokens: this.maxTokens,
system_prompt: systemPrompt,
temperature: this.temperature,
top_p: this.topP,
},
});
};
if (this.model.endsWith("4bit")) {
replicateOptions.input.max_new_tokens = this.maxTokens;
} else {
replicateOptions.input.max_length = this.maxTokens;
}
const response = await this.replicateSession.replicate.run(
api,
replicateOptions,
);
return {
message: {
content: (response as Array<string>).join(""),
// We need to do this because Replicate returns a list of strings (for streaming functionality which is not exposed by the run function)
content: (response as Array<string>).join("").trimStart(),
//^ We need to do this because Replicate returns a list of strings (for streaming functionality which is not exposed by the run function)
role: "assistant",
},
};
@@ -325,7 +421,7 @@ If a question does not make any sense, or is not factually coherent, explain why
async complete(
prompt: string,
parentEvent?: Event
parentEvent?: Event,
): Promise<CompletionResponse> {
return this.chat([{ content: prompt, role: "user" }], parentEvent);
}
@@ -352,7 +448,7 @@ export class Anthropic implements LLM {
constructor(init?: Partial<Anthropic>) {
this.model = init?.model ?? "claude-2";
this.temperature = init?.temperature ?? 0;
this.temperature = init?.temperature ?? 0.1;
this.topP = init?.topP ?? 0.999; // Per Ben Mann
this.maxTokens = init?.maxTokens ?? undefined;
@@ -387,7 +483,7 @@ export class Anthropic implements LLM {
async chat(
messages: ChatMessage[],
parentEvent?: Event | undefined
parentEvent?: Event | undefined,
): Promise<ChatResponse> {
const response = await this.session.anthropic.completions.create({
model: this.model,
@@ -405,7 +501,7 @@ export class Anthropic implements LLM {
}
async complete(
prompt: string,
parentEvent?: Event | undefined
parentEvent?: Event | undefined,
): Promise<CompletionResponse> {
return this.chat([{ content: prompt, role: "user" }], parentEvent);
}
+96
View File
@@ -0,0 +1,96 @@
export interface AzureOpenAIConfig {
apiKey?: string;
endpoint?: string;
apiVersion?: string;
deploymentName?: string;
}
// NOTE we're not supporting the legacy models as they're not available for new deployments
// https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/legacy-models
// If you have a need for them, please open an issue on GitHub
const ALL_AZURE_OPENAI_CHAT_MODELS = {
"gpt-35-turbo": { contextWindow: 4096, openAIModel: "gpt-3.5-turbo" },
"gpt-35-turbo-16k": {
contextWindow: 16384,
openAIModel: "gpt-3.5-turbo-16k",
},
"gpt-4": { contextWindow: 8192, openAIModel: "gpt-4" },
"gpt-4-32k": { contextWindow: 32768, openAIModel: "gpt-4-32k" },
};
const ALL_AZURE_OPENAI_EMBEDDING_MODELS = {
"text-embedding-ada-002": {
dimensions: 1536,
openAIModel: "text-embedding-ada-002",
maxTokens: 8191,
},
};
const ALL_AZURE_API_VERSIONS = [
"2022-12-01",
"2023-05-15",
"2023-06-01-preview",
"2023-07-01-preview",
];
const DEFAULT_API_VERSION = "2023-05-15";
//^ NOTE: this will change over time, if you want to pin it, use a specific version
export function getAzureConfigFromEnv(
init?: Partial<AzureOpenAIConfig> & { model?: string }
): AzureOpenAIConfig {
return {
apiKey:
init?.apiKey ??
process.env.AZURE_OPENAI_KEY ?? // From Azure docs
process.env.OPENAI_API_KEY ?? // Python compatible
process.env.AZURE_OPENAI_API_KEY, // LCJS compatible
endpoint:
init?.endpoint ??
process.env.AZURE_OPENAI_ENDPOINT ?? // From Azure docs
process.env.OPENAI_API_BASE ?? // Python compatible
process.env.AZURE_OPENAI_API_INSTANCE_NAME, // LCJS compatible
apiVersion:
init?.apiVersion ??
process.env.AZURE_OPENAI_API_VERSION ?? // From Azure docs
process.env.OPENAI_API_VERSION ?? // Python compatible
process.env.AZURE_OPENAI_API_VERSION ?? // LCJS compatible
DEFAULT_API_VERSION,
deploymentName:
init?.deploymentName ??
process.env.AZURE_OPENAI_DEPLOYMENT ?? // From Azure docs
process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME ?? // LCJS compatible
init?.model, // Fall back to model name, Python compatible
};
}
export function getAzureBaseUrl(config: AzureOpenAIConfig): string {
return `${config.endpoint}/openai/deployments/${config.deploymentName}`;
}
export function getAzureModel(openAIModel: string) {
for (const [key, value] of Object.entries(
ALL_AZURE_OPENAI_EMBEDDING_MODELS
)) {
if (value.openAIModel === openAIModel) {
return key;
}
}
for (const [key, value] of Object.entries(ALL_AZURE_OPENAI_CHAT_MODELS)) {
if (value.openAIModel === openAIModel) {
return key;
}
}
throw new Error(`Unknown model: ${openAIModel}`);
}
export function shouldUseAzure() {
return (
process.env.AZURE_OPENAI_ENDPOINT ||
process.env.AZURE_OPENAI_API_INSTANCE_NAME ||
process.env.OPENAI_API_TYPE === "azure"
);
}
+15 -3
View File
@@ -1,10 +1,16 @@
import OpenAI, { ClientOptions } from "openai";
import _ from "lodash";
export class AzureOpenAI extends OpenAI {
protected override authHeaders() {
return { "api-key": this.apiKey };
}
}
export class OpenAISession {
openai: OpenAI;
constructor(options: ClientOptions = {}) {
constructor(options: ClientOptions & { azure?: boolean } = {}) {
if (!options.apiKey) {
if (typeof process !== undefined) {
options.apiKey = process.env.OPENAI_API_KEY;
@@ -15,7 +21,11 @@ export class OpenAISession {
throw new Error("Set OpenAI Key in OPENAI_API_KEY env variable"); // Overriding OpenAI package's error message
}
this.openai = new OpenAI(options);
if (options.azure) {
this.openai = new AzureOpenAI(options);
} else {
this.openai = new OpenAI(options);
}
}
}
@@ -31,7 +41,9 @@ let defaultOpenAISession: { session: OpenAISession; options: ClientOptions }[] =
* @param options
* @returns
*/
export function getOpenAISession(options: ClientOptions = {}) {
export function getOpenAISession(
options: ClientOptions & { azure?: boolean } = {}
) {
let session = defaultOpenAISession.find((session) => {
return _.isEqual(session.options, options);
})?.session;
+1 -1
View File
@@ -1,7 +1,7 @@
export const DEFAULT_COLLECTION = "data";
export const DEFAULT_PERSIST_DIR = "./storage";
export const DEFAULT_INDEX_STORE_PERSIST_FILENAME = "index_store.json";
export const DEFAULT_DOC_STORE_PERSIST_FILENAME = "docstore.json";
export const DEFAULT_DOC_STORE_PERSIST_FILENAME = "doc_store.json";
export const DEFAULT_VECTOR_STORE_PERSIST_FILENAME = "vector_store.json";
export const DEFAULT_GRAPH_STORE_PERSIST_FILENAME = "graph_store.json";
export const DEFAULT_NAMESPACE = "docstore";
@@ -1,9 +1,9 @@
import { BaseNode, Document, ObjectType, TextNode } from "../../Node";
import { BaseDocumentStore, RefDocInfo } from "./types";
import { BaseKVStore } from "../kvStore/types";
import _, * as lodash from "lodash";
import { docToJson, jsonToDoc } from "./utils";
import { BaseNode, ObjectType } from "../../Node";
import { DEFAULT_NAMESPACE } from "../constants";
import { BaseKVStore } from "../kvStore/types";
import { BaseDocumentStore, RefDocInfo } from "./types";
import { docToJson, jsonToDoc } from "./utils";
type DocMetaData = { docHash: string; refDocId?: string };
@@ -32,7 +32,7 @@ export class KVDocumentStore extends BaseDocumentStore {
async addDocuments(
docs: BaseNode[],
allowUpdate: boolean = true
allowUpdate: boolean = true,
): Promise<void> {
for (var idx = 0; idx < docs.length; idx++) {
const doc = docs[idx];
@@ -41,7 +41,7 @@ export class KVDocumentStore extends BaseDocumentStore {
}
if (!allowUpdate && (await this.documentExists(doc.id_))) {
throw new Error(
`doc_id ${doc.id_} already exists. Set allow_update to True to overwrite.`
`doc_id ${doc.id_} already exists. Set allow_update to True to overwrite.`,
);
}
let nodeKey = doc.id_;
@@ -51,17 +51,17 @@ export class KVDocumentStore extends BaseDocumentStore {
if (doc.getType() === ObjectType.TEXT && doc.sourceNode !== undefined) {
let refDocInfo = (await this.getRefDocInfo(doc.sourceNode.nodeId)) || {
docIds: [],
nodeIds: [],
extraInfo: {},
};
refDocInfo.docIds.push(doc.id_);
refDocInfo.nodeIds.push(doc.id_);
if (_.isEmpty(refDocInfo.extraInfo)) {
refDocInfo.extraInfo = {};
}
await this.kvstore.put(
doc.sourceNode.nodeId,
refDocInfo,
this.refDocCollection
this.refDocCollection,
);
metadata.refDocId = doc.sourceNode.nodeId!;
}
@@ -72,7 +72,7 @@ export class KVDocumentStore extends BaseDocumentStore {
async getDocument(
docId: string,
raiseError: boolean = true
raiseError: boolean = true,
): Promise<BaseNode | undefined> {
let json = await this.kvstore.get(docId, this.nodeCollection);
if (_.isNil(json)) {
@@ -131,7 +131,7 @@ export class KVDocumentStore extends BaseDocumentStore {
async deleteDocument(
docId: string,
raiseError: boolean = true,
removeRefDocNode: boolean = true
removeRefDocNode: boolean = true,
): Promise<void> {
if (removeRefDocNode) {
await this.removeRefDocNode(docId);
@@ -147,7 +147,7 @@ export class KVDocumentStore extends BaseDocumentStore {
async deleteRefDoc(
refDocId: string,
raiseError: boolean = true
raiseError: boolean = true,
): Promise<void> {
let refDocInfo = await this.getRefDocInfo(refDocId);
if (_.isNil(refDocInfo)) {
@@ -158,7 +158,7 @@ export class KVDocumentStore extends BaseDocumentStore {
}
}
for (let docId of refDocInfo.docIds) {
for (let docId of refDocInfo.nodeIds) {
await this.deleteDocument(docId, false, false);
}
+8 -8
View File
@@ -1,14 +1,14 @@
import { BaseNode } from "../../Node";
import { GenericFileSystem } from "../FileSystem";
import {
DEFAULT_PERSIST_DIR,
DEFAULT_DOC_STORE_PERSIST_FILENAME,
DEFAULT_PERSIST_DIR,
} from "../constants";
import { GenericFileSystem } from "../FileSystem";
const defaultPersistPath = `${DEFAULT_PERSIST_DIR}/${DEFAULT_DOC_STORE_PERSIST_FILENAME}`;
export interface RefDocInfo {
docIds: string[];
nodeIds: string[];
extraInfo: Record<string, any>;
}
@@ -16,7 +16,7 @@ export abstract class BaseDocumentStore {
// Save/load
persist(
persistPath: string = defaultPersistPath,
fs?: GenericFileSystem
fs?: GenericFileSystem,
): void {
// Persist the docstore to a file.
}
@@ -24,14 +24,14 @@ export abstract class BaseDocumentStore {
// Main interface
abstract docs(): Promise<Record<string, BaseNode>>;
abstract addDocuments(docs: BaseNode[], allowUpdate: boolean): void;
abstract addDocuments(docs: BaseNode[], allowUpdate: boolean): Promise<void>;
abstract getDocument(
docId: string,
raiseError: boolean
raiseError: boolean,
): Promise<BaseNode | undefined>;
abstract deleteDocument(docId: string, raiseError: boolean): void;
abstract deleteDocument(docId: string, raiseError: boolean): Promise<void>;
abstract documentExists(docId: string): Promise<boolean>;
@@ -50,7 +50,7 @@ export abstract class BaseDocumentStore {
// Nodes
getNodes(nodeIds: string[], raiseError: boolean = true): Promise<BaseNode[]> {
return Promise.all(
nodeIds.map((nodeId) => this.getNode(nodeId, raiseError))
nodeIds.map((nodeId) => this.getNode(nodeId, raiseError)),
);
}
+7
View File
@@ -0,0 +1,7 @@
export * from "./constants";
export * from "./FileSystem";
export * from "./StorageContext";
export * from "./vectorStore/types";
export { SimpleDocumentStore } from "./docStore/SimpleDocumentStore";
export { SimpleIndexStore } from "./indexStore/SimpleIndexStore";
export { SimpleVectorStore } from "./vectorStore/SimpleVectorStore";
@@ -51,11 +51,11 @@ export class SimpleVectorStore implements VectorStore {
return null;
}
get(textId: string): number[] {
async get(textId: string): Promise<number[]> {
return this.data.embeddingDict[textId];
}
add(embeddingResults: NodeWithEmbedding[]): string[] {
async add(embeddingResults: NodeWithEmbedding[]): Promise<string[]> {
for (let result of embeddingResults) {
this.data.embeddingDict[result.node.id_] = result.embedding;
@@ -69,13 +69,13 @@ export class SimpleVectorStore implements VectorStore {
}
if (this.persistPath) {
this.persist(this.persistPath, this.fs);
await this.persist(this.persistPath, this.fs);
}
return embeddingResults.map((result) => result.node.id_);
}
delete(refDocId: string): void {
async delete(refDocId: string): Promise<void> {
let textIdsToDelete = Object.keys(this.data.textIdToRefDocId).filter(
(textId) => this.data.textIdToRefDocId[textId] === refDocId
);
@@ -83,9 +83,10 @@ export class SimpleVectorStore implements VectorStore {
delete this.data.embeddingDict[textId];
delete this.data.textIdToRefDocId[textId];
}
return Promise.resolve();
}
query(query: VectorStoreQuery): VectorStoreQueryResult {
async query(query: VectorStoreQuery): Promise<VectorStoreQueryResult> {
if (!_.isNil(query.filters)) {
throw new Error(
"Metadata filters not implemented for SimpleVectorStore yet."
@@ -137,10 +138,10 @@ export class SimpleVectorStore implements VectorStore {
throw new Error(`Invalid query mode: ${query.mode}`);
}
return {
return Promise.resolve({
similarities: topSimilarities,
ids: topIds,
};
});
}
async persist(
@@ -21,6 +21,7 @@ export enum VectorStoreQueryMode {
}
export interface ExactMatchFilter {
filterType: "ExactMatch";
key: string;
value: string | number;
}
@@ -61,8 +62,8 @@ export interface VectorStore {
storesText: boolean;
isEmbeddingQuery?: boolean;
client(): any;
add(embeddingResults: NodeWithEmbedding[]): string[];
delete(refDocId: string, deleteKwargs?: any): void;
query(query: VectorStoreQuery, kwargs?: any): VectorStoreQueryResult;
persist(persistPath: string, fs?: GenericFileSystem): void;
add(embeddingResults: NodeWithEmbedding[]): Promise<string[]>;
delete(refDocId: string, deleteKwargs?: any): Promise<void>;
query(query: VectorStoreQuery, kwargs?: any): Promise<VectorStoreQueryResult>;
persist(persistPath: string, fs?: GenericFileSystem): Promise<void>;
}

Some files were not shown because too many files have changed in this diff Show More