mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-02 20:13:52 -04:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d751af3ba1 | |||
| 6e0bf26566 |
@@ -150,7 +150,7 @@ jobs:
|
||||
done
|
||||
- name: Pack provider packages
|
||||
run: |
|
||||
for dir in packages/providers/* packages/providers/storage/*; do
|
||||
for dir in packages/providers/*; do
|
||||
if [ -d "$dir" ] && [ -f "$dir/package.json" ]; then
|
||||
echo "Packing $dir"
|
||||
pnpm pack --pack-destination ${{ runner.temp }} -C $dir
|
||||
|
||||
@@ -76,7 +76,7 @@ If you need any of those classes, you have to import them instead directly thoug
|
||||
Here's an example for importing the `PineconeVectorStore` class:
|
||||
|
||||
```typescript
|
||||
import { PineconeVectorStore } from "llamaindex/vector-store/PineconeVectorStore";
|
||||
import { PineconeVectorStore } from "llamaindex/storage/vectorStore/PineconeVectorStore";
|
||||
```
|
||||
|
||||
As the `PDFReader` is not working with the Edge runtime, here's how to use the `SimpleDirectoryReader` with the `LlamaParseReader` to load PDFs:
|
||||
|
||||
@@ -1,38 +1,5 @@
|
||||
# @llamaindex/doc
|
||||
|
||||
## 0.0.36
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- f02621e: Fix internal links between chapters
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [d6c270e]
|
||||
- Updated dependencies [1892e1c]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
- @llamaindex/core@0.4.21
|
||||
- @llamaindex/cloud@2.0.22
|
||||
- @llamaindex/openai@0.1.46
|
||||
- @llamaindex/node-parser@0.0.22
|
||||
- @llamaindex/readers@1.0.23
|
||||
|
||||
## 0.0.35
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5dec9f9]
|
||||
- Updated dependencies [fd9c829]
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- @llamaindex/cloud@2.0.21
|
||||
- llamaindex@0.8.31
|
||||
- @llamaindex/core@0.4.20
|
||||
- @llamaindex/node-parser@0.0.21
|
||||
- @llamaindex/openai@0.1.45
|
||||
- @llamaindex/readers@1.0.22
|
||||
|
||||
## 0.0.34
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/doc",
|
||||
"version": "0.0.36",
|
||||
"version": "0.0.34",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "pnpm run build:docs && next build",
|
||||
|
||||
@@ -20,7 +20,7 @@ npm install llamaindex
|
||||
|
||||
## Choose your model
|
||||
|
||||
By default we'll be using OpenAI with GPT-4, as it's a powerful model and easy to get started with. If you'd prefer to run a local model, see [using a local model](3_local_model).
|
||||
By default we'll be using OpenAI with GPT-4, as it's a powerful model and easy to get started with. If you'd prefer to run a local model, see [using a local model](local_model).
|
||||
|
||||
## Get an OpenAI API key
|
||||
|
||||
@@ -36,4 +36,4 @@ We'll use `dotenv` to pull the API key out of that .env file, so also run:
|
||||
npm install dotenv
|
||||
```
|
||||
|
||||
Now you're ready to [create your agent](2_create_agent).
|
||||
Now you're ready to [create your agent](create_agent).
|
||||
|
||||
@@ -177,5 +177,5 @@ The second piece of output is the response from the LLM itself, where the `messa
|
||||
Great! We've built an agent with tool use! Next you can:
|
||||
|
||||
- [See the full code](https://github.com/run-llama/ts-agents/blob/main/1_agent/agent.ts)
|
||||
- [Switch to a local LLM](3_local_model)
|
||||
- Move on to [add Retrieval-Augmented Generation to your agent](4_agentic_rag)
|
||||
- [Switch to a local LLM](local_model)
|
||||
- Move on to [add Retrieval-Augmented Generation to your agent](agentic_rag)
|
||||
|
||||
@@ -89,4 +89,4 @@ You can use a ReActAgent instead of an OpenAIAgent in any of the further example
|
||||
|
||||
### Next steps
|
||||
|
||||
Now you've got a local agent, you can [add Retrieval-Augmented Generation to your agent](4_agentic_rag).
|
||||
Now you've got a local agent, you can [add Retrieval-Augmented Generation to your agent](agentic_rag).
|
||||
|
||||
@@ -153,4 +153,4 @@ The `OpenAIContextAwareAgent` approach simplifies the setup by allowing you to d
|
||||
|
||||
On the other hand, using the `QueryEngineTool` offers more flexibility and power. This method allows for customization in how queries are constructed and executed, enabling you to query data from various storages and process them in different ways. However, this added flexibility comes with increased complexity and response time due to the separate tool call and queryEngine generating tool output by LLM that is then passed to the agent.
|
||||
|
||||
So now we have an agent that can index complicated documents and answer questions about them. Let's [combine our math agent and our RAG agent](5_rag_and_tools)!
|
||||
So now we have an agent that can index complicated documents and answer questions about them. Let's [combine our math agent and our RAG agent](rag_and_tools)!
|
||||
|
||||
@@ -127,4 +127,4 @@ In the final tool call, it used the `sumNumbers` function to add the two budgets
|
||||
}
|
||||
```
|
||||
|
||||
Great! Now let's improve accuracy by improving our parsing with [LlamaParse](6_llamaparse).
|
||||
Great! Now let's improve accuracy by improving our parsing with [LlamaParse](llamaparse).
|
||||
|
||||
@@ -17,4 +17,4 @@ const documents = await reader.loadData("../data/sf_budget_2023_2024.pdf");
|
||||
|
||||
Now you will be able to ask more complicated questions of the same PDF and get better results. You can find this code [in our repo](https://github.com/run-llama/ts-agents/blob/main/4_llamaparse/agent.ts).
|
||||
|
||||
Next up, let's persist our embedded data so we don't have to re-parse every time by [using a vector store](7_qdrant).
|
||||
Next up, let's persist our embedded data so we don't have to re-parse every time by [using a vector store](qdrant).
|
||||
|
||||
@@ -65,13 +65,13 @@ Since parsing a PDF can be slow, especially a large one, using the pre-parsed ch
|
||||
|
||||
In this guide you've learned how to
|
||||
|
||||
- [Create an agent](2_create_agent)
|
||||
- [Create an agent](create_agent)
|
||||
- Use remote LLMs like GPT-4
|
||||
- [Use local LLMs like Mixtral](3_local_model)
|
||||
- [Create a RAG query engine](4_agentic_rag)
|
||||
- [Turn functions and query engines into agent tools](5_rag_and_tools)
|
||||
- [Use local LLMs like Mixtral](local_model)
|
||||
- [Create a RAG query engine](agentic_rag)
|
||||
- [Turn functions and query engines into agent tools](rag_and_tools)
|
||||
- Combine those tools
|
||||
- [Enhance your parsing with LlamaParse](6_llamaparse)
|
||||
- [Enhance your parsing with LlamaParse](llamaparse)
|
||||
- Persist your data in a vector store
|
||||
|
||||
The next steps are up to you! Try creating more complex functions and query engines, and set your agent loose on the world.
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
# @llamaindex/core-e2e
|
||||
|
||||
## 0.0.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 34faf48: chore: move vector stores to their own packages
|
||||
- 9456616: refactor: @llamaindex/postgres
|
||||
|
||||
## 0.0.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/cloudflare-worker-agent-test
|
||||
|
||||
## 0.0.128
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.0.127
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.0.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloudflare-worker-agent-test",
|
||||
"version": "0.0.128",
|
||||
"version": "0.0.126",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
# @llamaindex/llama-parse-browser-test
|
||||
|
||||
## 0.0.42
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d6c270e]
|
||||
- @llamaindex/cloud@2.0.22
|
||||
|
||||
## 0.0.41
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5dec9f9]
|
||||
- Updated dependencies [fd9c829]
|
||||
- @llamaindex/cloud@2.0.21
|
||||
|
||||
## 0.0.40
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/llama-parse-browser-test",
|
||||
"private": true,
|
||||
"version": "0.0.42",
|
||||
"version": "0.0.40",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.7.2",
|
||||
"vite": "^5.4.12",
|
||||
"vite": "^5.4.11",
|
||||
"vite-plugin-wasm": "^3.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/next-agent-test
|
||||
|
||||
## 0.1.128
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.1.127
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.1.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-agent-test",
|
||||
"version": "0.1.128",
|
||||
"version": "0.1.126",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# test-edge-runtime
|
||||
|
||||
## 0.1.127
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.1.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.1.125
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/nextjs-edge-runtime-test",
|
||||
"version": "0.1.127",
|
||||
"version": "0.1.125",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/next-node-runtime
|
||||
|
||||
## 0.0.109
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.0.108
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.0.107
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/next-node-runtime-test",
|
||||
"version": "0.0.109",
|
||||
"version": "0.0.107",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/waku-query-engine-test
|
||||
|
||||
## 0.0.128
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.0.127
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.0.126
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/waku-query-engine-test",
|
||||
"version": "0.0.128",
|
||||
"version": "0.0.126",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/e2e",
|
||||
"private": true,
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.7",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"e2e": "node --import tsx --import ./mock-register.js --test ./node/**/*.e2e.ts",
|
||||
|
||||
@@ -1,30 +1,5 @@
|
||||
# examples
|
||||
|
||||
## 0.0.23
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 8744796: Update the chromadb npm client to support the latest chromadb image (0.6.3)
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
- @llamaindex/core@0.4.21
|
||||
- @llamaindex/vercel@0.0.8
|
||||
- @llamaindex/readers@1.0.23
|
||||
|
||||
## 0.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
- @llamaindex/core@0.4.20
|
||||
- @llamaindex/vercel@0.0.7
|
||||
- @llamaindex/readers@1.0.22
|
||||
|
||||
## 0.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { OpenAI, OpenAIAgent } from "llamaindex";
|
||||
import { WikipediaTool } from "../wiki";
|
||||
import { OpenAI, OpenAIAgent, WikipediaTool } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
const llm = new OpenAI({ model: "gpt-4-turbo" });
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Anthropic, FunctionTool, Settings } from "llamaindex";
|
||||
import { Anthropic, FunctionTool, Settings, WikipediaTool } from "llamaindex";
|
||||
import { AnthropicAgent } from "llamaindex/agent/anthropic";
|
||||
import { WikipediaTool } from "../wiki";
|
||||
|
||||
Settings.callbackManager.on("llm-tool-call", (event) => {
|
||||
console.log("llm-tool-call", event.detail.toolCall);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
const collectionName = "movie_reviews";
|
||||
|
||||
async function main() {
|
||||
const sourceFile: string = "../data/movie_reviews.csv";
|
||||
const sourceFile: string = "./data/movie_reviews.csv";
|
||||
|
||||
try {
|
||||
console.log(`Loading data from ${sourceFile}`);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/examples",
|
||||
"private": true,
|
||||
"version": "0.0.23",
|
||||
"version": "0.0.21",
|
||||
"dependencies": {
|
||||
"@ai-sdk/openai": "^1.0.5",
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
@@ -9,9 +9,9 @@
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@datastax/astra-db-ts": "^1.4.1",
|
||||
"@llamaindex/core": "^0.4.21",
|
||||
"@llamaindex/readers": "^1.0.23",
|
||||
"@llamaindex/vercel": "^0.0.8",
|
||||
"@llamaindex/core": "^0.4.19",
|
||||
"@llamaindex/readers": "^1.0.21",
|
||||
"@llamaindex/vercel": "^0.0.6",
|
||||
"@llamaindex/workflow": "^0.0.8",
|
||||
"@notionhq/client": "^2.2.15",
|
||||
"@pinecone-database/pinecone": "^4.0.0",
|
||||
@@ -22,12 +22,10 @@
|
||||
"commander": "^12.1.0",
|
||||
"dotenv": "^16.4.5",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"llamaindex": "^0.8.32",
|
||||
"mongodb": "6.7.0",
|
||||
"llamaindex": "^0.8.28",
|
||||
"mongodb": "^6.7.0",
|
||||
"pathe": "^1.1.2",
|
||||
"postgres": "^3.4.4",
|
||||
"ajv": "^8.17.1",
|
||||
"wikipedia": "^2.1.2"
|
||||
"postgres": "^3.4.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.9.0",
|
||||
|
||||
@@ -37,7 +37,7 @@ Read and follow the instructions in the README.md file located one directory up
|
||||
|
||||
To import documents and save the embedding vectors to your database:
|
||||
|
||||
> `npx tsx vector-store/pg/load-docs.ts data`
|
||||
> `npx tsx pg-vector-store/load-docs.ts data`
|
||||
|
||||
where data is the directory containing your input files. Using the `data` directory in the example above will read all of the files in that directory using the LlamaIndexTS default readers for each file type.
|
||||
|
||||
@@ -45,23 +45,6 @@ where data is the directory containing your input files. Using the `data` direct
|
||||
|
||||
To query using the resulting vector store:
|
||||
|
||||
> `npx tsx vector-store/pg/query.ts`
|
||||
> `npx tsx pg-vector-store/query.ts`
|
||||
|
||||
The script will prompt for a question, then process and present the answer using the PGVectorStore data and your OpenAI API key. It will continue to prompt until you enter `q`, `quit` or `exit` as the next query.
|
||||
|
||||
## Supabase
|
||||
|
||||
You can try the supabase example by running:
|
||||
|
||||
> `npx tsx vector-store/pg/supabase.ts`
|
||||
|
||||
This will use the `POSTGRES_URL` environment variable to connect to your Supabase database.
|
||||
Get one from the Supabase project settings page. See more details here: https://supabase.com/docs/guides/database/connecting-to-postgres#direct-connection
|
||||
|
||||
## Vercel
|
||||
|
||||
You can try the vercel example by running:
|
||||
|
||||
> `npx tsx vector-store/pg/vercel.ts`
|
||||
|
||||
For more information on Vercel Postgres, see: https://vercel.com/docs/storage/vercel-postgres/sdk
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// load-docs.ts
|
||||
import {
|
||||
PGVectorStore,
|
||||
SimpleDirectoryReader,
|
||||
storageContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
|
||||
import fs from "node:fs/promises";
|
||||
|
||||
async function getSourceFilenames(sourceDir: string) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import dotenv from "dotenv";
|
||||
import { Document, VectorStoreQueryMode } from "llamaindex";
|
||||
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
|
||||
import { Document, PGVectorStore, VectorStoreQueryMode } from "llamaindex";
|
||||
import postgres from "postgres";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { VectorStoreIndex } from "llamaindex";
|
||||
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
|
||||
import { PGVectorStore, VectorStoreIndex } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import dotenv from "dotenv";
|
||||
import {
|
||||
SimpleDirectoryReader,
|
||||
storageContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
// Get direct connection string from Supabase and set it as POSTGRES_URL environment variable
|
||||
// https://supabase.com/docs/guides/database/connecting-to-postgres#direct-connection
|
||||
|
||||
const sourceDir = "../data";
|
||||
const connectionString = process.env.POSTGRES_URL;
|
||||
|
||||
const rdr = new SimpleDirectoryReader();
|
||||
const docs = await rdr.loadData({ directoryPath: sourceDir });
|
||||
const pgvs = new PGVectorStore({ clientConfig: { connectionString } });
|
||||
pgvs.setCollection(sourceDir);
|
||||
|
||||
const ctx = await storageContextFromDefaults({ vectorStore: pgvs });
|
||||
|
||||
const index = await VectorStoreIndex.fromDocuments(docs, {
|
||||
storageContext: ctx,
|
||||
});
|
||||
|
||||
const queryEngine = index.asQueryEngine();
|
||||
|
||||
const results = await queryEngine.query({
|
||||
query: "Information about the planet",
|
||||
});
|
||||
|
||||
console.log(results);
|
||||
@@ -1,8 +1,7 @@
|
||||
// https://vercel.com/docs/storage/vercel-postgres/sdk
|
||||
import { sql } from "@vercel/postgres";
|
||||
import dotenv from "dotenv";
|
||||
import { Document, VectorStoreQueryMode } from "llamaindex";
|
||||
import { PGVectorStore } from "llamaindex/vector-store/PGVectorStore";
|
||||
import { Document, PGVectorStore, VectorStoreQueryMode } from "llamaindex";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { openai } from "@ai-sdk/openai";
|
||||
import { VercelLLM } from "@llamaindex/vercel";
|
||||
import { LLMAgent } from "llamaindex";
|
||||
import { WikipediaTool } from "../wiki";
|
||||
import { LLMAgent, WikipediaTool } from "llamaindex";
|
||||
|
||||
async function main() {
|
||||
// Create an instance of VercelLLM with the OpenAI model
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/autotool
|
||||
|
||||
## 5.0.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 5.0.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 5.0.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
# @llamaindex/autotool-01-node-example
|
||||
|
||||
## 0.0.75
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
- @llamaindex/autotool@5.0.32
|
||||
|
||||
## 0.0.74
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
- @llamaindex/autotool@5.0.31
|
||||
|
||||
## 0.0.73
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -13,5 +13,5 @@
|
||||
"scripts": {
|
||||
"start": "node --import tsx --import @llamaindex/autotool/node ./src/index.ts"
|
||||
},
|
||||
"version": "0.0.75"
|
||||
"version": "0.0.73"
|
||||
}
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
# @llamaindex/autotool-02-next-example
|
||||
|
||||
## 0.1.119
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
- @llamaindex/autotool@5.0.32
|
||||
|
||||
## 0.1.118
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
- @llamaindex/autotool@5.0.31
|
||||
|
||||
## 0.1.117
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/autotool-02-next-example",
|
||||
"private": true,
|
||||
"version": "0.1.119",
|
||||
"version": "0.1.117",
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/autotool",
|
||||
"type": "module",
|
||||
"version": "5.0.32",
|
||||
"version": "5.0.30",
|
||||
"description": "auto transpile your JS function to LLM Agent compatible",
|
||||
"files": [
|
||||
"dist",
|
||||
@@ -70,7 +70,7 @@
|
||||
"@swc/types": "^0.1.12",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/node": "^22.9.0",
|
||||
"bunchee": "6.2.0",
|
||||
"bunchee": "6.0.3",
|
||||
"llamaindex": "workspace:*",
|
||||
"next": "15.0.3",
|
||||
"rollup": "^4.28.1",
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/cloud
|
||||
|
||||
## 2.0.22
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d6c270e: feat: support pass project and org id to llama parse reader
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- @llamaindex/core@0.4.21
|
||||
|
||||
## 2.0.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 5dec9f9: chore: bump sdk deps version
|
||||
- fd9c829: chore: bump llamacloud openapi
|
||||
- Updated dependencies [d211b7a]
|
||||
- @llamaindex/core@0.4.20
|
||||
|
||||
## 2.0.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -10,13 +10,7 @@ export default defineConfig({
|
||||
format: "prettier",
|
||||
lint: "eslint",
|
||||
},
|
||||
plugins: [
|
||||
"@hey-api/schemas",
|
||||
"@hey-api/sdk",
|
||||
{
|
||||
enums: "javascript",
|
||||
identifierCase: "preserve",
|
||||
name: "@hey-api/typescript",
|
||||
},
|
||||
],
|
||||
types: {
|
||||
enums: "javascript",
|
||||
},
|
||||
});
|
||||
|
||||
+190
-4694
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@llamaindex/cloud",
|
||||
"version": "2.0.22",
|
||||
"version": "2.0.20",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
@@ -50,11 +50,11 @@
|
||||
"directory": "packages/cloud"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hey-api/client-fetch": "^0.6.0",
|
||||
"@hey-api/openapi-ts": "^0.61.0",
|
||||
"@hey-api/client-fetch": "^0.4.4",
|
||||
"@hey-api/openapi-ts": "^0.56.0",
|
||||
"@llamaindex/core": "workspace:*",
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"bunchee": "6.2.0"
|
||||
"bunchee": "6.0.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@llamaindex/core": "workspace:*",
|
||||
|
||||
@@ -31,8 +31,6 @@ var process: any;
|
||||
* See https://github.com/run-llama/llama_parse
|
||||
*/
|
||||
export class LlamaParseReader extends FileReader {
|
||||
project_id?: string | undefined;
|
||||
organization_id?: string | undefined;
|
||||
// The API key for the LlamaParse API. Can be set as an environment variable: LLAMA_CLOUD_API_KEY
|
||||
apiKey: string;
|
||||
// The base URL of the Llama Cloud Platform.
|
||||
@@ -120,7 +118,6 @@ export class LlamaParseReader extends FileReader {
|
||||
structured_output?: boolean | undefined;
|
||||
structured_output_json_schema?: string | undefined;
|
||||
structured_output_json_schema_name?: string | undefined;
|
||||
extract_layout?: boolean | undefined;
|
||||
|
||||
// numWorkers is implemented in SimpleDirectoryReader
|
||||
stdout?: WriteStream | undefined;
|
||||
@@ -251,7 +248,6 @@ export class LlamaParseReader extends FileReader {
|
||||
structured_output_json_schema: this.structured_output_json_schema,
|
||||
structured_output_json_schema_name:
|
||||
this.structured_output_json_schema_name,
|
||||
extract_layout: this.extract_layout,
|
||||
} satisfies {
|
||||
[Key in keyof Body_upload_file_api_v1_parsing_upload_post]-?:
|
||||
| Body_upload_file_api_v1_parsing_upload_post[Key]
|
||||
@@ -261,10 +257,6 @@ export class LlamaParseReader extends FileReader {
|
||||
const response = await uploadFileApiV1ParsingUploadPost({
|
||||
client: this.#client,
|
||||
throwOnError: true,
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal: AbortSignal.timeout(this.maxTimeout * 1000),
|
||||
body,
|
||||
});
|
||||
@@ -290,10 +282,6 @@ export class LlamaParseReader extends FileReader {
|
||||
path: {
|
||||
job_id: jobId,
|
||||
},
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
const { data } = result;
|
||||
@@ -310,10 +298,6 @@ export class LlamaParseReader extends FileReader {
|
||||
path: {
|
||||
job_id: jobId,
|
||||
},
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
break;
|
||||
@@ -325,10 +309,6 @@ export class LlamaParseReader extends FileReader {
|
||||
path: {
|
||||
job_id: jobId,
|
||||
},
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
break;
|
||||
@@ -340,10 +320,6 @@ export class LlamaParseReader extends FileReader {
|
||||
path: {
|
||||
job_id: jobId,
|
||||
},
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
break;
|
||||
@@ -533,10 +509,6 @@ export class LlamaParseReader extends FileReader {
|
||||
job_id: jobId,
|
||||
name: imageName,
|
||||
},
|
||||
query: {
|
||||
project_id: this.project_id ?? null,
|
||||
organization_id: this.organization_id ?? null,
|
||||
},
|
||||
});
|
||||
if (response.error) {
|
||||
throw new Error(`Failed to download image: ${response.error.detail}`);
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
# @llamaindex/community
|
||||
|
||||
## 0.0.79
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- @llamaindex/core@0.4.21
|
||||
|
||||
## 0.0.78
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- @llamaindex/core@0.4.20
|
||||
|
||||
## 0.0.77
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/community",
|
||||
"description": "Community package for LlamaIndexTS",
|
||||
"version": "0.0.79",
|
||||
"version": "0.0.77",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
@@ -43,7 +43,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.9.0",
|
||||
"bunchee": "6.2.0"
|
||||
"bunchee": "6.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-bedrock-agent-runtime": "^3.706.0",
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
# @llamaindex/core
|
||||
|
||||
## 0.4.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 9456616: refactor: @llamaindex/postgres
|
||||
- 1931bbc: refactor: @llamaindex/azure
|
||||
|
||||
## 0.4.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d211b7a: added support for tool calls with results in message history for athropic agent
|
||||
|
||||
## 0.4.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/core",
|
||||
"type": "module",
|
||||
"version": "0.4.21",
|
||||
"version": "0.4.19",
|
||||
"description": "LlamaIndex Core Module",
|
||||
"exports": {
|
||||
"./agent": {
|
||||
@@ -391,7 +391,7 @@
|
||||
"devDependencies": {
|
||||
"@edge-runtime/vm": "^4.0.4",
|
||||
"ajv": "^8.17.1",
|
||||
"bunchee": "6.2.0",
|
||||
"bunchee": "6.0.3",
|
||||
"happy-dom": "^15.11.6",
|
||||
"natural": "^8.0.1"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import type { Tokenizer } from "@llamaindex/env/tokenizers";
|
||||
import type { BaseEmbedding } from "../embeddings";
|
||||
import type { LLM } from "../llms";
|
||||
import {
|
||||
type CallbackManager,
|
||||
@@ -13,11 +12,6 @@ import {
|
||||
setChunkSize,
|
||||
withChunkSize,
|
||||
} from "./settings/chunk-size";
|
||||
import {
|
||||
getEmbeddedModel,
|
||||
setEmbeddedModel,
|
||||
withEmbeddedModel,
|
||||
} from "./settings/embedModel";
|
||||
import { getLLM, setLLM, withLLM } from "./settings/llm";
|
||||
import {
|
||||
getTokenizer,
|
||||
@@ -35,15 +29,6 @@ export const Settings = {
|
||||
withLLM<Result>(llm: LLM, fn: () => Result): Result {
|
||||
return withLLM(llm, fn);
|
||||
},
|
||||
get embedModel() {
|
||||
return getEmbeddedModel();
|
||||
},
|
||||
set embedModel(embedModel) {
|
||||
setEmbeddedModel(embedModel);
|
||||
},
|
||||
withEmbedModel<Result>(embedModel: BaseEmbedding, fn: () => Result): Result {
|
||||
return withEmbeddedModel(embedModel, fn);
|
||||
},
|
||||
get tokenizer() {
|
||||
return getTokenizer();
|
||||
},
|
||||
|
||||
@@ -1,167 +0,0 @@
|
||||
import { path } from "@llamaindex/env";
|
||||
import {
|
||||
DEFAULT_DOC_STORE_PERSIST_FILENAME,
|
||||
DEFAULT_PERSIST_DIR,
|
||||
} from "../../global";
|
||||
import type { StoredValue } from "../../schema";
|
||||
import { BaseNode, Document, ObjectType, TextNode } from "../../schema";
|
||||
|
||||
const TYPE_KEY = "__type__";
|
||||
const DATA_KEY = "__data__";
|
||||
|
||||
export interface Serializer<T> {
|
||||
toPersistence(data: Record<string, unknown>): T;
|
||||
|
||||
fromPersistence(data: T): Record<string, unknown>;
|
||||
}
|
||||
|
||||
export const jsonSerializer: Serializer<string> = {
|
||||
toPersistence(data) {
|
||||
return JSON.stringify(data);
|
||||
},
|
||||
fromPersistence(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
};
|
||||
|
||||
export const noneSerializer: Serializer<Record<string, unknown>> = {
|
||||
toPersistence(data) {
|
||||
return data;
|
||||
},
|
||||
fromPersistence(data) {
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
||||
type DocJson<Data> = {
|
||||
[TYPE_KEY]: ObjectType;
|
||||
[DATA_KEY]: Data;
|
||||
};
|
||||
|
||||
export function isValidDocJson(
|
||||
docJson: StoredValue | null | undefined,
|
||||
): docJson is DocJson<unknown> {
|
||||
return (
|
||||
typeof docJson === "object" &&
|
||||
docJson !== null &&
|
||||
docJson[TYPE_KEY] !== undefined &&
|
||||
docJson[DATA_KEY] !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
export function docToJson(
|
||||
doc: BaseNode,
|
||||
serializer: Serializer<unknown>,
|
||||
): DocJson<unknown> {
|
||||
return {
|
||||
[DATA_KEY]: serializer.toPersistence(doc.toJSON()),
|
||||
[TYPE_KEY]: doc.type,
|
||||
};
|
||||
}
|
||||
|
||||
export function jsonToDoc<Data>(
|
||||
docDict: DocJson<Data>,
|
||||
serializer: Serializer<Data>,
|
||||
): BaseNode {
|
||||
const docType = docDict[TYPE_KEY];
|
||||
// fixme: zod type check this
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const dataDict: any = serializer.fromPersistence(docDict[DATA_KEY]);
|
||||
let doc: BaseNode;
|
||||
|
||||
if (docType === ObjectType.DOCUMENT) {
|
||||
doc = new Document({
|
||||
text: dataDict.text,
|
||||
id_: dataDict.id_,
|
||||
embedding: dataDict.embedding,
|
||||
hash: dataDict.hash,
|
||||
metadata: dataDict.metadata,
|
||||
});
|
||||
} else if (docType === ObjectType.TEXT) {
|
||||
doc = new TextNode({
|
||||
text: dataDict.text,
|
||||
id_: dataDict.id_,
|
||||
hash: dataDict.hash,
|
||||
metadata: dataDict.metadata,
|
||||
relationships: dataDict.relationships,
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Unknown doc type: ${docType}`);
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
const DEFAULT_PERSIST_PATH = path.join(
|
||||
DEFAULT_PERSIST_DIR,
|
||||
DEFAULT_DOC_STORE_PERSIST_FILENAME,
|
||||
);
|
||||
|
||||
export interface RefDocInfo {
|
||||
nodeIds: string[];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
extraInfo: Record<string, any>;
|
||||
}
|
||||
|
||||
export abstract class BaseDocumentStore {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serializer: Serializer<any> = jsonSerializer;
|
||||
|
||||
// Save/load
|
||||
persist(persistPath: string = DEFAULT_PERSIST_PATH): void {
|
||||
// Persist the docstore to a file.
|
||||
}
|
||||
|
||||
// Main interface
|
||||
abstract docs(): Promise<Record<string, BaseNode>>;
|
||||
|
||||
abstract addDocuments(docs: BaseNode[], allowUpdate: boolean): Promise<void>;
|
||||
|
||||
abstract getDocument(
|
||||
docId: string,
|
||||
raiseError: boolean,
|
||||
): Promise<BaseNode | undefined>;
|
||||
|
||||
abstract deleteDocument(docId: string, raiseError: boolean): Promise<void>;
|
||||
|
||||
abstract documentExists(docId: string): Promise<boolean>;
|
||||
|
||||
// Hash
|
||||
abstract setDocumentHash(docId: string, docHash: string): Promise<void>;
|
||||
|
||||
abstract getDocumentHash(docId: string): Promise<string | undefined>;
|
||||
|
||||
abstract getAllDocumentHashes(): Promise<Record<string, string>>;
|
||||
|
||||
// Ref Docs
|
||||
abstract getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined>;
|
||||
|
||||
abstract getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined>;
|
||||
|
||||
abstract deleteRefDoc(refDocId: string, raiseError: boolean): Promise<void>;
|
||||
|
||||
// Nodes
|
||||
getNodes(nodeIds: string[], raiseError: boolean = true): Promise<BaseNode[]> {
|
||||
return Promise.all(
|
||||
nodeIds.map((nodeId) => this.getNode(nodeId, raiseError)),
|
||||
);
|
||||
}
|
||||
|
||||
async getNode(nodeId: string, raiseError: boolean = true): Promise<BaseNode> {
|
||||
const doc = await this.getDocument(nodeId, raiseError);
|
||||
if (!(doc instanceof BaseNode)) {
|
||||
throw new Error(`Document ${nodeId} is not a Node.`);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
async getNodeDict(nodeIdDict: {
|
||||
[index: number]: string;
|
||||
}): Promise<Record<number, BaseNode>> {
|
||||
const result: Record<number, BaseNode> = {};
|
||||
for (const index in nodeIdDict) {
|
||||
result[index] = await this.getNode(nodeIdDict[index]!);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,167 @@
|
||||
export * from "./base-document-store";
|
||||
export * from "./kv-document-store";
|
||||
import { path } from "@llamaindex/env";
|
||||
import {
|
||||
DEFAULT_DOC_STORE_PERSIST_FILENAME,
|
||||
DEFAULT_PERSIST_DIR,
|
||||
} from "../../global";
|
||||
import type { StoredValue } from "../../schema";
|
||||
import { BaseNode, Document, ObjectType, TextNode } from "../../schema";
|
||||
|
||||
const TYPE_KEY = "__type__";
|
||||
const DATA_KEY = "__data__";
|
||||
|
||||
export interface Serializer<T> {
|
||||
toPersistence(data: Record<string, unknown>): T;
|
||||
|
||||
fromPersistence(data: T): Record<string, unknown>;
|
||||
}
|
||||
|
||||
export const jsonSerializer: Serializer<string> = {
|
||||
toPersistence(data) {
|
||||
return JSON.stringify(data);
|
||||
},
|
||||
fromPersistence(data) {
|
||||
return JSON.parse(data);
|
||||
},
|
||||
};
|
||||
|
||||
export const noneSerializer: Serializer<Record<string, unknown>> = {
|
||||
toPersistence(data) {
|
||||
return data;
|
||||
},
|
||||
fromPersistence(data) {
|
||||
return data;
|
||||
},
|
||||
};
|
||||
|
||||
type DocJson<Data> = {
|
||||
[TYPE_KEY]: ObjectType;
|
||||
[DATA_KEY]: Data;
|
||||
};
|
||||
|
||||
export function isValidDocJson(
|
||||
docJson: StoredValue | null | undefined,
|
||||
): docJson is DocJson<unknown> {
|
||||
return (
|
||||
typeof docJson === "object" &&
|
||||
docJson !== null &&
|
||||
docJson[TYPE_KEY] !== undefined &&
|
||||
docJson[DATA_KEY] !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
export function docToJson(
|
||||
doc: BaseNode,
|
||||
serializer: Serializer<unknown>,
|
||||
): DocJson<unknown> {
|
||||
return {
|
||||
[DATA_KEY]: serializer.toPersistence(doc.toJSON()),
|
||||
[TYPE_KEY]: doc.type,
|
||||
};
|
||||
}
|
||||
|
||||
export function jsonToDoc<Data>(
|
||||
docDict: DocJson<Data>,
|
||||
serializer: Serializer<Data>,
|
||||
): BaseNode {
|
||||
const docType = docDict[TYPE_KEY];
|
||||
// fixme: zod type check this
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const dataDict: any = serializer.fromPersistence(docDict[DATA_KEY]);
|
||||
let doc: BaseNode;
|
||||
|
||||
if (docType === ObjectType.DOCUMENT) {
|
||||
doc = new Document({
|
||||
text: dataDict.text,
|
||||
id_: dataDict.id_,
|
||||
embedding: dataDict.embedding,
|
||||
hash: dataDict.hash,
|
||||
metadata: dataDict.metadata,
|
||||
});
|
||||
} else if (docType === ObjectType.TEXT) {
|
||||
doc = new TextNode({
|
||||
text: dataDict.text,
|
||||
id_: dataDict.id_,
|
||||
hash: dataDict.hash,
|
||||
metadata: dataDict.metadata,
|
||||
relationships: dataDict.relationships,
|
||||
});
|
||||
} else {
|
||||
throw new Error(`Unknown doc type: ${docType}`);
|
||||
}
|
||||
|
||||
return doc;
|
||||
}
|
||||
|
||||
const DEFAULT_PERSIST_PATH = path.join(
|
||||
DEFAULT_PERSIST_DIR,
|
||||
DEFAULT_DOC_STORE_PERSIST_FILENAME,
|
||||
);
|
||||
|
||||
export interface RefDocInfo {
|
||||
nodeIds: string[];
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
extraInfo: Record<string, any>;
|
||||
}
|
||||
|
||||
export abstract class BaseDocumentStore {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serializer: Serializer<any> = jsonSerializer;
|
||||
|
||||
// Save/load
|
||||
persist(persistPath: string = DEFAULT_PERSIST_PATH): void {
|
||||
// Persist the docstore to a file.
|
||||
}
|
||||
|
||||
// Main interface
|
||||
abstract docs(): Promise<Record<string, BaseNode>>;
|
||||
|
||||
abstract addDocuments(docs: BaseNode[], allowUpdate: boolean): Promise<void>;
|
||||
|
||||
abstract getDocument(
|
||||
docId: string,
|
||||
raiseError: boolean,
|
||||
): Promise<BaseNode | undefined>;
|
||||
|
||||
abstract deleteDocument(docId: string, raiseError: boolean): Promise<void>;
|
||||
|
||||
abstract documentExists(docId: string): Promise<boolean>;
|
||||
|
||||
// Hash
|
||||
abstract setDocumentHash(docId: string, docHash: string): Promise<void>;
|
||||
|
||||
abstract getDocumentHash(docId: string): Promise<string | undefined>;
|
||||
|
||||
abstract getAllDocumentHashes(): Promise<Record<string, string>>;
|
||||
|
||||
// Ref Docs
|
||||
abstract getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined>;
|
||||
|
||||
abstract getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined>;
|
||||
|
||||
abstract deleteRefDoc(refDocId: string, raiseError: boolean): Promise<void>;
|
||||
|
||||
// Nodes
|
||||
getNodes(nodeIds: string[], raiseError: boolean = true): Promise<BaseNode[]> {
|
||||
return Promise.all(
|
||||
nodeIds.map((nodeId) => this.getNode(nodeId, raiseError)),
|
||||
);
|
||||
}
|
||||
|
||||
async getNode(nodeId: string, raiseError: boolean = true): Promise<BaseNode> {
|
||||
const doc = await this.getDocument(nodeId, raiseError);
|
||||
if (!(doc instanceof BaseNode)) {
|
||||
throw new Error(`Document ${nodeId} is not a Node.`);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
async getNodeDict(nodeIdDict: {
|
||||
[index: number]: string;
|
||||
}): Promise<Record<number, BaseNode>> {
|
||||
const result: Record<number, BaseNode> = {};
|
||||
for (const index in nodeIdDict) {
|
||||
result[index] = await this.getNode(nodeIdDict[index]!);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import type { BaseEmbedding } from "../embeddings/base.js";
|
||||
import { Settings } from "../global";
|
||||
import type { BaseNode, ModalityType } from "../schema/node.js";
|
||||
|
||||
/**
|
||||
* should compatible with npm:pg and npm:postgres
|
||||
*/
|
||||
@@ -16,134 +12,3 @@ export interface IsomorphicDB {
|
||||
close: () => Promise<void>;
|
||||
onCloseEvent: (listener: () => void) => void;
|
||||
}
|
||||
|
||||
export interface VectorStoreQueryResult {
|
||||
nodes?: BaseNode[];
|
||||
similarities: number[];
|
||||
ids: string[];
|
||||
}
|
||||
|
||||
export enum VectorStoreQueryMode {
|
||||
DEFAULT = "default",
|
||||
SPARSE = "sparse",
|
||||
HYBRID = "hybrid",
|
||||
// fit learners
|
||||
SVM = "svm",
|
||||
LOGISTIC_REGRESSION = "logistic_regression",
|
||||
LINEAR_REGRESSION = "linear_regression",
|
||||
// maximum marginal relevance
|
||||
MMR = "mmr",
|
||||
|
||||
// for Azure AI Search
|
||||
SEMANTIC_HYBRID = "semantic_hybrid",
|
||||
}
|
||||
|
||||
export enum FilterOperator {
|
||||
EQ = "==", // default operator (string, number)
|
||||
IN = "in", // In array (string or number)
|
||||
GT = ">", // greater than (number)
|
||||
LT = "<", // less than (number)
|
||||
NE = "!=", // not equal to (string, number)
|
||||
GTE = ">=", // greater than or equal to (number)
|
||||
LTE = "<=", // less than or equal to (number)
|
||||
NIN = "nin", // Not in array (string or number)
|
||||
ANY = "any", // Contains any (array of strings)
|
||||
ALL = "all", // Contains all (array of strings)
|
||||
TEXT_MATCH = "text_match", // full text match (allows you to search for a specific substring, token or phrase within the text field)
|
||||
CONTAINS = "contains", // metadata array contains value (string or number)
|
||||
IS_EMPTY = "is_empty", // the field is not exist or empty (null or empty array)
|
||||
}
|
||||
|
||||
export enum FilterCondition {
|
||||
AND = "and",
|
||||
OR = "or",
|
||||
}
|
||||
|
||||
export type MetadataFilterValue = string | number | string[] | number[];
|
||||
|
||||
export interface MetadataFilter {
|
||||
key: string;
|
||||
value?: MetadataFilterValue;
|
||||
operator: `${FilterOperator}`; // ==, any, all,...
|
||||
}
|
||||
|
||||
export interface MetadataFilters {
|
||||
filters: Array<MetadataFilter>;
|
||||
condition?: `${FilterCondition}`; // and, or
|
||||
}
|
||||
|
||||
export interface MetadataInfo {
|
||||
name: string;
|
||||
type: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface VectorStoreInfo {
|
||||
metadataInfo: MetadataInfo[];
|
||||
contentInfo: string;
|
||||
}
|
||||
|
||||
export interface VectorStoreQuery {
|
||||
queryEmbedding?: number[];
|
||||
similarityTopK: number;
|
||||
docIds?: string[];
|
||||
queryStr?: string;
|
||||
mode: VectorStoreQueryMode;
|
||||
alpha?: number;
|
||||
filters?: MetadataFilters | undefined;
|
||||
mmrThreshold?: number;
|
||||
}
|
||||
|
||||
// Supported types of vector stores (for each modality)
|
||||
export type VectorStoreByType = {
|
||||
[P in ModalityType]?: BaseVectorStore;
|
||||
};
|
||||
|
||||
export type VectorStoreBaseParams = {
|
||||
embeddingModel?: BaseEmbedding | undefined;
|
||||
};
|
||||
|
||||
export abstract class BaseVectorStore<Client = unknown> {
|
||||
embedModel: BaseEmbedding;
|
||||
abstract storesText: boolean;
|
||||
isEmbeddingQuery?: boolean;
|
||||
abstract client(): Client;
|
||||
abstract add(embeddingResults: BaseNode[]): Promise<string[]>;
|
||||
abstract delete(refDocId: string, deleteOptions?: object): Promise<void>;
|
||||
abstract query(
|
||||
query: VectorStoreQuery,
|
||||
options?: object,
|
||||
): Promise<VectorStoreQueryResult>;
|
||||
|
||||
protected constructor(params?: VectorStoreBaseParams) {
|
||||
this.embedModel = params?.embeddingModel ?? Settings.embedModel;
|
||||
}
|
||||
}
|
||||
|
||||
export const parsePrimitiveValue = (
|
||||
value?: MetadataFilterValue,
|
||||
): string | number => {
|
||||
if (typeof value !== "number" && typeof value !== "string") {
|
||||
throw new Error("Value must be a string or number");
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
export const parseArrayValue = (
|
||||
value?: MetadataFilterValue,
|
||||
): string[] | number[] => {
|
||||
const isPrimitiveArray =
|
||||
Array.isArray(value) &&
|
||||
value.every((v) => typeof v === "string" || typeof v === "number");
|
||||
if (!isPrimitiveArray) {
|
||||
throw new Error("Value must be an array of strings or numbers");
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
export const parseNumberValue = (value?: MetadataFilterValue): number => {
|
||||
if (typeof value !== "number") throw new Error("Value must be a number");
|
||||
return value;
|
||||
};
|
||||
|
||||
export * from "./utils.js";
|
||||
|
||||
Vendored
+1
-1
@@ -125,7 +125,7 @@
|
||||
"@huggingface/transformers": "^3.0.2",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/readable-stream": "^4.0.15",
|
||||
"bunchee": "6.2.0",
|
||||
"bunchee": "6.0.3",
|
||||
"gpt-tokenizer": "^2.6.2",
|
||||
"pathe": "^1.1.2",
|
||||
"vitest": "^2.1.5"
|
||||
|
||||
@@ -1,23 +1,5 @@
|
||||
# @llamaindex/experimental
|
||||
|
||||
## 0.0.144
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [1931bbc]
|
||||
- llamaindex@0.8.32
|
||||
|
||||
## 0.0.143
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d211b7a]
|
||||
- Updated dependencies [0ebbfc1]
|
||||
- llamaindex@0.8.31
|
||||
|
||||
## 0.0.142
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@llamaindex/experimental",
|
||||
"description": "Experimental package for LlamaIndexTS",
|
||||
"version": "0.0.144",
|
||||
"version": "0.0.142",
|
||||
"type": "module",
|
||||
"types": "dist/type/index.d.ts",
|
||||
"main": "dist/cjs/index.js",
|
||||
|
||||
@@ -1,73 +1,5 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.8.32
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 34faf48: chore: move vector stores to their own packages
|
||||
- 4df1fe6: chore: migrate llamaindex llms and embeddings to their own packages
|
||||
- 9456616: refactor: @llamaindex/postgres
|
||||
- 1931bbc: refactor: @llamaindex/azure
|
||||
- Updated dependencies [34faf48]
|
||||
- Updated dependencies [4df1fe6]
|
||||
- Updated dependencies [9456616]
|
||||
- Updated dependencies [d6c270e]
|
||||
- Updated dependencies [1892e1c]
|
||||
- Updated dependencies [1931bbc]
|
||||
- Updated dependencies [8744796]
|
||||
- @llamaindex/astra@0.0.2
|
||||
- @llamaindex/chroma@0.0.2
|
||||
- @llamaindex/milvus@0.0.2
|
||||
- @llamaindex/mongodb@0.0.2
|
||||
- @llamaindex/pinecone@0.0.2
|
||||
- @llamaindex/qdrant@0.0.2
|
||||
- @llamaindex/upstash@0.0.2
|
||||
- @llamaindex/weaviate@0.0.2
|
||||
- @llamaindex/google@0.0.2
|
||||
- @llamaindex/mistral@0.0.2
|
||||
- @llamaindex/core@0.4.21
|
||||
- @llamaindex/cloud@2.0.22
|
||||
- @llamaindex/openai@0.1.46
|
||||
- @llamaindex/azure@0.0.2
|
||||
- @llamaindex/node-parser@0.0.22
|
||||
- @llamaindex/anthropic@0.0.30
|
||||
- @llamaindex/clip@0.0.30
|
||||
- @llamaindex/cohere@0.0.2
|
||||
- @llamaindex/deepinfra@0.0.30
|
||||
- @llamaindex/huggingface@0.0.30
|
||||
- @llamaindex/mixedbread@0.0.2
|
||||
- @llamaindex/ollama@0.0.37
|
||||
- @llamaindex/portkey-ai@0.0.30
|
||||
- @llamaindex/replicate@0.0.30
|
||||
- @llamaindex/postgres@0.0.30
|
||||
- @llamaindex/readers@1.0.23
|
||||
- @llamaindex/groq@0.0.45
|
||||
- @llamaindex/vllm@0.0.16
|
||||
|
||||
## 0.8.31
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d211b7a: added support for tool calls with results in message history for athropic agent
|
||||
- 0ebbfc1: fix: clean up docstore when generating embedding fail
|
||||
- Updated dependencies [5dec9f9]
|
||||
- Updated dependencies [fd9c829]
|
||||
- Updated dependencies [d211b7a]
|
||||
- @llamaindex/cloud@2.0.21
|
||||
- @llamaindex/anthropic@0.0.29
|
||||
- @llamaindex/core@0.4.20
|
||||
- @llamaindex/node-parser@0.0.21
|
||||
- @llamaindex/clip@0.0.29
|
||||
- @llamaindex/deepinfra@0.0.29
|
||||
- @llamaindex/huggingface@0.0.29
|
||||
- @llamaindex/ollama@0.0.36
|
||||
- @llamaindex/openai@0.1.45
|
||||
- @llamaindex/portkey-ai@0.0.29
|
||||
- @llamaindex/replicate@0.0.29
|
||||
- @llamaindex/readers@1.0.22
|
||||
- @llamaindex/groq@0.0.44
|
||||
- @llamaindex/vllm@0.0.15
|
||||
|
||||
## 0.8.30
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.8.32",
|
||||
"version": "0.8.30",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
@@ -20,6 +20,17 @@
|
||||
"llamaindex"
|
||||
],
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "0.32.1",
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
"@aws-sdk/client-sso-oidc": "^3.693.0",
|
||||
"@azure/cosmos": "^4.1.1",
|
||||
"@azure/identity": "^4.4.1",
|
||||
"@azure/search-documents": "^12.1.0",
|
||||
"@datastax/astra-db-ts": "^1.4.1",
|
||||
"@discoveryjs/json-ext": "^0.6.1",
|
||||
"@google-cloud/vertexai": "1.9.0",
|
||||
"@google/generative-ai": "0.21.0",
|
||||
"@grpc/grpc-js": "^1.12.2",
|
||||
"@llamaindex/anthropic": "workspace:*",
|
||||
"@llamaindex/clip": "workspace:*",
|
||||
"@llamaindex/cloud": "workspace:*",
|
||||
@@ -35,31 +46,55 @@
|
||||
"@llamaindex/readers": "workspace:*",
|
||||
"@llamaindex/replicate": "workspace:*",
|
||||
"@llamaindex/vllm": "workspace:*",
|
||||
"@llamaindex/postgres": "workspace:*",
|
||||
"@llamaindex/azure": "workspace:*",
|
||||
"@llamaindex/astra": "workspace:*",
|
||||
"@llamaindex/milvus": "workspace:*",
|
||||
"@llamaindex/chroma": "workspace:*",
|
||||
"@llamaindex/mongodb": "workspace:*",
|
||||
"@llamaindex/pinecone": "workspace:*",
|
||||
"@llamaindex/qdrant": "workspace:*",
|
||||
"@llamaindex/upstash": "workspace:*",
|
||||
"@llamaindex/weaviate": "workspace:*",
|
||||
"@llamaindex/google": "workspace:*",
|
||||
"@llamaindex/mistral": "workspace:*",
|
||||
"@llamaindex/mixedbread": "workspace:*",
|
||||
"@llamaindex/cohere": "workspace:*",
|
||||
"@mistralai/mistralai": "^1.3.4",
|
||||
"@mixedbread-ai/sdk": "^2.2.11",
|
||||
"@pinecone-database/pinecone": "^4.0.0",
|
||||
"@qdrant/js-client-rest": "^1.11.0",
|
||||
"@types/lodash": "^4.17.7",
|
||||
"@types/node": "^22.9.0",
|
||||
"@types/pg": "^8.11.8",
|
||||
"@upstash/vector": "^1.1.5",
|
||||
"@zilliz/milvus2-sdk-node": "^2.4.6",
|
||||
"ajv": "^8.17.1",
|
||||
"assemblyai": "^4.8.0",
|
||||
"chromadb": "1.9.2",
|
||||
"chromadb-default-embed": "^2.13.2",
|
||||
"cohere-ai": "7.14.0",
|
||||
"gpt-tokenizer": "^2.6.2",
|
||||
"groq-sdk": "^0.8.0",
|
||||
"js-tiktoken": "^1.0.14",
|
||||
"lodash": "^4.17.21",
|
||||
"magic-bytes.js": "^1.10.0"
|
||||
"magic-bytes.js": "^1.10.0",
|
||||
"mongodb": "^6.7.0",
|
||||
"openai": "^4.73.1",
|
||||
"pathe": "^1.1.2",
|
||||
"rake-modified": "^1.0.8",
|
||||
"weaviate-client": "^3.2.3",
|
||||
"wikipedia": "^2.1.2",
|
||||
"wink-nlp": "^2.3.0",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg": "^8.12.0",
|
||||
"pgvector": "0.2.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"pg": {
|
||||
"optional": true
|
||||
},
|
||||
"pgvector": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@swc/cli": "^0.5.0",
|
||||
"@swc/core": "^1.9.2",
|
||||
"@vercel/postgres": "^0.10.0",
|
||||
"concurrently": "^9.1.0",
|
||||
"glob": "^11.0.0",
|
||||
"pg": "^8.12.0",
|
||||
"pgvector": "0.2.0",
|
||||
"postgres": "^3.4.4",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -13,6 +13,11 @@ import {
|
||||
} from "@llamaindex/core/node-parser";
|
||||
import { AsyncLocalStorage } from "@llamaindex/env";
|
||||
import type { ServiceContext } from "./ServiceContext.js";
|
||||
import {
|
||||
getEmbeddedModel,
|
||||
setEmbeddedModel,
|
||||
withEmbeddedModel,
|
||||
} from "./internal/settings/EmbedModel.js";
|
||||
|
||||
export type PromptConfig = {
|
||||
llm?: string;
|
||||
@@ -79,15 +84,15 @@ class GlobalSettings implements Config {
|
||||
}
|
||||
|
||||
get embedModel(): BaseEmbedding {
|
||||
return CoreSettings.embedModel;
|
||||
return getEmbeddedModel();
|
||||
}
|
||||
|
||||
set embedModel(embedModel: BaseEmbedding) {
|
||||
CoreSettings.embedModel = embedModel;
|
||||
setEmbeddedModel(embedModel);
|
||||
}
|
||||
|
||||
withEmbedModel<Result>(embedModel: BaseEmbedding, fn: () => Result): Result {
|
||||
return CoreSettings.withEmbedModel(embedModel, fn);
|
||||
return withEmbeddedModel(embedModel, fn);
|
||||
}
|
||||
|
||||
get nodeParser(): NodeParser {
|
||||
|
||||
@@ -1 +1,39 @@
|
||||
export { GEMINI_EMBEDDING_MODEL, GeminiEmbedding } from "@llamaindex/google";
|
||||
import { BaseEmbedding } from "@llamaindex/core/embeddings";
|
||||
import { GeminiSession, GeminiSessionStore } from "../llm/gemini/base.js";
|
||||
import { GEMINI_BACKENDS } from "../llm/gemini/types.js";
|
||||
|
||||
export enum GEMINI_EMBEDDING_MODEL {
|
||||
EMBEDDING_001 = "embedding-001",
|
||||
TEXT_EMBEDDING_004 = "text-embedding-004",
|
||||
}
|
||||
|
||||
/**
|
||||
* GeminiEmbedding is an alias for Gemini that implements the BaseEmbedding interface.
|
||||
* Note: Vertex SDK currently does not support embeddings
|
||||
*/
|
||||
export class GeminiEmbedding extends BaseEmbedding {
|
||||
model: GEMINI_EMBEDDING_MODEL;
|
||||
session: GeminiSession;
|
||||
|
||||
constructor(init?: Partial<GeminiEmbedding>) {
|
||||
super();
|
||||
this.model = init?.model ?? GEMINI_EMBEDDING_MODEL.EMBEDDING_001;
|
||||
this.session =
|
||||
init?.session ??
|
||||
(GeminiSessionStore.get({
|
||||
backend: GEMINI_BACKENDS.GOOGLE,
|
||||
}) as GeminiSession);
|
||||
}
|
||||
|
||||
private async getEmbedding(prompt: string): Promise<number[]> {
|
||||
const client = this.session.getGenerativeModel({
|
||||
model: this.model,
|
||||
});
|
||||
const result = await client.embedContent(prompt);
|
||||
return result.embedding.values;
|
||||
}
|
||||
|
||||
getTextEmbedding(text: string): Promise<number[]> {
|
||||
return this.getEmbedding(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,33 @@
|
||||
export {
|
||||
MistralAIEmbedding,
|
||||
MistralAIEmbeddingModelType,
|
||||
} from "@llamaindex/mistral";
|
||||
import { BaseEmbedding } from "@llamaindex/core/embeddings";
|
||||
import { MistralAISession } from "../llm/mistral.js";
|
||||
|
||||
export enum MistralAIEmbeddingModelType {
|
||||
MISTRAL_EMBED = "mistral-embed",
|
||||
}
|
||||
|
||||
export class MistralAIEmbedding extends BaseEmbedding {
|
||||
model: MistralAIEmbeddingModelType;
|
||||
apiKey?: string;
|
||||
|
||||
private session: MistralAISession;
|
||||
|
||||
constructor(init?: Partial<MistralAIEmbedding>) {
|
||||
super();
|
||||
this.model = MistralAIEmbeddingModelType.MISTRAL_EMBED;
|
||||
this.session = new MistralAISession(init);
|
||||
}
|
||||
|
||||
private async getMistralAIEmbedding(input: string) {
|
||||
const client = await this.session.getClient();
|
||||
const { data } = await client.embeddings({
|
||||
model: this.model,
|
||||
input: [input],
|
||||
});
|
||||
|
||||
return data[0].embedding;
|
||||
}
|
||||
|
||||
async getTextEmbedding(text: string): Promise<number[]> {
|
||||
return this.getMistralAIEmbedding(text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,178 @@
|
||||
export {
|
||||
MixedbreadAIEmbeddings,
|
||||
type MixedbreadAIEmbeddingsParams,
|
||||
} from "@llamaindex/mixedbread";
|
||||
import { BaseEmbedding, type EmbeddingInfo } from "@llamaindex/core/embeddings";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { MixedbreadAI, MixedbreadAIClient } from "@mixedbread-ai/sdk";
|
||||
|
||||
type EmbeddingsRequestWithoutInput = Omit<
|
||||
MixedbreadAI.EmbeddingsRequest,
|
||||
"input"
|
||||
>;
|
||||
|
||||
/**
|
||||
* Interface extending EmbeddingsParams with additional
|
||||
* parameters specific to the MixedbreadAIEmbeddings class.
|
||||
*/
|
||||
export interface MixedbreadAIEmbeddingsParams
|
||||
extends Omit<EmbeddingsRequestWithoutInput, "model"> {
|
||||
/**
|
||||
* The model to use for generating embeddings.
|
||||
* @default {"mixedbread-ai/mxbai-embed-large-v1"}
|
||||
*/
|
||||
model?: string;
|
||||
|
||||
/**
|
||||
* The API key to use.
|
||||
* @default {process.env.MXBAI_API_KEY}
|
||||
*/
|
||||
apiKey?: string;
|
||||
|
||||
/**
|
||||
* The base URL for the API.
|
||||
*/
|
||||
baseUrl?: string;
|
||||
|
||||
/**
|
||||
* The maximum number of documents to embed in a single request.
|
||||
* @default {128}
|
||||
*/
|
||||
embedBatchSize?: number;
|
||||
|
||||
/**
|
||||
* The embed info for the model.
|
||||
*/
|
||||
embedInfo?: EmbeddingInfo;
|
||||
|
||||
/**
|
||||
* The maximum number of retries to attempt.
|
||||
* @default {3}
|
||||
*/
|
||||
maxRetries?: number;
|
||||
|
||||
/**
|
||||
* Timeouts for the request.
|
||||
*/
|
||||
timeoutInSeconds?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for generating embeddings using the mixedbread ai API.
|
||||
*
|
||||
* This class leverages the model "mixedbread-ai/mxbai-embed-large-v1" to generate
|
||||
* embeddings for text documents. The embeddings can be used for various NLP tasks
|
||||
* such as similarity comparison, clustering, or as features in machine learning models.
|
||||
*
|
||||
* @example
|
||||
* const mxbai = new MixedbreadAIEmbeddings({ apiKey: 'your-api-key' });
|
||||
* const texts = ["Baking bread is fun", "I love baking"];
|
||||
* const result = await mxbai.getTextEmbeddings(texts);
|
||||
* console.log(result);
|
||||
*
|
||||
* @example
|
||||
* const mxbai = new MixedbreadAIEmbeddings({
|
||||
* apiKey: 'your-api-key',
|
||||
* model: 'mixedbread-ai/mxbai-embed-large-v1',
|
||||
* encodingFormat: MixedbreadAI.EncodingFormat.Binary,
|
||||
* dimensions: 512,
|
||||
* normalized: true,
|
||||
* });
|
||||
* const query = "Represent this sentence for searching relevant passages: Is baking bread fun?";
|
||||
* const result = await mxbai.getTextEmbedding(query);
|
||||
* console.log(result);
|
||||
*/
|
||||
export class MixedbreadAIEmbeddings extends BaseEmbedding {
|
||||
requestParams: EmbeddingsRequestWithoutInput;
|
||||
requestOptions: MixedbreadAIClient.RequestOptions;
|
||||
private client: MixedbreadAIClient;
|
||||
|
||||
/**
|
||||
* Constructor for MixedbreadAIEmbeddings.
|
||||
* @param {Partial<MixedbreadAIEmbeddingsParams>} params - An optional object with properties to configure the instance.
|
||||
* @throws {Error} If the API key is not provided or found in the environment variables.
|
||||
* @throws {Error} If the batch size exceeds 256.
|
||||
*/
|
||||
constructor(params?: Partial<MixedbreadAIEmbeddingsParams>) {
|
||||
super();
|
||||
|
||||
const apiKey = params?.apiKey ?? getEnv("MXBAI_API_KEY");
|
||||
if (!apiKey) {
|
||||
throw new Error(
|
||||
"mixedbread ai API key not found. Either provide it in the constructor or set the 'MXBAI_API_KEY' environment variable.",
|
||||
);
|
||||
}
|
||||
if (params?.embedBatchSize && params?.embedBatchSize > 256) {
|
||||
throw new Error(
|
||||
"The maximum batch size for mixedbread ai embeddings API is 256.",
|
||||
);
|
||||
}
|
||||
|
||||
this.embedBatchSize = params?.embedBatchSize ?? 128;
|
||||
if (params?.embedInfo) {
|
||||
this.embedInfo = params?.embedInfo;
|
||||
}
|
||||
this.requestParams = <EmbeddingsRequestWithoutInput>{
|
||||
model: params?.model ?? "mixedbread-ai/mxbai-embed-large-v1",
|
||||
normalized: params?.normalized,
|
||||
dimensions: params?.dimensions,
|
||||
encodingFormat: params?.encodingFormat,
|
||||
truncationStrategy: params?.truncationStrategy,
|
||||
prompt: params?.prompt,
|
||||
};
|
||||
this.requestOptions = {
|
||||
timeoutInSeconds: params?.timeoutInSeconds,
|
||||
maxRetries: params?.maxRetries ?? 3,
|
||||
// Support for this already exists in the python sdk and will be added to the js sdk soon
|
||||
// @ts-expect-error fixme
|
||||
additionalHeaders: {
|
||||
"user-agent": "@mixedbread-ai/llamaindex-ts-sdk",
|
||||
},
|
||||
};
|
||||
this.client = new MixedbreadAIClient(
|
||||
params?.baseUrl
|
||||
? {
|
||||
apiKey,
|
||||
environment: params?.baseUrl,
|
||||
}
|
||||
: {
|
||||
apiKey,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an embedding for a single text.
|
||||
* @param {string} text - A string to generate an embedding for.
|
||||
* @returns {Promise<number[]>} A Promise that resolves to an array of numbers representing the embedding.
|
||||
*
|
||||
* @example
|
||||
* const query = "Represent this sentence for searching relevant passages: Is baking bread fun?";
|
||||
* const result = await mxbai.getTextEmbedding(text);
|
||||
* console.log(result);
|
||||
*/
|
||||
async getTextEmbedding(text: string): Promise<number[]> {
|
||||
return (await this.getTextEmbeddings([text]))[0]!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates embeddings for an array of texts.
|
||||
* @param {string[]} texts - An array of strings to generate embeddings for.
|
||||
* @returns {Promise<Array<number[]>>} A Promise that resolves to an array of embeddings.
|
||||
*
|
||||
* @example
|
||||
* const texts = ["Baking bread is fun", "I love baking"];
|
||||
* const result = await mxbai.getTextEmbeddings(texts);
|
||||
* console.log(result);
|
||||
*/
|
||||
getTextEmbeddings = async (texts: string[]): Promise<Array<number[]>> => {
|
||||
if (texts.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const response = await this.client.embeddings(
|
||||
{
|
||||
...this.requestParams,
|
||||
input: texts,
|
||||
},
|
||||
this.requestOptions,
|
||||
);
|
||||
return response.data.map((d) => d.embedding as number[]);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ export * from "@llamaindex/core/embeddings";
|
||||
export { ClipEmbedding, ClipEmbeddingModelType } from "./ClipEmbedding.js";
|
||||
export { DeepInfraEmbedding } from "./DeepInfraEmbedding.js";
|
||||
export { FireworksEmbedding } from "./fireworks.js";
|
||||
export { GEMINI_EMBEDDING_MODEL, GeminiEmbedding } from "./GeminiEmbedding.js";
|
||||
export * from "./GeminiEmbedding.js";
|
||||
export * from "./HuggingFaceEmbedding.js";
|
||||
export * from "./JinaAIEmbedding.js";
|
||||
export * from "./MistralAIEmbedding.js";
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
//#region initial setup for OpenAI
|
||||
import { OpenAI, OpenAIEmbedding } from "@llamaindex/openai";
|
||||
import { OpenAI } from "@llamaindex/openai";
|
||||
import { Settings } from "./Settings.js";
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
Settings.llm;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||
Settings.embedModel;
|
||||
} catch {
|
||||
Settings.llm = new OpenAI();
|
||||
Settings.embedModel = new OpenAIEmbedding();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
@@ -7,14 +7,12 @@ export {
|
||||
HuggingFaceEmbeddingModelType,
|
||||
} from "./embeddings/HuggingFaceEmbedding.js";
|
||||
|
||||
export {
|
||||
GeminiVertexSession,
|
||||
type VertexGeminiSessionOptions,
|
||||
} from "@llamaindex/google";
|
||||
export { type VertexGeminiSessionOptions } from "./llm/gemini/types.js";
|
||||
export { GeminiVertexSession } from "./llm/gemini/vertex.js";
|
||||
|
||||
// Expose AzureDynamicSessionTool for node.js runtime only
|
||||
export { AzureDynamicSessionTool } from "@llamaindex/azure";
|
||||
export { JinaAIEmbedding } from "./embeddings/JinaAIEmbedding.js";
|
||||
export { AzureDynamicSessionTool } from "./tools/AzureDynamicSessionTool.node.js";
|
||||
|
||||
// Don't export vector store modules for non-node.js runtime on top level,
|
||||
// as we cannot guarantee that they will work in other environments
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
} from "@llamaindex/core/schema";
|
||||
import type { BaseIndexStore } from "@llamaindex/core/storage/index-store";
|
||||
import { extractText } from "@llamaindex/core/utils";
|
||||
import { VectorStoreQueryMode } from "@llamaindex/core/vector-store";
|
||||
import type { ServiceContext } from "../../ServiceContext.js";
|
||||
import { nodeParserFromSettingsOrContext } from "../../Settings.js";
|
||||
import { RetrieverQueryEngine } from "../../engines/query/RetrieverQueryEngine.js";
|
||||
@@ -39,6 +38,7 @@ import type {
|
||||
VectorStoreByType,
|
||||
VectorStoreQueryResult,
|
||||
} from "../../vector-store/index.js";
|
||||
import { VectorStoreQueryMode } from "../../vector-store/types.js";
|
||||
import type { BaseIndexInit } from "../BaseIndex.js";
|
||||
import { BaseIndex } from "../BaseIndex.js";
|
||||
|
||||
@@ -237,12 +237,7 @@ export class VectorStoreIndex extends BaseIndex<IndexDict> {
|
||||
if (args.logProgress) {
|
||||
console.log("Finished parsing documents.");
|
||||
}
|
||||
try {
|
||||
return await this.init(args);
|
||||
} catch (error) {
|
||||
await docStoreStrategy.rollback(args.storageContext.docStore, args.nodes);
|
||||
throw error;
|
||||
}
|
||||
return await this.init(args);
|
||||
}
|
||||
|
||||
static async fromVectorStores(
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import type {
|
||||
BaseVectorStore,
|
||||
VectorStoreByType,
|
||||
} from "@llamaindex/core/vector-store";
|
||||
} from "../vector-store/types.js";
|
||||
import { IngestionCache, getTransformationHash } from "./IngestionCache.js";
|
||||
import {
|
||||
DocStoreStrategy,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { BaseNode } from "@llamaindex/core/schema";
|
||||
import { BaseNode, TransformComponent } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import { RollbackableTransformComponent } from "./rollback.js";
|
||||
|
||||
/**
|
||||
* Handle doc store duplicates by checking all hashes.
|
||||
*/
|
||||
export class DuplicatesStrategy extends RollbackableTransformComponent {
|
||||
export class DuplicatesStrategy extends TransformComponent {
|
||||
private docStore: BaseDocumentStore;
|
||||
|
||||
constructor(docStore: BaseDocumentStore) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { BaseNode } from "@llamaindex/core/schema";
|
||||
import { BaseNode, TransformComponent } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import type { BaseVectorStore } from "@llamaindex/core/vector-store";
|
||||
import type { BaseVectorStore } from "../../vector-store/types.js";
|
||||
import { classify } from "./classify.js";
|
||||
import { RollbackableTransformComponent } from "./rollback.js";
|
||||
|
||||
/**
|
||||
* Handle docstore upserts by checking hashes and ids.
|
||||
* Identify missing docs and delete them from docstore and vector store
|
||||
*/
|
||||
export class UpsertsAndDeleteStrategy extends RollbackableTransformComponent {
|
||||
export class UpsertsAndDeleteStrategy extends TransformComponent {
|
||||
protected docStore: BaseDocumentStore;
|
||||
protected vectorStores: BaseVectorStore[] | undefined;
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { BaseNode } from "@llamaindex/core/schema";
|
||||
import { BaseNode, TransformComponent } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import type { BaseVectorStore } from "@llamaindex/core/vector-store";
|
||||
import type { BaseVectorStore } from "../../vector-store/types.js";
|
||||
import { classify } from "./classify.js";
|
||||
import { RollbackableTransformComponent } from "./rollback.js";
|
||||
|
||||
/**
|
||||
* Handles doc store upserts by checking hashes and ids.
|
||||
*/
|
||||
export class UpsertsStrategy extends RollbackableTransformComponent {
|
||||
export class UpsertsStrategy extends TransformComponent {
|
||||
protected docStore: BaseDocumentStore;
|
||||
protected vectorStores: BaseVectorStore[] | undefined;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { TransformComponent } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import type { BaseVectorStore } from "@llamaindex/core/vector-store";
|
||||
import type { BaseVectorStore } from "../../vector-store/types.js";
|
||||
import { DuplicatesStrategy } from "./DuplicatesStrategy.js";
|
||||
import { UpsertsAndDeleteStrategy } from "./UpsertsAndDeleteStrategy.js";
|
||||
import { UpsertsStrategy } from "./UpsertsStrategy.js";
|
||||
import { RollbackableTransformComponent } from "./rollback.js";
|
||||
|
||||
/**
|
||||
* Document de-deduplication strategies work by comparing the hashes or ids stored in the document store.
|
||||
@@ -19,7 +19,7 @@ export enum DocStoreStrategy {
|
||||
NONE = "none", // no-op strategy
|
||||
}
|
||||
|
||||
class NoOpStrategy extends RollbackableTransformComponent {
|
||||
class NoOpStrategy extends TransformComponent {
|
||||
constructor() {
|
||||
super(async (nodes) => nodes);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export function createDocStoreStrategy(
|
||||
docStoreStrategy: DocStoreStrategy,
|
||||
docStore?: BaseDocumentStore,
|
||||
vectorStores: BaseVectorStore[] = [],
|
||||
): RollbackableTransformComponent {
|
||||
): TransformComponent {
|
||||
if (docStoreStrategy === DocStoreStrategy.NONE) {
|
||||
return new NoOpStrategy();
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { BaseNode, TransformComponent } from "@llamaindex/core/schema";
|
||||
import type { BaseDocumentStore } from "../../index.edge.js";
|
||||
import { classify } from "./classify.js";
|
||||
|
||||
export class RollbackableTransformComponent extends TransformComponent {
|
||||
// Remove unused docs from the doc store. It is useful in case
|
||||
// generating embeddings fails and we want to remove the unused docs
|
||||
// TODO: override this in UpsertsStrategy if we want to revert removed docs also
|
||||
public async rollback(
|
||||
docStore: BaseDocumentStore,
|
||||
nodes: BaseNode[],
|
||||
): Promise<void> {
|
||||
const { unusedDocs } = await classify(docStore, nodes);
|
||||
for (const docId of unusedDocs) {
|
||||
await docStore.deleteDocument(docId, false);
|
||||
}
|
||||
docStore.persist();
|
||||
}
|
||||
}
|
||||
+4
-7
@@ -1,18 +1,15 @@
|
||||
import type { BaseEmbedding } from "@llamaindex/core/embeddings";
|
||||
import { AsyncLocalStorage } from "@llamaindex/env";
|
||||
import { OpenAIEmbedding } from "@llamaindex/openai";
|
||||
|
||||
const embeddedModelAsyncLocalStorage = new AsyncLocalStorage<BaseEmbedding>();
|
||||
let globalEmbeddedModel: BaseEmbedding | null = null;
|
||||
|
||||
export function getEmbeddedModel(): BaseEmbedding {
|
||||
const currentEmbeddedModel =
|
||||
embeddedModelAsyncLocalStorage.getStore() ?? globalEmbeddedModel;
|
||||
if (!currentEmbeddedModel) {
|
||||
throw new Error(
|
||||
"Cannot find Embedding, please set `Settings.embedModel = ...` on the top of your code",
|
||||
);
|
||||
if (globalEmbeddedModel === null) {
|
||||
globalEmbeddedModel = new OpenAIEmbedding();
|
||||
}
|
||||
return currentEmbeddedModel;
|
||||
return embeddedModelAsyncLocalStorage.getStore() ?? globalEmbeddedModel;
|
||||
}
|
||||
|
||||
export function setEmbeddedModel(embeddedModel: BaseEmbedding) {
|
||||
@@ -1 +0,0 @@
|
||||
export * from "@llamaindex/google";
|
||||
@@ -6,12 +6,11 @@ export {
|
||||
Anthropic,
|
||||
} from "./anthropic.js";
|
||||
export { FireworksLLM } from "./fireworks.js";
|
||||
export { Gemini, GeminiSession } from "./gemini/base.js";
|
||||
export {
|
||||
GEMINI_MODEL,
|
||||
Gemini,
|
||||
GeminiSession,
|
||||
type GoogleGeminiSessionOptions,
|
||||
} from "./google.js";
|
||||
} from "./gemini/types.js";
|
||||
export * from "./groq.js";
|
||||
export { HuggingFaceInferenceAPI, HuggingFaceLLM } from "./huggingface.js";
|
||||
export {
|
||||
|
||||
@@ -1 +1,138 @@
|
||||
export * from "@llamaindex/mistral";
|
||||
import {
|
||||
BaseLLM,
|
||||
type ChatMessage,
|
||||
type ChatResponse,
|
||||
type ChatResponseChunk,
|
||||
type LLMChatParamsNonStreaming,
|
||||
type LLMChatParamsStreaming,
|
||||
} from "@llamaindex/core/llms";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
|
||||
export const ALL_AVAILABLE_MISTRAL_MODELS = {
|
||||
"mistral-tiny": { contextWindow: 32000 },
|
||||
"mistral-small": { contextWindow: 32000 },
|
||||
"mistral-medium": { contextWindow: 32000 },
|
||||
};
|
||||
|
||||
export class MistralAISession {
|
||||
apiKey: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private client: any;
|
||||
|
||||
constructor(init?: { apiKey?: string | undefined }) {
|
||||
if (init?.apiKey) {
|
||||
this.apiKey = init?.apiKey;
|
||||
} else {
|
||||
this.apiKey = getEnv("MISTRAL_API_KEY")!;
|
||||
}
|
||||
if (!this.apiKey) {
|
||||
throw new Error("Set Mistral API key in MISTRAL_API_KEY env variable"); // Overriding MistralAI package's error message
|
||||
}
|
||||
}
|
||||
|
||||
async getClient() {
|
||||
const { Mistral } = await import("@mistralai/mistralai");
|
||||
if (!this.client) {
|
||||
this.client = new Mistral({
|
||||
apiKey: this.apiKey,
|
||||
});
|
||||
}
|
||||
return this.client;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MistralAI LLM implementation
|
||||
*/
|
||||
export class MistralAI extends BaseLLM {
|
||||
// Per completion MistralAI params
|
||||
model: keyof typeof ALL_AVAILABLE_MISTRAL_MODELS;
|
||||
temperature: number;
|
||||
topP: number;
|
||||
maxTokens?: number | undefined;
|
||||
apiKey?: string;
|
||||
safeMode: boolean;
|
||||
randomSeed?: number | undefined;
|
||||
|
||||
private session: MistralAISession;
|
||||
|
||||
constructor(init?: Partial<MistralAI>) {
|
||||
super();
|
||||
this.model = init?.model ?? "mistral-small";
|
||||
this.temperature = init?.temperature ?? 0.1;
|
||||
this.topP = init?.topP ?? 1;
|
||||
this.maxTokens = init?.maxTokens ?? undefined;
|
||||
this.safeMode = init?.safeMode ?? false;
|
||||
this.randomSeed = init?.randomSeed ?? undefined;
|
||||
this.session = new MistralAISession(init);
|
||||
}
|
||||
|
||||
get metadata() {
|
||||
return {
|
||||
model: this.model,
|
||||
temperature: this.temperature,
|
||||
topP: this.topP,
|
||||
maxTokens: this.maxTokens,
|
||||
contextWindow: ALL_AVAILABLE_MISTRAL_MODELS[this.model].contextWindow,
|
||||
tokenizer: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private buildParams(messages: ChatMessage[]): any {
|
||||
return {
|
||||
model: this.model,
|
||||
temperature: this.temperature,
|
||||
maxTokens: this.maxTokens,
|
||||
topP: this.topP,
|
||||
safeMode: this.safeMode,
|
||||
randomSeed: this.randomSeed,
|
||||
messages,
|
||||
};
|
||||
}
|
||||
|
||||
chat(
|
||||
params: LLMChatParamsStreaming,
|
||||
): Promise<AsyncIterable<ChatResponseChunk>>;
|
||||
chat(params: LLMChatParamsNonStreaming): Promise<ChatResponse>;
|
||||
async chat(
|
||||
params: LLMChatParamsNonStreaming | LLMChatParamsStreaming,
|
||||
): Promise<ChatResponse | AsyncIterable<ChatResponseChunk>> {
|
||||
const { messages, stream } = params;
|
||||
// Streaming
|
||||
if (stream) {
|
||||
return this.streamChat(params);
|
||||
}
|
||||
// Non-streaming
|
||||
const client = await this.session.getClient();
|
||||
const response = await client.chat(this.buildParams(messages));
|
||||
const message = response.choices[0].message;
|
||||
return {
|
||||
raw: response,
|
||||
message,
|
||||
};
|
||||
}
|
||||
|
||||
protected async *streamChat({
|
||||
messages,
|
||||
}: LLMChatParamsStreaming): AsyncIterable<ChatResponseChunk> {
|
||||
const client = await this.session.getClient();
|
||||
const chunkStream = await client.chatStream(this.buildParams(messages));
|
||||
|
||||
//Indices
|
||||
let idx_counter: number = 0;
|
||||
for await (const part of chunkStream) {
|
||||
if (!part.choices.length) continue;
|
||||
|
||||
part.choices[0].index = idx_counter;
|
||||
|
||||
idx_counter++;
|
||||
|
||||
yield {
|
||||
raw: part,
|
||||
delta: part.choices[0].delta.content ?? "",
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
export * from "@llamaindex/cohere";
|
||||
export {
|
||||
MixedbreadAIReranker,
|
||||
type MixedbreadAIRerankerParams,
|
||||
} from "@llamaindex/mixedbread";
|
||||
export * from "./CohereRerank.js";
|
||||
export * from "./JinaAIReranker.js";
|
||||
export * from "./MixedbreadAIReranker.js";
|
||||
|
||||
@@ -9,13 +9,13 @@ import {
|
||||
BaseIndexStore,
|
||||
SimpleIndexStore,
|
||||
} from "@llamaindex/core/storage/index-store";
|
||||
import type {
|
||||
BaseVectorStore,
|
||||
VectorStoreByType,
|
||||
} from "@llamaindex/core/vector-store";
|
||||
import { path } from "@llamaindex/env";
|
||||
import type { ServiceContext } from "../ServiceContext.js";
|
||||
import { SimpleVectorStore } from "../vector-store/SimpleVectorStore.js";
|
||||
import type {
|
||||
BaseVectorStore,
|
||||
VectorStoreByType,
|
||||
} from "../vector-store/types.js";
|
||||
import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore.js";
|
||||
|
||||
export interface StorageContext {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { KVDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import { MongoClient } from "mongodb";
|
||||
import { AzureCosmosVCoreKVStore } from "../kvStore/AzureCosmosMongovCoreKVStore.js";
|
||||
import { KVDocumentStore } from "./KVDocumentStore.js";
|
||||
|
||||
const DEFAULT_DATABASE = "DocumentStoreDB";
|
||||
const DEFAULT_COLLECTION = "DocumentStoreCollection";
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
import { KVDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import {
|
||||
AzureCosmosNoSqlKVStore,
|
||||
type AadTokenOptions,
|
||||
type AccountAndKeyOptions,
|
||||
type ConnectionStringOptions,
|
||||
} from "../kvStore/AzureCosmosNoSqlKVStore.js";
|
||||
import { KVDocumentStore } from "./KVDocumentStore.js";
|
||||
|
||||
const DEFAULT_DATABASE = "DocumentStoreDB";
|
||||
const DEFAULT_CONTAINER = "DocumentStoreContainer";
|
||||
+19
-21
@@ -1,13 +1,15 @@
|
||||
import { DEFAULT_NAMESPACE } from "../../global";
|
||||
import { BaseNode, ObjectType, type StoredValue } from "../../schema";
|
||||
import type { BaseKVStore } from "../kv-store";
|
||||
import { DEFAULT_NAMESPACE } from "@llamaindex/core/global";
|
||||
import type { BaseNode } from "@llamaindex/core/schema";
|
||||
import { ObjectType } from "@llamaindex/core/schema";
|
||||
import type { RefDocInfo } from "@llamaindex/core/storage/doc-store";
|
||||
import {
|
||||
BaseDocumentStore,
|
||||
docToJson,
|
||||
isValidDocJson,
|
||||
jsonToDoc,
|
||||
type RefDocInfo,
|
||||
} from "./base-document-store";
|
||||
} from "@llamaindex/core/storage/doc-store";
|
||||
import type { BaseKVStore } from "@llamaindex/core/storage/kv-store";
|
||||
import _ from "lodash";
|
||||
|
||||
type DocMetaData = { docHash: string; refDocId?: string };
|
||||
|
||||
@@ -66,7 +68,7 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
extraInfo: {},
|
||||
};
|
||||
refDocInfo.nodeIds.push(doc.id_);
|
||||
if (Object.keys(refDocInfo.extraInfo).length === 0) {
|
||||
if (_.isEmpty(refDocInfo.extraInfo)) {
|
||||
refDocInfo.extraInfo = {};
|
||||
}
|
||||
await this.kvstore.put(
|
||||
@@ -86,7 +88,7 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
raiseError: boolean = true,
|
||||
): Promise<BaseNode | undefined> {
|
||||
const json = await this.kvstore.get(docId, this.nodeCollection);
|
||||
if (this.isNil(json)) {
|
||||
if (_.isNil(json)) {
|
||||
if (raiseError) {
|
||||
throw new Error(`docId ${docId} not found.`);
|
||||
} else {
|
||||
@@ -101,23 +103,23 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
|
||||
async getRefDocInfo(refDocId: string): Promise<RefDocInfo | undefined> {
|
||||
const refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection);
|
||||
return refDocInfo ? (structuredClone(refDocInfo) as RefDocInfo) : undefined;
|
||||
return refDocInfo ? (_.clone(refDocInfo) as RefDocInfo) : undefined;
|
||||
}
|
||||
|
||||
async getAllRefDocInfo(): Promise<Record<string, RefDocInfo> | undefined> {
|
||||
const refDocInfos = await this.kvstore.getAll(this.refDocCollection);
|
||||
if (this.isNil(refDocInfos)) {
|
||||
if (_.isNil(refDocInfos)) {
|
||||
return;
|
||||
}
|
||||
return refDocInfos as Record<string, RefDocInfo>;
|
||||
}
|
||||
|
||||
async refDocExists(refDocId: string): Promise<boolean> {
|
||||
return !this.isNil(await this.getRefDocInfo(refDocId));
|
||||
return !_.isNil(await this.getRefDocInfo(refDocId));
|
||||
}
|
||||
|
||||
async documentExists(docId: string): Promise<boolean> {
|
||||
return !this.isNil(await this.kvstore.get(docId, this.nodeCollection));
|
||||
return !_.isNil(await this.kvstore.get(docId, this.nodeCollection));
|
||||
}
|
||||
|
||||
private async removeRefDocNode(docId: string): Promise<void> {
|
||||
@@ -127,13 +129,13 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
}
|
||||
|
||||
const refDocId = metadata.refDocId;
|
||||
if (this.isNil(refDocId)) {
|
||||
if (_.isNil(refDocId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const refDocInfo = await this.kvstore.get(refDocId, this.refDocCollection);
|
||||
if (!this.isNil(refDocInfo)) {
|
||||
if (refDocInfo!.nodeIds.length > 0) {
|
||||
if (!_.isNil(refDocInfo)) {
|
||||
if (refDocInfo.nodeIds.length > 0) {
|
||||
await this.kvstore.put(refDocId, refDocInfo, this.refDocCollection);
|
||||
}
|
||||
await this.kvstore.delete(refDocId, this.metadataCollection);
|
||||
@@ -162,7 +164,7 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
raiseError: boolean = true,
|
||||
): Promise<void> {
|
||||
const refDocInfo = await this.getRefDocInfo(refDocId);
|
||||
if (this.isNil(refDocInfo)) {
|
||||
if (_.isNil(refDocInfo)) {
|
||||
if (raiseError) {
|
||||
throw new Error(`ref_doc_id ${refDocId} not found.`);
|
||||
} else {
|
||||
@@ -170,7 +172,7 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
}
|
||||
}
|
||||
|
||||
for (const docId of refDocInfo!.nodeIds) {
|
||||
for (const docId of refDocInfo.nodeIds) {
|
||||
await this.deleteDocument(docId, false, false);
|
||||
}
|
||||
|
||||
@@ -185,7 +187,7 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
|
||||
async getDocumentHash(docId: string): Promise<string | undefined> {
|
||||
const metadata = await this.kvstore.get(docId, this.metadataCollection);
|
||||
return metadata?.docHash;
|
||||
return _.get(metadata, "docHash");
|
||||
}
|
||||
|
||||
async getAllDocumentHashes(): Promise<Record<string, string>> {
|
||||
@@ -199,8 +201,4 @@ export class KVDocumentStore extends BaseDocumentStore {
|
||||
}
|
||||
return hashes;
|
||||
}
|
||||
|
||||
private isNil(value: RefDocInfo | StoredValue | undefined): boolean {
|
||||
return value === null || value === undefined;
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
import { DEFAULT_NAMESPACE } from "@llamaindex/core/global";
|
||||
import { noneSerializer } from "@llamaindex/core/storage/doc-store";
|
||||
import {
|
||||
KVDocumentStore,
|
||||
noneSerializer,
|
||||
} from "@llamaindex/core/storage/doc-store";
|
||||
import { PostgresKVStore, type PostgresKVStoreConfig } from "./PostgresKVStore";
|
||||
PostgresKVStore,
|
||||
type PostgresKVStoreConfig,
|
||||
} from "../kvStore/PostgresKVStore.js";
|
||||
import { KVDocumentStore } from "./KVDocumentStore.js";
|
||||
|
||||
const DEFAULT_TABLE_NAME = "llamaindex_doc_store";
|
||||
|
||||
@@ -3,13 +3,13 @@ import {
|
||||
DEFAULT_NAMESPACE,
|
||||
DEFAULT_PERSIST_DIR,
|
||||
} from "@llamaindex/core/global";
|
||||
import { KVDocumentStore } from "@llamaindex/core/storage/doc-store";
|
||||
import {
|
||||
BaseInMemoryKVStore,
|
||||
SimpleKVStore,
|
||||
} from "@llamaindex/core/storage/kv-store";
|
||||
import { path } from "@llamaindex/env";
|
||||
import _ from "lodash";
|
||||
import { KVDocumentStore } from "./KVDocumentStore.js";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
type SaveDict = Record<string, any>;
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
export * from "@llamaindex/azure/storage";
|
||||
export * from "@llamaindex/core/storage/chat-store";
|
||||
export * from "@llamaindex/core/storage/doc-store";
|
||||
export * from "@llamaindex/core/storage/index-store";
|
||||
export * from "@llamaindex/core/storage/kv-store";
|
||||
export {
|
||||
PostgresDocumentStore,
|
||||
PostgresIndexStore,
|
||||
PostgresKVStore,
|
||||
} from "@llamaindex/postgres";
|
||||
export * from "./chatStore/AzureCosmosMongovCoreChatStore.js";
|
||||
export * from "./chatStore/AzureCosmosNoSqlChatStore.js";
|
||||
export * from "./docStore/AzureCosmosMongovCoreDocumentStore.js";
|
||||
export * from "./docStore/AzureCosmosNoSqlDocumentStore.js";
|
||||
export { PostgresDocumentStore } from "./docStore/PostgresDocumentStore.js";
|
||||
export { SimpleDocumentStore } from "./docStore/SimpleDocumentStore.js";
|
||||
export * from "./FileSystem.js";
|
||||
|
||||
export * from "./indexStore/AzureCosmosMongovCoreIndexStore.js";
|
||||
export * from "./indexStore/AzureCosmosNoSqlIndexStore.js";
|
||||
export { PostgresIndexStore } from "./indexStore/PostgresIndexStore.js";
|
||||
export * from "./kvStore/AzureCosmosMongovCoreKVStore.js";
|
||||
export * from "./kvStore/AzureCosmosNoSqlKVStore.js";
|
||||
export { PostgresKVStore } from "./kvStore/PostgresKVStore.js";
|
||||
export * from "./StorageContext.js";
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { KVIndexStore } from "@llamaindex/core/storage/index-store";
|
||||
import { MongoClient } from "mongodb";
|
||||
import { AzureCosmosVCoreKVStore } from "../kvStore/AzureCosmosMongovCoreKVStore.js";
|
||||
import { KVIndexStore } from "./KVIndexStore.js";
|
||||
|
||||
const DEFAULT_DATABASE = "IndexStoreDB";
|
||||
const DEFAULT_COLLECTION = "IndexStoreCollection";
|
||||
+1
-1
@@ -1,10 +1,10 @@
|
||||
import { KVIndexStore } from "@llamaindex/core/storage/index-store";
|
||||
import {
|
||||
AzureCosmosNoSqlKVStore,
|
||||
type AadTokenOptions,
|
||||
type AccountAndKeyOptions,
|
||||
type ConnectionStringOptions,
|
||||
} from "../kvStore/AzureCosmosNoSqlKVStore.js";
|
||||
import { KVIndexStore } from "./KVIndexStore.js";
|
||||
|
||||
const DEFAULT_DATABASE = "IndexStoreDB";
|
||||
const DEFAULT_CONTAINER = "IndexStoreContainer";
|
||||
+5
-2
@@ -1,6 +1,9 @@
|
||||
import { DEFAULT_NAMESPACE } from "@llamaindex/core/global";
|
||||
import { KVIndexStore } from "@llamaindex/core/storage/index-store";
|
||||
import { PostgresKVStore, type PostgresKVStoreConfig } from "./PostgresKVStore";
|
||||
import {
|
||||
PostgresKVStore,
|
||||
type PostgresKVStoreConfig,
|
||||
} from "../kvStore/PostgresKVStore.js";
|
||||
import { KVIndexStore } from "./KVIndexStore.js";
|
||||
|
||||
const DEFAULT_TABLE_NAME = "llamaindex_index_store";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user