mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-10 15:53:42 -04:00
Compare commits
60 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 355910bade | |||
| 74ab63232b | |||
| 90418fa4ec | |||
| 8983e9b0f0 | |||
| cc4bac899e | |||
| 82f30f5637 | |||
| ade9d8fb8e | |||
| 402152f96b | |||
| a43d76d4a7 | |||
| 824c13cb85 | |||
| 0904d3dc5d | |||
| 978ef781e4 | |||
| 18b8915f22 | |||
| 9bbfc2414e | |||
| 9487aa1ed5 | |||
| fd74c52fe8 | |||
| 0d2bf51a2e | |||
| 551c0edadf | |||
| f80b06293b | |||
| b3fec86413 | |||
| ab886a34d7 | |||
| 1ec9da120e | |||
| 817178272d | |||
| 3316c6b41c | |||
| 9214b0669d | |||
| b3d659b9af | |||
| 05b0fca610 | |||
| 64b909f436 | |||
| a2e6299aaa | |||
| 1fbfcab55e | |||
| 7db567ea74 | |||
| 6354c16776 | |||
| eb4c3dd3c7 | |||
| 8a4330132c | |||
| f2d4f828d4 | |||
| fe8030a9ad | |||
| ec12633ae0 | |||
| 5e24733e41 | |||
| a13911435f | |||
| 857bb4596a | |||
| 1359de75b5 | |||
| f9d1a6e013 | |||
| b18e1228a8 | |||
| b501eb5a19 | |||
| bfab1d407b | |||
| 4ef334a70f | |||
| af60503115 | |||
| b3a7a9df2c | |||
| 6b90e4c1b3 | |||
| 108634b94f | |||
| 4bb92be1e4 | |||
| 7678d319f2 | |||
| aaff02bc4b | |||
| 34f5398f41 | |||
| c06d1e5b09 | |||
| a44ee19114 | |||
| b599813600 | |||
| 5dbbb7d4c1 | |||
| c8ea424c7a | |||
| 8de110e577 |
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
---
|
||||
|
||||
Added Meta strategy for Llama2
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
---
|
||||
|
||||
OpenAI v4 (final), Anthropic 0.6, Replicate 0.16.1
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
---
|
||||
|
||||
Fixed sentence splitter overlap logic
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"llamaindex": patch
|
||||
---
|
||||
|
||||
Breaking: Removed NodeWithEmbeddings (just use BaseNode)
|
||||
+4
-2
@@ -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
|
||||
|
||||
@@ -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 you’re 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 you’re interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
|
||||
|
||||
## Bugs? Questions?
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
---
|
||||
id: "Anthropic"
|
||||
title: "Class: Anthropic"
|
||||
sidebar_label: "Anthropic"
|
||||
sidebar_position: 0
|
||||
custom_edit_url: null
|
||||
---
|
||||
|
||||
Anthropic LLM implementation
|
||||
|
||||
## Implements
|
||||
|
||||
- [`LLM`](../interfaces/LLM.md)
|
||||
|
||||
## Constructors
|
||||
|
||||
### constructor
|
||||
|
||||
• **new Anthropic**(`init?`)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `init?` | `Partial`<[`Anthropic`](Anthropic.md)\> |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:449](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L449)
|
||||
|
||||
## Properties
|
||||
|
||||
### apiKey
|
||||
|
||||
• `Optional` **apiKey**: `string` = `undefined`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:442](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L442)
|
||||
|
||||
___
|
||||
|
||||
### callbackManager
|
||||
|
||||
• `Optional` **callbackManager**: [`CallbackManager`](CallbackManager.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:447](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L447)
|
||||
|
||||
___
|
||||
|
||||
### maxRetries
|
||||
|
||||
• **maxRetries**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:443](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L443)
|
||||
|
||||
___
|
||||
|
||||
### maxTokens
|
||||
|
||||
• `Optional` **maxTokens**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:439](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L439)
|
||||
|
||||
___
|
||||
|
||||
### model
|
||||
|
||||
• **model**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:436](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L436)
|
||||
|
||||
___
|
||||
|
||||
### session
|
||||
|
||||
• **session**: `AnthropicSession`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:445](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L445)
|
||||
|
||||
___
|
||||
|
||||
### temperature
|
||||
|
||||
• **temperature**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:437](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L437)
|
||||
|
||||
___
|
||||
|
||||
### timeout
|
||||
|
||||
• `Optional` **timeout**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[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
|
||||
|
||||
### chat
|
||||
|
||||
▸ **chat**(`messages`, `parentEvent?`): `Promise`<[`ChatResponse`](../interfaces/ChatResponse.md)\>
|
||||
|
||||
Get a chat response from the LLM
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
|
||||
| `parentEvent?` | [`Event`](../interfaces/Event.md) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`ChatResponse`](../interfaces/ChatResponse.md)\>
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[LLM](../interfaces/LLM.md).[chat](../interfaces/LLM.md#chat)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:484](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L484)
|
||||
|
||||
___
|
||||
|
||||
### complete
|
||||
|
||||
▸ **complete**(`prompt`, `parentEvent?`): `Promise`<[`ChatResponse`](../interfaces/ChatResponse.md)\>
|
||||
|
||||
Get a prompt completion from the LLM
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `prompt` | `string` | the prompt to complete |
|
||||
| `parentEvent?` | [`Event`](../interfaces/Event.md) | - |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`ChatResponse`](../interfaces/ChatResponse.md)\>
|
||||
|
||||
#### Implementation of
|
||||
|
||||
[LLM](../interfaces/LLM.md).[complete](../interfaces/LLM.md#complete)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:502](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L502)
|
||||
|
||||
___
|
||||
|
||||
### mapMessagesToPrompt
|
||||
|
||||
▸ **mapMessagesToPrompt**(`messages`): `string`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:469](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L469)
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -26,27 +26,37 @@ Llama2 LLM implementation
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:189](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L189)
|
||||
[llm/LLM.ts:266](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L266)
|
||||
|
||||
## Properties
|
||||
|
||||
### chatStrategy
|
||||
|
||||
• **chatStrategy**: [`DeuceChatStrategy`](../enums/DeuceChatStrategy.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:260](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L260)
|
||||
|
||||
___
|
||||
|
||||
### maxTokens
|
||||
|
||||
• `Optional` **maxTokens**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:186](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L186)
|
||||
[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:184](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L184)
|
||||
[llm/LLM.ts:259](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L259)
|
||||
|
||||
___
|
||||
|
||||
@@ -56,7 +66,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L187)
|
||||
[llm/LLM.ts:264](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L264)
|
||||
|
||||
___
|
||||
|
||||
@@ -66,7 +76,17 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:185](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L185)
|
||||
[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
|
||||
|
||||
@@ -93,7 +113,7 @@ Get a chat response from the LLM
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:209](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L209)
|
||||
[llm/LLM.ts:385](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L385)
|
||||
|
||||
___
|
||||
|
||||
@@ -120,13 +140,13 @@ Get a prompt completion from the LLM
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:234](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L234)
|
||||
[llm/LLM.ts:422](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L422)
|
||||
|
||||
___
|
||||
|
||||
### mapMessageType
|
||||
### mapMessageTypeA16Z
|
||||
|
||||
▸ **mapMessageType**(`messageType`): `string`
|
||||
▸ **mapMessageTypeA16Z**(`messageType`): `string`
|
||||
|
||||
#### Parameters
|
||||
|
||||
@@ -140,4 +160,82 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:196](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L196)
|
||||
[llm/LLM.ts:309](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L309)
|
||||
|
||||
___
|
||||
|
||||
### mapMessagesToPrompt
|
||||
|
||||
▸ **mapMessagesToPrompt**(`messages`): `Object`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `prompt` | `string` |
|
||||
| `systemPrompt` | `undefined` \| `string` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:281](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L281)
|
||||
|
||||
___
|
||||
|
||||
### mapMessagesToPromptA16Z
|
||||
|
||||
▸ **mapMessagesToPromptA16Z**(`messages`): `Object`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `prompt` | `string` |
|
||||
| `systemPrompt` | `undefined` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:295](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L295)
|
||||
|
||||
___
|
||||
|
||||
### mapMessagesToPromptMeta
|
||||
|
||||
▸ **mapMessagesToPromptMeta**(`messages`, `opts?`): `Object`
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `messages` | [`ChatMessage`](../interfaces/ChatMessage.md)[] |
|
||||
| `opts?` | `Object` |
|
||||
| `opts.replicate4Bit?` | `boolean` |
|
||||
| `opts.withBos?` | `boolean` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Object`
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `prompt` | `string` |
|
||||
| `systemPrompt` | `undefined` \| `string` |
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:322](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L322)
|
||||
|
||||
@@ -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:80](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L80)
|
||||
[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:73](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L73)
|
||||
[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:78](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L78)
|
||||
[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:74](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L74)
|
||||
[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:70](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L70)
|
||||
[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:68](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L68)
|
||||
[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:76](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L76)
|
||||
[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:69](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L69)
|
||||
[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:75](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L75)
|
||||
[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:116](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L116)
|
||||
[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:154](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L154)
|
||||
[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:99](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L99)
|
||||
[llm/LLM.ts:140](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L140)
|
||||
|
||||
@@ -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)
|
||||
@@ -31,7 +31,7 @@ SimpleNodeParser is the default NodeParser. It splits documents into TextNodes u
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:64](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L64)
|
||||
[NodeParser.ts:93](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L93)
|
||||
|
||||
## Properties
|
||||
|
||||
@@ -39,9 +39,11 @@ SimpleNodeParser is the default NodeParser. It splits documents into TextNodes u
|
||||
|
||||
• **includeMetadata**: `boolean`
|
||||
|
||||
Whether to include metadata in the nodes.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:61](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L61)
|
||||
[NodeParser.ts:87](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L87)
|
||||
|
||||
___
|
||||
|
||||
@@ -49,9 +51,11 @@ ___
|
||||
|
||||
• **includePrevNextRel**: `boolean`
|
||||
|
||||
Whether to include previous and next relationships in the nodes.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L62)
|
||||
[NodeParser.ts:91](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L91)
|
||||
|
||||
___
|
||||
|
||||
@@ -59,9 +63,11 @@ ___
|
||||
|
||||
• **textSplitter**: [`SentenceSplitter`](SentenceSplitter.md)
|
||||
|
||||
The text splitter to use.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:60](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L60)
|
||||
[NodeParser.ts:83](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L83)
|
||||
|
||||
## Methods
|
||||
|
||||
@@ -87,7 +93,7 @@ Generate Node objects from documents
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:95](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L95)
|
||||
[NodeParser.ts:124](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L124)
|
||||
|
||||
___
|
||||
|
||||
@@ -111,4 +117,4 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:82](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L82)
|
||||
[NodeParser.ts:111](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L111)
|
||||
|
||||
@@ -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` | [`BaseNode`](BaseNode.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:77](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L77)
|
||||
|
||||
___
|
||||
|
||||
### 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:146](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L146)
|
||||
|
||||
___
|
||||
|
||||
### 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:88](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L88)
|
||||
|
||||
___
|
||||
|
||||
### toDict
|
||||
|
||||
▸ **toDict**(): `SimpleVectorStoreData`
|
||||
|
||||
#### Returns
|
||||
|
||||
`SimpleVectorStoreData`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/SimpleVectorStore.ts:196](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L196)
|
||||
|
||||
___
|
||||
|
||||
### fromDict
|
||||
|
||||
▸ `Static` **fromDict**(`saveDict`): [`SimpleVectorStore`](SimpleVectorStore.md)
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `saveDict` | `SimpleVectorStoreData` |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`SimpleVectorStore`](SimpleVectorStore.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/SimpleVectorStore.ts:189](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L189)
|
||||
|
||||
___
|
||||
|
||||
### 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:159](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/SimpleVectorStore.ts#L159)
|
||||
@@ -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)
|
||||
|
||||
@@ -32,7 +32,7 @@ The VectorStoreIndex, an index that stores the nodes only according to their vec
|
||||
|
||||
#### Defined in
|
||||
|
||||
[indices/vectorStore/VectorStoreIndex.ts:36](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L36)
|
||||
[indices/vectorStore/VectorStoreIndex.ts:31](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L31)
|
||||
|
||||
## Properties
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -116,7 +116,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[indices/vectorStore/VectorStoreIndex.ts:34](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L34)
|
||||
[indices/vectorStore/VectorStoreIndex.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L29)
|
||||
|
||||
## Methods
|
||||
|
||||
@@ -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:216](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L216)
|
||||
|
||||
___
|
||||
|
||||
@@ -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:212](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L212)
|
||||
|
||||
___
|
||||
|
||||
### 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:252](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L252)
|
||||
|
||||
___
|
||||
|
||||
### 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:227](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L227)
|
||||
|
||||
___
|
||||
|
||||
### 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:143](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L143)
|
||||
|
||||
___
|
||||
|
||||
@@ -221,13 +297,13 @@ 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:187](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L187)
|
||||
|
||||
___
|
||||
|
||||
### getNodeEmbeddingResults
|
||||
|
||||
▸ `Static` **getNodeEmbeddingResults**(`nodes`, `serviceContext`, `logProgress?`): `Promise`<[`NodeWithEmbedding`](../interfaces/NodeWithEmbedding.md)[]\>
|
||||
▸ `Static` **getNodeEmbeddingResults**(`nodes`, `serviceContext`, `logProgress?`): `Promise`<[`BaseNode`](BaseNode.md)[]\>
|
||||
|
||||
Get the embeddings for nodes.
|
||||
|
||||
@@ -241,11 +317,11 @@ Get the embeddings for nodes.
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<[`NodeWithEmbedding`](../interfaces/NodeWithEmbedding.md)[]\>
|
||||
`Promise`<[`BaseNode`](BaseNode.md)[]\>
|
||||
|
||||
#### 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:114](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L114)
|
||||
|
||||
___
|
||||
|
||||
@@ -268,4 +344,4 @@ This is needed to handle persistence.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[indices/vectorStore/VectorStoreIndex.ts:47](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L47)
|
||||
[indices/vectorStore/VectorStoreIndex.ts:42](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/indices/vectorStore/VectorStoreIndex.ts#L42)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
---
|
||||
id: "DeuceChatStrategy"
|
||||
title: "Enumeration: DeuceChatStrategy"
|
||||
sidebar_label: "DeuceChatStrategy"
|
||||
sidebar_position: 0
|
||||
custom_edit_url: null
|
||||
---
|
||||
|
||||
## Enumeration Members
|
||||
|
||||
### A16Z
|
||||
|
||||
• **A16Z** = ``"a16z"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:246](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L246)
|
||||
|
||||
___
|
||||
|
||||
### META
|
||||
|
||||
• **META** = ``"meta"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:247](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L247)
|
||||
|
||||
___
|
||||
|
||||
### METAWBOS
|
||||
|
||||
• **METAWBOS** = ``"metawbos"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:11](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L11)
|
||||
|
||||
___
|
||||
|
||||
### HYBRID
|
||||
|
||||
• **HYBRID** = ``"hybrid"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:13](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L13)
|
||||
|
||||
___
|
||||
|
||||
### LINEAR\_REGRESSION
|
||||
|
||||
• **LINEAR\_REGRESSION** = ``"linear_regression"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:17](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L17)
|
||||
|
||||
___
|
||||
|
||||
### LOGISTIC\_REGRESSION
|
||||
|
||||
• **LOGISTIC\_REGRESSION** = ``"logistic_regression"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:16](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L16)
|
||||
|
||||
___
|
||||
|
||||
### MMR
|
||||
|
||||
• **MMR** = ``"mmr"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:19](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L19)
|
||||
|
||||
___
|
||||
|
||||
### SPARSE
|
||||
|
||||
• **SPARSE** = ``"sparse"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:12](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L12)
|
||||
|
||||
___
|
||||
|
||||
### SVM
|
||||
|
||||
• **SVM** = ``"svm"``
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:15](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L15)
|
||||
+27
-10
@@ -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 you’re 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 you’re 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)
|
||||
|
||||
@@ -14,7 +14,7 @@ custom_edit_url: null
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:15](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L15)
|
||||
[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:16](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L16)
|
||||
[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:22](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L22)
|
||||
[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:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L20)
|
||||
[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:21](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L21)
|
||||
[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:23](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L23)
|
||||
|
||||
___
|
||||
|
||||
### key
|
||||
|
||||
• **key**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:24](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L24)
|
||||
|
||||
___
|
||||
|
||||
### value
|
||||
|
||||
• **value**: `string` \| `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:25](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L25)
|
||||
@@ -10,6 +10,7 @@ Unified language model interface
|
||||
|
||||
## Implemented by
|
||||
|
||||
- [`Anthropic`](../classes/Anthropic.md)
|
||||
- [`LlamaDeuce`](../classes/LlamaDeuce.md)
|
||||
- [`OpenAI`](../classes/OpenAI.md)
|
||||
|
||||
@@ -34,7 +35,7 @@ Get a chat response from the LLM
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:36](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L36)
|
||||
[llm/LLM.ts:49](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L49)
|
||||
|
||||
___
|
||||
|
||||
@@ -57,4 +58,4 @@ Get a prompt completion 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: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:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L29)
|
||||
@@ -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:41](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L41)
|
||||
|
||||
___
|
||||
|
||||
### name
|
||||
|
||||
• **name**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L39)
|
||||
|
||||
___
|
||||
|
||||
### type
|
||||
|
||||
• **type**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:40](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L40)
|
||||
@@ -6,7 +6,7 @@ sidebar_position: 0
|
||||
custom_edit_url: null
|
||||
---
|
||||
|
||||
A node parser generates TextNodes from Documents
|
||||
A NodeParser generates TextNodes from Documents
|
||||
|
||||
## Implemented by
|
||||
|
||||
@@ -18,16 +18,20 @@ A node parser generates TextNodes from Documents
|
||||
|
||||
▸ **getNodesFromDocuments**(`documents`): [`TextNode`](../classes/TextNode.md)[]
|
||||
|
||||
Generates an array of nodes from an array of documents.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `documents` | [`Document`](../classes/Document.md)[] |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `documents` | [`Document`](../classes/Document.md)[] | The documents to generate nodes from. |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`TextNode`](../classes/TextNode.md)[]
|
||||
|
||||
An array of nodes.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L53)
|
||||
[NodeParser.ts:73](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L73)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
---
|
||||
id: "NodeWithEmbedding"
|
||||
title: "Interface: NodeWithEmbedding"
|
||||
sidebar_label: "NodeWithEmbedding"
|
||||
sidebar_position: 0
|
||||
custom_edit_url: null
|
||||
---
|
||||
|
||||
A node with an embedding
|
||||
|
||||
## Properties
|
||||
|
||||
### embedding
|
||||
|
||||
• **embedding**: `number`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[Node.ts:247](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L247)
|
||||
|
||||
___
|
||||
|
||||
### node
|
||||
|
||||
• **node**: [`BaseNode`](../classes/BaseNode.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[Node.ts:246](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/Node.ts#L246)
|
||||
@@ -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)
|
||||
|
||||
@@ -50,7 +50,7 @@ ___
|
||||
|
||||
### llm
|
||||
|
||||
• `Optional` **llm**: [`OpenAI`](../classes/OpenAI.md)
|
||||
• `Optional` **llm**: [`LLM`](LLM.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
|
||||
@@ -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:62](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L62)
|
||||
|
||||
___
|
||||
|
||||
### storesText
|
||||
|
||||
• **storesText**: `boolean`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:61](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L61)
|
||||
|
||||
## Methods
|
||||
|
||||
### add
|
||||
|
||||
▸ **add**(`embeddingResults`): `Promise`<`string`[]\>
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `embeddingResults` | [`BaseNode`](../classes/BaseNode.md)[] |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`string`[]\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:64](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L64)
|
||||
|
||||
___
|
||||
|
||||
### client
|
||||
|
||||
▸ **client**(): `any`
|
||||
|
||||
#### Returns
|
||||
|
||||
`any`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:63](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L63)
|
||||
|
||||
___
|
||||
|
||||
### delete
|
||||
|
||||
▸ **delete**(`refDocId`, `deleteKwargs?`): `Promise`<`void`\>
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `refDocId` | `string` |
|
||||
| `deleteKwargs?` | `any` |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:65](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L65)
|
||||
|
||||
___
|
||||
|
||||
### persist
|
||||
|
||||
▸ **persist**(`persistPath`, `fs?`): `Promise`<`void`\>
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `persistPath` | `string` |
|
||||
| `fs?` | [`GenericFileSystem`](GenericFileSystem.md) |
|
||||
|
||||
#### Returns
|
||||
|
||||
`Promise`<`void`\>
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:67](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L67)
|
||||
|
||||
___
|
||||
|
||||
### 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:66](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L66)
|
||||
@@ -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:46](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L46)
|
||||
|
||||
___
|
||||
|
||||
### metadataInfo
|
||||
|
||||
• **metadataInfo**: [`MetadataInfo`](MetadataInfo.md)[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L45)
|
||||
@@ -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:55](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L55)
|
||||
|
||||
___
|
||||
|
||||
### docIds
|
||||
|
||||
• `Optional` **docIds**: `string`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:52](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L52)
|
||||
|
||||
___
|
||||
|
||||
### filters
|
||||
|
||||
• `Optional` **filters**: [`MetadataFilters`](MetadataFilters.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:56](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L56)
|
||||
|
||||
___
|
||||
|
||||
### mmrThreshold
|
||||
|
||||
• `Optional` **mmrThreshold**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:57](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L57)
|
||||
|
||||
___
|
||||
|
||||
### mode
|
||||
|
||||
• **mode**: [`VectorStoreQueryMode`](../enums/VectorStoreQueryMode.md)
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:54](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L54)
|
||||
|
||||
___
|
||||
|
||||
### queryEmbedding
|
||||
|
||||
• `Optional` **queryEmbedding**: `number`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L50)
|
||||
|
||||
___
|
||||
|
||||
### queryStr
|
||||
|
||||
• `Optional` **queryStr**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:53](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L53)
|
||||
|
||||
___
|
||||
|
||||
### similarityTopK
|
||||
|
||||
• **similarityTopK**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:51](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L51)
|
||||
@@ -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:7](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L7)
|
||||
|
||||
___
|
||||
|
||||
### nodes
|
||||
|
||||
• `Optional` **nodes**: [`BaseNode`](../classes/BaseNode.md)[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:5](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L5)
|
||||
|
||||
___
|
||||
|
||||
### similarities
|
||||
|
||||
• **similarities**: `number`[]
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:6](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L6)
|
||||
@@ -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:34](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L34)
|
||||
|
||||
___
|
||||
|
||||
### query
|
||||
|
||||
• **query**: `string`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:33](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L33)
|
||||
|
||||
___
|
||||
|
||||
### topK
|
||||
|
||||
• `Optional` **topK**: `number`
|
||||
|
||||
#### Defined in
|
||||
|
||||
[storage/vectorStore/types.ts:35](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/storage/vectorStore/types.ts#L35)
|
||||
@@ -8,15 +8,18 @@ custom_edit_url: null
|
||||
|
||||
## Enumerations
|
||||
|
||||
- [DeuceChatStrategy](enums/DeuceChatStrategy.md)
|
||||
- [IndexStructType](enums/IndexStructType.md)
|
||||
- [ListRetrieverMode](enums/ListRetrieverMode.md)
|
||||
- [MetadataMode](enums/MetadataMode.md)
|
||||
- [NodeRelationship](enums/NodeRelationship.md)
|
||||
- [ObjectType](enums/ObjectType.md)
|
||||
- [SimilarityType](enums/SimilarityType.md)
|
||||
- [VectorStoreQueryMode](enums/VectorStoreQueryMode.md)
|
||||
|
||||
## Classes
|
||||
|
||||
- [Anthropic](classes/Anthropic.md)
|
||||
- [BaseEmbedding](classes/BaseEmbedding.md)
|
||||
- [BaseIndex](classes/BaseIndex.md)
|
||||
- [BaseNode](classes/BaseNode.md)
|
||||
@@ -45,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)
|
||||
@@ -68,10 +74,12 @@ 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)
|
||||
- [QueryEngineTool](interfaces/QueryEngineTool.md)
|
||||
- [RelatedNodeInfo](interfaces/RelatedNodeInfo.md)
|
||||
@@ -86,6 +94,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
|
||||
@@ -106,7 +119,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:39](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L39)
|
||||
|
||||
___
|
||||
|
||||
@@ -136,7 +149,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:7](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L7)
|
||||
[llm/LLM.ts:20](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L20)
|
||||
|
||||
___
|
||||
|
||||
@@ -146,7 +159,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)
|
||||
|
||||
___
|
||||
|
||||
@@ -208,16 +221,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:162](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L162)
|
||||
[llm/LLM.ts:205](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L205)
|
||||
|
||||
___
|
||||
|
||||
@@ -242,7 +264,7 @@ We currently support GPT-3.5 and GPT-4 models
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L58)
|
||||
[llm/LLM.ts:71](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L71)
|
||||
|
||||
___
|
||||
|
||||
@@ -298,7 +320,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
|
||||
|
||||
@@ -421,7 +443,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:45](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L45)
|
||||
[llm/LLM.ts:58](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L58)
|
||||
|
||||
___
|
||||
|
||||
@@ -440,7 +462,7 @@ ___
|
||||
|
||||
#### Defined in
|
||||
|
||||
[llm/LLM.ts:50](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L50)
|
||||
[llm/LLM.ts:63](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/llm/LLM.ts#L63)
|
||||
|
||||
___
|
||||
|
||||
@@ -686,22 +708,26 @@ ___
|
||||
|
||||
▸ **getNodesFromDocument**(`document`, `textSplitter`, `includeMetadata?`, `includePrevNextRel?`): [`TextNode`](classes/TextNode.md)[]
|
||||
|
||||
Generates an array of nodes from a document.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Default value |
|
||||
| :------ | :------ | :------ |
|
||||
| `document` | [`Document`](classes/Document.md) | `undefined` |
|
||||
| `textSplitter` | [`SentenceSplitter`](classes/SentenceSplitter.md) | `undefined` |
|
||||
| `includeMetadata` | `boolean` | `true` |
|
||||
| `includePrevNextRel` | `boolean` | `true` |
|
||||
| Name | Type | Default value | Description |
|
||||
| :------ | :------ | :------ | :------ |
|
||||
| `document` | [`Document`](classes/Document.md) | `undefined` | The document to generate nodes from. |
|
||||
| `textSplitter` | [`SentenceSplitter`](classes/SentenceSplitter.md) | `undefined` | The text splitter to use. |
|
||||
| `includeMetadata` | `boolean` | `true` | Whether to include metadata in the nodes. |
|
||||
| `includePrevNextRel` | `boolean` | `true` | Whether to include previous and next relationships in the nodes. |
|
||||
|
||||
#### Returns
|
||||
|
||||
[`TextNode`](classes/TextNode.md)[]
|
||||
|
||||
An array of nodes.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:15](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L15)
|
||||
[NodeParser.ts:29](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L29)
|
||||
|
||||
___
|
||||
|
||||
@@ -730,20 +756,24 @@ ___
|
||||
|
||||
▸ **getTextSplitsFromDocument**(`document`, `textSplitter`): `string`[]
|
||||
|
||||
Splits the text of a document into smaller parts.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `document` | [`Document`](classes/Document.md) |
|
||||
| `textSplitter` | [`SentenceSplitter`](classes/SentenceSplitter.md) |
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `document` | [`Document`](classes/Document.md) | The document to split. |
|
||||
| `textSplitter` | [`SentenceSplitter`](classes/SentenceSplitter.md) | The text splitter to use. |
|
||||
|
||||
#### Returns
|
||||
|
||||
`string`[]
|
||||
|
||||
An array of text splits.
|
||||
|
||||
#### Defined in
|
||||
|
||||
[NodeParser.ts:5](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L5)
|
||||
[NodeParser.ts:11](https://github.com/run-llama/LlamaIndexTS/blob/main/packages/core/src/NodeParser.ts#L11)
|
||||
|
||||
___
|
||||
|
||||
@@ -769,7 +799,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)
|
||||
|
||||
___
|
||||
|
||||
@@ -785,7 +815,7 @@ ___
|
||||
| `embeddings` | `number`[][] | `undefined` |
|
||||
| `similarityTopK?` | `number` | `undefined` |
|
||||
| `embeddingsIds?` | `any`[] | `undefined` |
|
||||
| `queryMode` | `VectorStoreQueryMode` | `VectorStoreQueryMode.SVM` |
|
||||
| `queryMode` | [`VectorStoreQueryMode`](enums/VectorStoreQueryMode.md) | `VectorStoreQueryMode.SVM` |
|
||||
|
||||
#### Returns
|
||||
|
||||
@@ -793,7 +823,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)
|
||||
|
||||
___
|
||||
|
||||
@@ -819,7 +849,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)
|
||||
|
||||
___
|
||||
|
||||
@@ -839,7 +869,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)
|
||||
|
||||
___
|
||||
|
||||
@@ -934,7 +984,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)
|
||||
|
||||
___
|
||||
|
||||
|
||||
Generated
-12839
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,52 @@
|
||||
# simple
|
||||
|
||||
## 0.0.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [824c13c]
|
||||
- Updated dependencies [18b8915]
|
||||
- Updated dependencies [ade9d8f]
|
||||
- Updated dependencies [824c13c]
|
||||
- llamaindex@0.0.18
|
||||
|
||||
## 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
|
||||
|
||||
- Updated dependencies [4ef334a]
|
||||
- Updated dependencies [0af7773]
|
||||
- Updated dependencies [bea4af9]
|
||||
- Updated dependencies [4ef334a]
|
||||
- llamaindex@0.0.14
|
||||
|
||||
## 0.0.11
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Anthropic } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const anthropic = new Anthropic();
|
||||
const result = await anthropic.chat([
|
||||
{ content: "You want to talk in rhymes.", role: "system" },
|
||||
{ content: "Hello, world!", role: "user" },
|
||||
{ content: "Hello!", role: "assistant" },
|
||||
{
|
||||
content:
|
||||
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
||||
role: "user",
|
||||
},
|
||||
]);
|
||||
console.log(result);
|
||||
})();
|
||||
@@ -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 });
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})();
|
||||
@@ -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,5 +1,5 @@
|
||||
{
|
||||
"version": "0.0.11",
|
||||
"version": "0.0.16",
|
||||
"private": true,
|
||||
"name": "simple",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from "fs/promises";
|
||||
import { PDFReader, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
import fs from "fs/promises";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import {
|
||||
Anthropic,
|
||||
Document,
|
||||
serviceContextFromDefaults,
|
||||
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"
|
||||
);
|
||||
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 with persistence
|
||||
const storageContext = await storageContextFromDefaults({
|
||||
persistDir: "./storage",
|
||||
});
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const serviceContext = serviceContextFromDefaults({ llm: new Anthropic() });
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
storageContext,
|
||||
serviceContext,
|
||||
});
|
||||
|
||||
// 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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import {
|
||||
Document,
|
||||
OpenAI,
|
||||
serviceContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
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, id_: path });
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const serviceContext = serviceContextFromDefaults({
|
||||
llm: new OpenAI({ model: "gpt-4" }),
|
||||
});
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
serviceContext,
|
||||
});
|
||||
|
||||
// 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);
|
||||
@@ -0,0 +1 @@
|
||||
package-lock.json
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Anthropic } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const anthropic = new Anthropic();
|
||||
const result = await anthropic.chat([
|
||||
{ content: "You want to talk in rhymes.", role: "system" },
|
||||
{ content: "Hello, world!", role: "user" },
|
||||
{ content: "Hello!", role: "assistant" },
|
||||
{
|
||||
content:
|
||||
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
||||
role: "user",
|
||||
},
|
||||
]);
|
||||
console.log(result);
|
||||
})();
|
||||
+10
-9
@@ -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 });
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})();
|
||||
@@ -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,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);
|
||||
})();
|
||||
|
||||
Generated
-228
@@ -1,228 +0,0 @@
|
||||
{
|
||||
"name": "simple",
|
||||
"version": "0.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "simple",
|
||||
"version": "0.0.3",
|
||||
"dependencies": {
|
||||
"llamaindex": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18"
|
||||
}
|
||||
},
|
||||
"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==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.8"
|
||||
}
|
||||
},
|
||||
"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/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "3.2.7",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
|
||||
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
|
||||
"dependencies": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.2",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||
}
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"debug": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"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.11",
|
||||
"resolved": "https://registry.npmjs.org/llamaindex/-/llamaindex-0.0.11.tgz",
|
||||
"integrity": "sha512-bdkN6bEgUGsNEy2mn7tIDYtT8+dC/ot9Nq6Wr3S5VK3cqdlJwS87rmqubLO5cqDVc7VBV6cdv1EeYccsvd3tzQ==",
|
||||
"dependencies": {
|
||||
"js-tiktoken": "^1.0.7",
|
||||
"lodash": "^4.17.21",
|
||||
"openai": "^3.3.0",
|
||||
"pdf-parse": "^1.1.1",
|
||||
"replicate": "^0.12.3",
|
||||
"tiktoken-node": "^0.0.6",
|
||||
"uuid": "^9.0.0",
|
||||
"wink-nlp": "^1.14.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="
|
||||
},
|
||||
"node_modules/node-ensure": {
|
||||
"version": "0.0.0",
|
||||
"resolved": "https://registry.npmjs.org/node-ensure/-/node-ensure-0.0.0.tgz",
|
||||
"integrity": "sha512-DRI60hzo2oKN1ma0ckc6nQWlHU69RH6xN0sjQTjMpChPfTYvKZdcQFfdYK2RWbJcKyUizSIy/l8OTGxMAM1QDw=="
|
||||
},
|
||||
"node_modules/openai": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/openai/-/openai-3.3.0.tgz",
|
||||
"integrity": "sha512-uqxI/Au+aPRnsaQRe8CojU0eCR7I0mBiKjD3sNMzY6DaC1ZVrc85u98mtJW6voDug8fgGN+DIZmTDxTthxb7dQ==",
|
||||
"dependencies": {
|
||||
"axios": "^0.26.0",
|
||||
"form-data": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/pdf-parse": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/pdf-parse/-/pdf-parse-1.1.1.tgz",
|
||||
"integrity": "sha512-v6ZJ/efsBpGrGGknjtq9J/oC8tZWq0KWL5vQrk2GlzLEQPUDB1ex+13Rmidl1neNN358Jn9EHZw5y07FFtaC7A==",
|
||||
"dependencies": {
|
||||
"debug": "^3.1.0",
|
||||
"node-ensure": "^0.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.8.1"
|
||||
}
|
||||
},
|
||||
"node_modules/replicate": {
|
||||
"version": "0.12.3",
|
||||
"resolved": "https://registry.npmjs.org/replicate/-/replicate-0.12.3.tgz",
|
||||
"integrity": "sha512-HVWKPoVhWVTONlWk+lUXmq9Vy2J8MxBJMtDBQq3dA5uq71ZzKTh0xvJfvzW4+VLBjhBeL7tkdua6hZJmKfzAPQ==",
|
||||
"engines": {
|
||||
"git": ">=2.11.0",
|
||||
"node": ">=16.6.0",
|
||||
"npm": ">=7.19.0",
|
||||
"yarn": ">=1.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tiktoken-node": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/tiktoken-node/-/tiktoken-node-0.0.6.tgz",
|
||||
"integrity": "sha512-MiprfzPhoKhCflzl0Jyds0VKibAgUGHfJLvBCAXPpum6Lru6ZoKQGsl8lJP0B94LPpby2B2WveOB2tZVfEZQOQ==",
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
},
|
||||
"node_modules/uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/wink-nlp": {
|
||||
"version": "1.14.3",
|
||||
"resolved": "https://registry.npmjs.org/wink-nlp/-/wink-nlp-1.14.3.tgz",
|
||||
"integrity": "sha512-lvY5iCs3T8I34F8WKS70+2P0U9dWLn3vdPf/Z+m2VK14N7OmqnPzmHfh3moHdusajoQ37Em39z0IZB9K4x/96A=="
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from "fs/promises";
|
||||
import { PDFReader, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -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
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import {
|
||||
Anthropic,
|
||||
Document,
|
||||
serviceContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
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, id_: path });
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const serviceContext = serviceContextFromDefaults({ llm: new Anthropic() });
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
serviceContext,
|
||||
});
|
||||
|
||||
// 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);
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
import {
|
||||
Document,
|
||||
OpenAI,
|
||||
serviceContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Load essay from abramov.txt in Node
|
||||
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, id_: path });
|
||||
|
||||
// Split text and create embeddings. Store them in a VectorStoreIndex
|
||||
const serviceContext = serviceContextFromDefaults({
|
||||
llm: new OpenAI({ model: "gpt-4" }),
|
||||
});
|
||||
const index = await VectorStoreIndex.fromDocuments([document], {
|
||||
serviceContext,
|
||||
});
|
||||
|
||||
// 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);
|
||||
+10
-4
@@ -7,7 +7,8 @@
|
||||
"lint": "turbo run lint",
|
||||
"prepare": "husky install",
|
||||
"test": "turbo run test",
|
||||
"publish-packages": "turbo run build lint test && changeset version && changeset publish"
|
||||
"publish-packages": "turbo run build lint test && changeset version && changeset publish",
|
||||
"publish-snapshot": "turbo run build lint test && changeset version --snapshot && changeset publish"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@turbo/gen": "^1.10.12",
|
||||
@@ -15,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.2",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,48 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.0.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 824c13c: Breaking: allow documents to be reimported with hash checking.
|
||||
- 18b8915: Update storage exports (thanks @TomPenguin)
|
||||
- ade9d8f: Bug fix: use session in OpenAI Embeddings (thanks @swk777)
|
||||
- 824c13c: Breaking: removed nodeId and docId. Just use id\_
|
||||
|
||||
## 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
|
||||
|
||||
- 4ef334a: JSDoc and Github Actions thanks to @kevinlu1248, @sweep-ai
|
||||
- 0af7773: Added Meta strategy for Llama2
|
||||
- bea4af9: Fixed sentence splitter overlap logic
|
||||
- 4ef334a: asQueryEngine bug fix from @ysak-y
|
||||
|
||||
## 0.0.13
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -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
@@ -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 you’re 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 you’re interested in hacking on it with us check out our [contributing guide](/CONTRIBUTING.md)
|
||||
|
||||
## Bugs? Questions?
|
||||
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.0.13",
|
||||
"version": "0.0.18",
|
||||
"dependencies": {
|
||||
"js-tiktoken": "^1.0.7",
|
||||
"@anthropic-ai/sdk": "^0.6.0",
|
||||
"lodash": "^4.17.21",
|
||||
"openai": "4.0.0-beta.6",
|
||||
"openai": "^4.0.0",
|
||||
"pdf-parse": "^1.1.1",
|
||||
"replicate": "^0.12.3",
|
||||
"replicate": "^0.16.1",
|
||||
"tiktoken-node": "^0.0.6",
|
||||
"uuid": "^9.0.0",
|
||||
"wink-nlp": "^1.14.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.196",
|
||||
"@types/node": "^18.17.1",
|
||||
"@types/lodash": "^4.14.197",
|
||||
"@types/node": "^18.17.5",
|
||||
"@types/pdf-parse": "^1.1.1",
|
||||
"@types/uuid": "^9.0.2",
|
||||
"node-stdlib-browser": "^1.2.0",
|
||||
"tsup": "^7.1.0"
|
||||
"tsup": "^7.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
|
||||
@@ -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,47 @@ 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 =
|
||||
init?.session ??
|
||||
getOpenAISession({
|
||||
apiKey: this.apiKey,
|
||||
maxRetries: this.maxRetries,
|
||||
timeout: this.timeout,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async getOpenAIEmbedding(input: string) {
|
||||
|
||||
+68
-18
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,11 +296,3 @@ export interface NodeWithScore {
|
||||
node: BaseNode;
|
||||
score: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A node with an embedding
|
||||
*/
|
||||
export interface NodeWithEmbedding {
|
||||
node: BaseNode;
|
||||
embedding: number[];
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@ import { Document, NodeRelationship, TextNode } from "./Node";
|
||||
import { SentenceSplitter } from "./TextSplitter";
|
||||
import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "./constants";
|
||||
|
||||
/**
|
||||
* Splits the text of a document into smaller parts.
|
||||
* @param document - The document to split.
|
||||
* @param textSplitter - The text splitter to use.
|
||||
* @returns An array of text splits.
|
||||
*/
|
||||
export function getTextSplitsFromDocument(
|
||||
document: Document,
|
||||
textSplitter: SentenceSplitter
|
||||
@@ -12,6 +18,14 @@ export function getTextSplitsFromDocument(
|
||||
return splits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of nodes from a document.
|
||||
* @param document - The document to generate nodes from.
|
||||
* @param textSplitter - The text splitter to use.
|
||||
* @param includeMetadata - Whether to include metadata in the nodes.
|
||||
* @param includePrevNextRel - Whether to include previous and next relationships in the nodes.
|
||||
* @returns An array of nodes.
|
||||
*/
|
||||
export function getNodesFromDocument(
|
||||
document: Document,
|
||||
textSplitter: SentenceSplitter,
|
||||
@@ -46,10 +60,16 @@ export function getNodesFromDocument(
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* A node parser generates TextNodes from Documents
|
||||
* A NodeParser generates TextNodes from Documents
|
||||
*/
|
||||
export interface NodeParser {
|
||||
/**
|
||||
* Generates an array of nodes from an array of documents.
|
||||
* @param documents - The documents to generate nodes from.
|
||||
* @returns An array of nodes.
|
||||
*/
|
||||
getNodesFromDocuments(documents: Document[]): TextNode[];
|
||||
}
|
||||
|
||||
@@ -57,8 +77,17 @@ export interface NodeParser {
|
||||
* SimpleNodeParser is the default NodeParser. It splits documents into TextNodes using a splitter, by default SentenceSplitter
|
||||
*/
|
||||
export class SimpleNodeParser implements NodeParser {
|
||||
/**
|
||||
* The text splitter to use.
|
||||
*/
|
||||
textSplitter: SentenceSplitter;
|
||||
/**
|
||||
* Whether to include metadata in the nodes.
|
||||
*/
|
||||
includeMetadata: boolean;
|
||||
/**
|
||||
* Whether to include previous and next relationships in the nodes.
|
||||
*/
|
||||
includePrevNextRel: boolean;
|
||||
|
||||
constructor(init?: {
|
||||
|
||||
@@ -17,7 +17,7 @@ export interface ServiceContext {
|
||||
}
|
||||
|
||||
export interface ServiceContextOptions {
|
||||
llm?: OpenAI;
|
||||
llm?: LLM;
|
||||
promptHelper?: PromptHelper;
|
||||
embedModel?: BaseEmbedding;
|
||||
nodeParser?: NodeParser;
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import { ChatCompletionChunk } from "openai/resources/chat";
|
||||
import { globalsHelper } from "../../GlobalsHelper";
|
||||
import { StreamCallbackResponse, Event } from "../CallbackManager";
|
||||
import { APIResponse } from "openai/core";
|
||||
import { Stream } from "openai/streaming";
|
||||
import { globalsHelper } from "../../GlobalsHelper";
|
||||
import { MessageType } from "../../llm/LLM";
|
||||
import { Event, StreamCallbackResponse } from "../CallbackManager";
|
||||
|
||||
/**
|
||||
* Handles the OpenAI streaming interface and pipes it to the callback function
|
||||
* @param response - The response from the OpenAI API.
|
||||
* @param onLLMStream - A callback function to handle the LLM stream.
|
||||
* @param parentEvent - An optional parent event.
|
||||
* @returns A promise that resolves to an object with a message and a role.
|
||||
*/
|
||||
export async function handleOpenAIStream({
|
||||
response,
|
||||
onLLMStream,
|
||||
parentEvent,
|
||||
}: {
|
||||
response: APIResponse<Stream<ChatCompletionChunk>>;
|
||||
response: Stream<ChatCompletionChunk>;
|
||||
onLLMStream: (data: StreamCallbackResponse) => void;
|
||||
parentEvent?: Event;
|
||||
}): Promise<{ message: string; role: MessageType }> {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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,12 @@
|
||||
import {
|
||||
Document,
|
||||
BaseNode,
|
||||
MetadataMode,
|
||||
NodeWithEmbedding,
|
||||
} from "../../Node";
|
||||
import { BaseNode, Document, MetadataMode } 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 +15,11 @@ import { VectorStore } from "../../storage/vectorStore/types";
|
||||
import {
|
||||
BaseIndex,
|
||||
IndexDict,
|
||||
IndexStructType,
|
||||
VectorIndexConstructorProps,
|
||||
VectorIndexOptions,
|
||||
} from "../BaseIndex";
|
||||
import { BaseRetriever } from "../../Retriever";
|
||||
import { ResponseSynthesizer } from "../../ResponseSynthesizer";
|
||||
import { BaseDocumentStore } from "../../storage/docStore/types";
|
||||
import { IndexStructType } from "../BaseIndex";
|
||||
import { VectorIndexRetriever } from "./VectorIndexRetriever";
|
||||
|
||||
/**
|
||||
* The VectorStoreIndex, an index that stores the nodes only according to their vector embedings.
|
||||
@@ -55,11 +50,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 +64,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,9 +114,9 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
static async getNodeEmbeddingResults(
|
||||
nodes: BaseNode[],
|
||||
serviceContext: ServiceContext,
|
||||
logProgress = false
|
||||
logProgress = false,
|
||||
) {
|
||||
const nodesWithEmbeddings: NodeWithEmbedding[] = [];
|
||||
const nodesWithEmbeddings: BaseNode[] = [];
|
||||
|
||||
for (let i = 0; i < nodes.length; ++i) {
|
||||
const node = nodes[i];
|
||||
@@ -133,9 +124,10 @@ 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 });
|
||||
node.embedding = embedding;
|
||||
nodesWithEmbeddings.push(node);
|
||||
}
|
||||
|
||||
return nodesWithEmbeddings;
|
||||
@@ -152,24 +144,33 @@ 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
|
||||
);
|
||||
await docStore.addDocuments(embeddingResults, true);
|
||||
}
|
||||
|
||||
const indexDict = new IndexDict();
|
||||
for (const { node } of embeddingResults) {
|
||||
for (const node of embeddingResults) {
|
||||
indexDict.addNode(node);
|
||||
}
|
||||
|
||||
@@ -188,7 +189,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
args: {
|
||||
storageContext?: StorageContext;
|
||||
serviceContext?: ServiceContext;
|
||||
} = {}
|
||||
} = {},
|
||||
): Promise<VectorStoreIndex> {
|
||||
let { storageContext, serviceContext } = args;
|
||||
storageContext = storageContext ?? (await storageContextFromDefaults({}));
|
||||
@@ -216,9 +217,58 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
retriever?: BaseRetriever;
|
||||
responseSynthesizer?: ResponseSynthesizer;
|
||||
}): BaseQueryEngine {
|
||||
let { retriever, responseSynthesizer } = options ?? {};
|
||||
const { retriever, responseSynthesizer } = options ?? {};
|
||||
return new RetrieverQueryEngine(
|
||||
retriever ?? this.asRetriever(),
|
||||
responseSynthesizer,
|
||||
);
|
||||
}
|
||||
|
||||
retriever = retriever ?? this.asRetriever();
|
||||
return new RetrieverQueryEngine(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+253
-62
@@ -1,7 +1,20 @@
|
||||
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 {
|
||||
AnthropicSession,
|
||||
ANTHROPIC_AI_PROMPT,
|
||||
ANTHROPIC_HUMAN_PROMPT,
|
||||
getAnthropicSession,
|
||||
} from "./anthropic";
|
||||
import {
|
||||
AzureOpenAIConfig,
|
||||
getAzureBaseUrl,
|
||||
getAzureConfigFromEnv,
|
||||
getAzureModel,
|
||||
shouldUseAzure,
|
||||
} from "./azure";
|
||||
import { getOpenAISession, OpenAISession } from "./openai";
|
||||
import { ReplicateSession } from "./replicate";
|
||||
|
||||
export type MessageType =
|
||||
@@ -67,6 +80,7 @@ export class OpenAI implements LLM {
|
||||
// Per completion OpenAI params
|
||||
model: keyof typeof ALL_AVAILABLE_OPENAI_MODELS;
|
||||
temperature: number;
|
||||
topP: number;
|
||||
maxTokens?: number;
|
||||
|
||||
// OpenAI session params
|
||||
@@ -77,27 +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":
|
||||
@@ -115,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,
|
||||
@@ -125,6 +166,7 @@ export class OpenAI implements LLM {
|
||||
role: this.mapMessageType(message.role),
|
||||
content: message.content,
|
||||
})),
|
||||
top_p: this.topP,
|
||||
};
|
||||
|
||||
if (this.callbackManager?.onLLMStream) {
|
||||
@@ -142,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 } };
|
||||
@@ -153,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",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -183,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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,38 +259,51 @@ export class LlamaDeuce implements LLM {
|
||||
model: keyof typeof ALL_AVAILABLE_LLAMADEUCE_MODELS;
|
||||
chatStrategy: DeuceChatStrategy;
|
||||
temperature: number;
|
||||
topP: number;
|
||||
maxTokens?: number;
|
||||
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;
|
||||
this.maxTokens = init?.maxTokens ?? undefined;
|
||||
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 ??
|
||||
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 {
|
||||
@@ -239,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.`;
|
||||
@@ -252,57 +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: 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",
|
||||
},
|
||||
};
|
||||
@@ -310,7 +421,87 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Anthropic LLM implementation
|
||||
*/
|
||||
|
||||
export class Anthropic implements LLM {
|
||||
// Per completion Anthropic params
|
||||
model: string;
|
||||
temperature: number;
|
||||
topP: number;
|
||||
maxTokens?: number;
|
||||
|
||||
// Anthropic session params
|
||||
apiKey?: string = undefined;
|
||||
maxRetries: number;
|
||||
timeout?: number;
|
||||
session: AnthropicSession;
|
||||
|
||||
callbackManager?: CallbackManager;
|
||||
|
||||
constructor(init?: Partial<Anthropic>) {
|
||||
this.model = init?.model ?? "claude-2";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
this.topP = init?.topP ?? 0.999; // Per Ben Mann
|
||||
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 ??
|
||||
getAnthropicSession({
|
||||
apiKey: this.apiKey,
|
||||
maxRetries: this.maxRetries,
|
||||
timeout: this.timeout,
|
||||
});
|
||||
|
||||
this.callbackManager = init?.callbackManager;
|
||||
}
|
||||
|
||||
mapMessagesToPrompt(messages: ChatMessage[]) {
|
||||
return (
|
||||
messages.reduce((acc, message) => {
|
||||
return (
|
||||
acc +
|
||||
`${
|
||||
message.role === "assistant"
|
||||
? ANTHROPIC_AI_PROMPT
|
||||
: ANTHROPIC_HUMAN_PROMPT
|
||||
} ${message.content} `
|
||||
);
|
||||
}, "") + ANTHROPIC_AI_PROMPT
|
||||
);
|
||||
}
|
||||
|
||||
async chat(
|
||||
messages: ChatMessage[],
|
||||
parentEvent?: Event | undefined,
|
||||
): Promise<ChatResponse> {
|
||||
const response = await this.session.anthropic.completions.create({
|
||||
model: this.model,
|
||||
prompt: this.mapMessagesToPrompt(messages),
|
||||
max_tokens_to_sample: this.maxTokens ?? 100000,
|
||||
temperature: this.temperature,
|
||||
top_p: this.topP,
|
||||
});
|
||||
|
||||
return {
|
||||
message: { content: response.completion.trimStart(), role: "assistant" },
|
||||
//^ We're trimming the start because Anthropic often starts with a space in the response
|
||||
// That space will be re-added when we generate the next prompt.
|
||||
};
|
||||
}
|
||||
async complete(
|
||||
prompt: string,
|
||||
parentEvent?: Event | undefined,
|
||||
): Promise<CompletionResponse> {
|
||||
return this.chat([{ content: prompt, role: "user" }], parentEvent);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import Anthropic, {
|
||||
ClientOptions,
|
||||
AI_PROMPT,
|
||||
HUMAN_PROMPT,
|
||||
} from "@anthropic-ai/sdk";
|
||||
import _ from "lodash";
|
||||
|
||||
export class AnthropicSession {
|
||||
anthropic: Anthropic;
|
||||
|
||||
constructor(options: ClientOptions = {}) {
|
||||
if (!options.apiKey) {
|
||||
if (typeof process !== undefined) {
|
||||
options.apiKey = process.env.ANTHROPIC_API_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
if (!options.apiKey) {
|
||||
throw new Error("Set Anthropic Key in ANTHROPIC_API_KEY env variable"); // Overriding Anthropic package's error message
|
||||
}
|
||||
|
||||
this.anthropic = new Anthropic(options);
|
||||
}
|
||||
}
|
||||
|
||||
// I'm not 100% sure this is necessary vs. just starting a new session
|
||||
// every time we make a call. They say they try to reuse connections
|
||||
// so in theory this is more efficient, but we should test it in the future.
|
||||
let defaultAnthropicSession: {
|
||||
session: AnthropicSession;
|
||||
options: ClientOptions;
|
||||
}[] = [];
|
||||
|
||||
/**
|
||||
* Get a session for the Anthropic API. If one already exists with the same options,
|
||||
* it will be returned. Otherwise, a new session will be created.
|
||||
* @param options
|
||||
* @returns
|
||||
*/
|
||||
export function getAnthropicSession(options: ClientOptions = {}) {
|
||||
let session = defaultAnthropicSession.find((session) => {
|
||||
return _.isEqual(session.options, options);
|
||||
})?.session;
|
||||
|
||||
if (!session) {
|
||||
session = new AnthropicSession(options);
|
||||
defaultAnthropicSession.push({ session, options });
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
export const ANTHROPIC_HUMAN_PROMPT = HUMAN_PROMPT;
|
||||
export const ANTHROPIC_AI_PROMPT = AI_PROMPT;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user