mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-10 15:53:42 -04:00
Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eac09e7816 | |||
| dd95927498 | |||
| 4f72feae91 | |||
| 3cd8f9f597 | |||
| d2e8d0c62a | |||
| fafbd8c9c7 | |||
| a40c91b054 | |||
| 98894055c6 | |||
| 4589a84643 | |||
| e6b7f52d3e | |||
| b169db617a | |||
| 89a49f4f4f | |||
| 58490715fe | |||
| 4c2283c4e5 | |||
| a059070dec | |||
| 20dfeb4cfa | |||
| aefc3266c1 | |||
| fdf48dd459 | |||
| 66525346a2 | |||
| c9b2ec4a2b | |||
| bf583a7266 | |||
| de194d1c73 | |||
| ecdc289df1 | |||
| 9e198ac40d | |||
| 0a06998690 | |||
| 484a7105a9 | |||
| 8d18ea167b | |||
| a2ca89bfe0 | |||
| edeea40898 | |||
| 2a7080b094 | |||
| b354f2386b | |||
| d766bd03d2 | |||
| 6a69148356 | |||
| e1e1b0b522 | |||
| d824876653 | |||
| 2048698f77 | |||
| 9942979aa7 | |||
| 3c2655a1f9 | |||
| 552a61a66f | |||
| d13143e322 | |||
| 5116ad8d08 | |||
| 64683a55f3 | |||
| 698cd9c631 | |||
| c744a99102 | |||
| 2d2935085e | |||
| 1b31e2c8cd | |||
| 7257751993 | |||
| de6bfdb1b1 | |||
| 9e49f4411b | |||
| 026d068ddf | |||
| 7055d6fc3c | |||
| e9c2366bf1 | |||
| 6278152e49 | |||
| 76010c0cea | |||
| 889b84cfb9 | |||
| a26681c416 | |||
| 90027a7b44 | |||
| aab56faf88 | |||
| c57bd11c45 |
@@ -11,5 +11,13 @@ module.exports = {
|
||||
"max-params": ["error", 4],
|
||||
"prefer-const": "error",
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ["examples/**/*.ts"],
|
||||
rules: {
|
||||
"turbo/no-undeclared-env-vars": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
ignorePatterns: ["dist/", "lib/"],
|
||||
};
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
name: E2E Tests
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
paths:
|
||||
- "packages/create-llama/**"
|
||||
- ".github/workflows/e2e.yml"
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
POETRY_VERSION: "1.6.1"
|
||||
|
||||
jobs:
|
||||
e2e:
|
||||
name: create-llama
|
||||
timeout-minutes: 60
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
node-version: [18, 20]
|
||||
python-version: ["3.11"]
|
||||
os: [macos-latest, windows-latest]
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install Poetry
|
||||
uses: snok/install-poetry@v1
|
||||
with:
|
||||
version: ${{ env.POETRY_VERSION }}
|
||||
- uses: pnpm/action-setup@v2
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: "pnpm"
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
- name: Install Playwright Browsers
|
||||
run: pnpm exec playwright install --with-deps
|
||||
working-directory: ./packages/create-llama
|
||||
- name: Build create-llama
|
||||
run: pnpm run build
|
||||
working-directory: ./packages/create-llama
|
||||
- name: Pack
|
||||
run: pnpm pack --pack-destination ./output
|
||||
working-directory: ./packages/create-llama
|
||||
- name: Extract Pack
|
||||
run: tar -xvzf ./output/*.tgz -C ./output
|
||||
working-directory: ./packages/create-llama
|
||||
- name: Run Playwright tests
|
||||
run: pnpm exec playwright test
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
working-directory: ./packages/create-llama
|
||||
- uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
with:
|
||||
name: playwright-report
|
||||
path: ./packages/create-llama/playwright-report/
|
||||
retention-days: 30
|
||||
@@ -0,0 +1,28 @@
|
||||
name: Publish
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Publish @llamaindex/env
|
||||
run: npx jsr publish
|
||||
working-directory: packages/env
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Publish @llamaindex/core
|
||||
run: npx jsr publish --allow-slow-types
|
||||
working-directory: packages/core
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -44,6 +44,7 @@ test-results/
|
||||
playwright-report/
|
||||
blob-report/
|
||||
playwright/.cache/
|
||||
.tsbuildinfo
|
||||
|
||||
# intellij
|
||||
**/.idea
|
||||
|
||||
+1
-2
@@ -84,8 +84,7 @@ Any changes you make should be reflected in the browser. If you need to regenera
|
||||
To publish a new version of the library, run
|
||||
|
||||
```shell
|
||||
pnpm new-llamaindex
|
||||
pnpm new-create-llama
|
||||
pnpm new-version
|
||||
pnpm release
|
||||
git push # push to the main branch
|
||||
git push --tags
|
||||
|
||||
@@ -121,6 +121,42 @@ const nextConfig = {
|
||||
module.exports = nextConfig;
|
||||
```
|
||||
|
||||
### NextJS with Milvus:
|
||||
|
||||
As proto files are not loaded per default in NextJS, you'll need to add the following to your next.config.js to have it load the proto files.
|
||||
|
||||
```js
|
||||
const path = require("path");
|
||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||
|
||||
// next.config.js
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
webpack: (config, { isServer }) => {
|
||||
if (isServer) {
|
||||
// Copy the proto files to the server build directory
|
||||
config.plugins.push(
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{
|
||||
from: path.join(
|
||||
__dirname,
|
||||
"node_modules/@zilliz/milvus2-sdk-node/dist",
|
||||
),
|
||||
to: path.join(__dirname, ".next"),
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
// Important: return the modified config
|
||||
return config;
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
```
|
||||
|
||||
## Supported LLMs:
|
||||
|
||||
- OpenAI GPT-3.5-turbo and GPT-4
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# docs
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [5116ad8]
|
||||
- @llamaindex/env@0.0.5
|
||||
|
||||
## 0.0.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -23,3 +23,15 @@ const results = await queryEngine.query({
|
||||
query,
|
||||
});
|
||||
```
|
||||
|
||||
Per default, `HuggingFaceEmbedding` is using the `Xenova/all-MiniLM-L6-v2` model. You can change the model by passing the `modelType` parameter to the constructor.
|
||||
If you're not using a quantized model, set the `quantized` parameter to `false`.
|
||||
|
||||
For example, to use the not quantized `BAAI/bge-small-en-v1.5` model, you can use the following code:
|
||||
|
||||
```
|
||||
const embedModel = new HuggingFaceEmbedding({
|
||||
modelType: "BAAI/bge-small-en-v1.5",
|
||||
quantized: false,
|
||||
});
|
||||
```
|
||||
|
||||
@@ -53,10 +53,6 @@ const evaluator = new CorrectnessEvaluator({
|
||||
serviceContext: ctx,
|
||||
});
|
||||
|
||||
const response = await queryEngine.query({
|
||||
query,
|
||||
});
|
||||
|
||||
const result = await evaluator.evaluateResponse({
|
||||
query,
|
||||
response,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Transformations
|
||||
|
||||
A transformation is something that takes a list of nodes as an input, and returns a list of nodes. Each component that implements the Transformatio class has both a `transform` definition responsible for transforming the nodes
|
||||
A transformation is something that takes a list of nodes as an input, and returns a list of nodes. Each component that implements the Transformation class has both a `transform` definition responsible for transforming the nodes.
|
||||
|
||||
Currently, the following components are Transformation objects:
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ const response = await queryEngine.query("<user_query>");
|
||||
```ts
|
||||
import { SimilarityPostprocessor } from "llamaindex";
|
||||
|
||||
nodes = await index.asRetriever().retrieve("test query str");
|
||||
nodes = await index.asRetriever().retrieve({ query: "test query str" });
|
||||
|
||||
const processor = new SimilarityPostprocessor({
|
||||
similarityCutoff: 0.7,
|
||||
|
||||
@@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Fetch nodes!
|
||||
const nodesWithScore = await retriever.retrieve("query string");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "query string" });
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// جلب العقد!
|
||||
const nodesWithScore = await retriever.retrieve("سلسلة الاستعلام");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "سلسلة الاستعلام" });
|
||||
```
|
||||
|
||||
## مرجع الواجهة البرمجية (API Reference)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Извличане на върхове!
|
||||
const nodesWithScore = await retriever.retrieve("query string");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "query string" });
|
||||
```
|
||||
|
||||
## API Reference (API справка)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
|
||||
recuperador.similarityTopK = 3;
|
||||
|
||||
// Obteniu els nodes!
|
||||
const nodesAmbPuntuació = await recuperador.retrieve("cadena de consulta");
|
||||
const nodesAmbPuntuació = await recuperador.retrieve({ query: "cadena de consulta" });
|
||||
```
|
||||
|
||||
## Referència de l'API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Získání uzlů!
|
||||
const nodesWithScore = await retriever.retrieve("dotazovací řetězec");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "dotazovací řetězec" });
|
||||
```
|
||||
|
||||
## API Reference (Odkazy na rozhraní)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Hent noder!
|
||||
const nodesWithScore = await retriever.retrieve("forespørgselsstreng");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "forespørgselsstreng" });
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Knoten abrufen!
|
||||
const nodesWithScore = await retriever.retrieve("Abfragezeichenfolge");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "Abfragezeichenfolge" });
|
||||
```
|
||||
|
||||
## API-Referenz
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Ανάκτηση κόμβων!
|
||||
const nodesWithScore = await retriever.retrieve("συμβολοσειρά ερωτήματος");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "συμβολοσειρά ερωτήματος" });
|
||||
```
|
||||
|
||||
## Αναφορά API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
|
||||
recuperador.similarityTopK = 3;
|
||||
|
||||
// ¡Obtener nodos!
|
||||
const nodosConPuntuación = await recuperador.retrieve("cadena de consulta");
|
||||
const nodosConPuntuación = await recuperador.retrieve({ query: "cadena de consulta" });
|
||||
```
|
||||
|
||||
## Referencia de la API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Too sõlmed!
|
||||
const nodesWithScore = await retriever.retrieve("päringu string");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "päringu string" });
|
||||
```
|
||||
|
||||
## API viide
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// بازیابی گره ها!
|
||||
const nodesWithScore = await retriever.retrieve("رشته پرس و جو");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "رشته پرس و جو" });
|
||||
```
|
||||
|
||||
## مرجع API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Hae solmut!
|
||||
const nodesWithScore = await retriever.retrieve("kyselymerkkijono");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "kyselymerkkijono" });
|
||||
```
|
||||
|
||||
## API-viite
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Récupérer les nœuds !
|
||||
const nodesWithScore = await retriever.retrieve("chaîne de requête");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "chaîne de requête" });
|
||||
```
|
||||
|
||||
## Référence de l'API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// אחזור צמתים!
|
||||
const nodesWithScore = await retriever.retrieve("מחרוזת שאילתה");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "מחרוזת שאילתה" });
|
||||
```
|
||||
|
||||
## מדריך לממשק API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// नोड्स प्राप्त करें!
|
||||
const nodesWithScore = await retriever.retrieve("क्वेरी स्ट्रिंग");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "क्वेरी स्ट्रिंग" });
|
||||
```
|
||||
|
||||
## एपीआई संदर्भ (API Reference)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const dohvatnik = vector_index.asRetriever();
|
||||
dohvatnik.similarityTopK = 3;
|
||||
|
||||
// Dohvati čvorove!
|
||||
const čvoroviSaRezultatom = await dohvatnik.retrieve("upitni niz");
|
||||
const čvoroviSaRezultatom = await dohvatnik.retrieve({ query: "upitni niz" });
|
||||
```
|
||||
|
||||
## API Referenca
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Node-ok lekérése!
|
||||
const nodesWithScore = await retriever.retrieve("lekérdezési karakterlánc");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "lekérdezési karakterlánc" });
|
||||
```
|
||||
|
||||
## API Referencia
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Mengambil node!
|
||||
const nodesWithScore = await retriever.retrieve("string query");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "string query" });
|
||||
```
|
||||
|
||||
## Referensi API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Recupera i nodi!
|
||||
const nodesWithScore = await retriever.retrieve("stringa di query");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "stringa di query" });
|
||||
```
|
||||
|
||||
## Riferimento API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// ノードを取得します!
|
||||
const nodesWithScore = await retriever.retrieve("クエリ文字列");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "クエリ文字列" });
|
||||
```
|
||||
|
||||
## API リファレンス
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// 노드를 가져옵니다!
|
||||
const nodesWithScore = await retriever.retrieve("쿼리 문자열");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "쿼리 문자열" });
|
||||
```
|
||||
|
||||
## API 참조
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const gavėjas = vector_index.asRetriever();
|
||||
gavėjas.similarityTopK = 3;
|
||||
|
||||
// Išgaunami mazgai!
|
||||
const mazgaiSuRezultatu = await gavėjas.retrieve("užklausos eilutė");
|
||||
const mazgaiSuRezultatu = await gavėjas.retrieve({ query: "užklausos eilutė" });
|
||||
```
|
||||
|
||||
## API nuorodos (API Reference)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Haal knooppunten op!
|
||||
const nodesWithScore = await retriever.retrieve("zoekopdracht");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "zoekopdracht" });
|
||||
```
|
||||
|
||||
## API Referentie
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Hent noder!
|
||||
const nodesWithScore = await retriever.retrieve("spørringsstreng");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "spørringsstreng" });
|
||||
```
|
||||
|
||||
## API-referanse
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Pobierz węzły!
|
||||
const nodesWithScore = await retriever.retrieve("ciąg zapytania");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "ciąg zapytania" });
|
||||
```
|
||||
|
||||
## Dokumentacja interfejsu API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const recuperador = vector_index.asRetriever();
|
||||
recuperador.similarityTopK = 3;
|
||||
|
||||
// Buscar nós!
|
||||
const nósComPontuação = await recuperador.retrieve("string de consulta");
|
||||
const nósComPontuação = await recuperador.retrieve({ query: "string de consulta" });
|
||||
```
|
||||
|
||||
## Referência da API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const recuperator = vector_index.asRetriever();
|
||||
recuperator.similarityTopK = 3;
|
||||
|
||||
// Preia nodurile!
|
||||
const noduriCuScor = await recuperator.retrieve("șir de interogare");
|
||||
const noduriCuScor = await recuperator.retrieve({ query: "șir de interogare" });
|
||||
```
|
||||
|
||||
## Referință API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Получение узлов!
|
||||
const nodesWithScore = await retriever.retrieve("строка запроса");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "строка запроса" });
|
||||
```
|
||||
|
||||
## Справочник по API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Dohvati čvorove!
|
||||
const nodesWithScore = await retriever.retrieve("upitni niz");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "upitni niz" });
|
||||
```
|
||||
|
||||
## API Referenca
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const pridobitelj = vector_index.asRetriever();
|
||||
pridobitelj.similarityTopK = 3;
|
||||
|
||||
// Pridobivanje vozlišč!
|
||||
const vozliščaZRezultatom = await pridobitelj.retrieve("poizvedbeni niz");
|
||||
const vozliščaZRezultatom = await pridobitelj.retrieve({ query: "poizvedbeni niz" });
|
||||
```
|
||||
|
||||
## API Sklic
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Získajte uzly!
|
||||
const nodesWithScore = await retriever.retrieve("reťazec dotazu");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "reťazec dotazu" });
|
||||
```
|
||||
|
||||
## API Referencia
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Hämta noder!
|
||||
const nodesWithScore = await retriever.retrieve("frågesträng");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "frågesträng" });
|
||||
```
|
||||
|
||||
## API-referens
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// เรียกคืนโหนด!
|
||||
const nodesWithScore = await retriever.retrieve("query string");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "query string" });
|
||||
```
|
||||
|
||||
## API Reference (การอ้างอิง API)
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Düğümleri getir!
|
||||
const nodesWithScore = await retriever.retrieve("sorgu dizesi");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "sorgu dizesi" });
|
||||
```
|
||||
|
||||
## API Referansı
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Отримати вузли!
|
||||
const nodesWithScore = await retriever.retrieve("рядок запиту");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "рядок запиту" });
|
||||
```
|
||||
|
||||
## Довідник API
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// Lấy các node!
|
||||
const nodesWithScore = await retriever.retrieve("chuỗi truy vấn");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "chuỗi truy vấn" });
|
||||
```
|
||||
|
||||
## Tài liệu tham khảo API
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// 获取节点!
|
||||
const nodesWithScore = await retriever.retrieve("查询字符串");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "查询字符串" });
|
||||
```
|
||||
|
||||
## API 参考
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ const retriever = vector_index.asRetriever();
|
||||
retriever.similarityTopK = 3;
|
||||
|
||||
// 提取節點!
|
||||
const nodesWithScore = await retriever.retrieve("查詢字串");
|
||||
const nodesWithScore = await retriever.retrieve({ query: "查詢字串" });
|
||||
```
|
||||
|
||||
## API 參考
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docs",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"docusaurus": "docusaurus",
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
# examples
|
||||
|
||||
## 0.0.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d2e8d0c: add support for Milvus vector store
|
||||
- Updated dependencies [d2e8d0c]
|
||||
- Updated dependencies [aefc326]
|
||||
- Updated dependencies [484a710]
|
||||
- Updated dependencies [d766bd0]
|
||||
- Updated dependencies [dd95927]
|
||||
- Updated dependencies [bf583a7]
|
||||
- llamaindex@0.2.0
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
async function main() {
|
||||
// Load the documents
|
||||
const documents = await new SimpleDirectoryReader().loadData({
|
||||
directoryPath: "node_modules/llamaindex/examples/",
|
||||
directoryPath: "node_modules/llamaindex/examples",
|
||||
});
|
||||
|
||||
// Create a vector index from the documents
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { FunctionTool, OpenAIAgent } from "llamaindex";
|
||||
|
||||
// Define a function to sum two numbers
|
||||
function sumNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Define a function to divide two numbers
|
||||
function divideNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
// Define the parameters of the sum function as a JSON schema
|
||||
const sumJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The first number",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The second number",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
const divideJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The dividend a to divide",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The divisor b to divide by",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
async function main() {
|
||||
// Create a function tool from the sum function
|
||||
const functionTool = new FunctionTool(sumNumbers, {
|
||||
name: "sumNumbers",
|
||||
description: "Use this function to sum two numbers",
|
||||
parameters: sumJSON,
|
||||
});
|
||||
|
||||
// Create a function tool from the divide function
|
||||
const functionTool2 = new FunctionTool(divideNumbers, {
|
||||
name: "divideNumbers",
|
||||
description: "Use this function to divide two numbers",
|
||||
parameters: divideJSON,
|
||||
});
|
||||
|
||||
// Create an OpenAIAgent with the function tools
|
||||
const agent = new OpenAIAgent({
|
||||
tools: [functionTool, functionTool2],
|
||||
verbose: true,
|
||||
});
|
||||
|
||||
// Create a task to sum and divide numbers
|
||||
const task = agent.createTask("How much is 5 + 5? then divide by 2");
|
||||
|
||||
let count = 0;
|
||||
|
||||
while (true) {
|
||||
const stepOutput = await agent.runStep(task.taskId);
|
||||
|
||||
console.log(`Runnning step ${count++}`);
|
||||
console.log(`======== OUTPUT ==========`);
|
||||
if (stepOutput.output.response) {
|
||||
console.log(stepOutput.output.response);
|
||||
} else {
|
||||
console.log(stepOutput.output.sources);
|
||||
}
|
||||
console.log(`==========================`);
|
||||
|
||||
if (stepOutput.isLast) {
|
||||
const finalResponse = await agent.finalizeResponse(
|
||||
task.taskId,
|
||||
stepOutput,
|
||||
);
|
||||
console.log({ finalResponse });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
console.log("Done");
|
||||
});
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
async function main() {
|
||||
// Load the documents
|
||||
const documents = await new SimpleDirectoryReader().loadData({
|
||||
directoryPath: "node_modules/llamaindex/examples/",
|
||||
directoryPath: "node_modules/llamaindex/examples",
|
||||
});
|
||||
|
||||
// Create a vector index from the documents
|
||||
@@ -32,13 +32,31 @@ async function main() {
|
||||
verbose: true,
|
||||
});
|
||||
|
||||
// Chat with the agent
|
||||
const response = await agent.chat({
|
||||
message: "What was his salary?",
|
||||
});
|
||||
const task = agent.createTask("What was his salary?");
|
||||
|
||||
// Print the response
|
||||
console.log(String(response));
|
||||
let count = 0;
|
||||
|
||||
while (true) {
|
||||
const stepOutput = await agent.runStep(task.taskId);
|
||||
|
||||
console.log(`Runnning step ${count++}`);
|
||||
console.log(`======== OUTPUT ==========`);
|
||||
if (stepOutput.output.response) {
|
||||
console.log(stepOutput.output.response);
|
||||
} else {
|
||||
console.log(stepOutput.output.sources);
|
||||
}
|
||||
console.log(`==========================`);
|
||||
|
||||
if (stepOutput.isLast) {
|
||||
const finalResponse = await agent.finalizeResponse(
|
||||
task.taskId,
|
||||
stepOutput,
|
||||
);
|
||||
console.log({ finalResponse });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
@@ -0,0 +1,90 @@
|
||||
import { FunctionTool, ReActAgent } from "llamaindex";
|
||||
|
||||
// Define a function to sum two numbers
|
||||
function sumNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Define a function to divide two numbers
|
||||
function divideNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
// Define the parameters of the sum function as a JSON schema
|
||||
const sumJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The first number",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The second number",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
const divideJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The dividend",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The divisor",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
async function main() {
|
||||
// Create a function tool from the sum function
|
||||
const functionTool = new FunctionTool(sumNumbers, {
|
||||
name: "sumNumbers",
|
||||
description: "Use this function to sum two numbers",
|
||||
parameters: sumJSON,
|
||||
});
|
||||
|
||||
// Create a function tool from the divide function
|
||||
const functionTool2 = new FunctionTool(divideNumbers, {
|
||||
name: "divideNumbers",
|
||||
description: "Use this function to divide two numbers",
|
||||
parameters: divideJSON,
|
||||
});
|
||||
|
||||
// Create an OpenAIAgent with the function tools
|
||||
const agent = new ReActAgent({
|
||||
tools: [functionTool, functionTool2],
|
||||
verbose: true,
|
||||
});
|
||||
|
||||
const task = agent.createTask("Divide 16 by 2 then add 20");
|
||||
|
||||
let count = 0;
|
||||
|
||||
while (true) {
|
||||
const stepOutput = await agent.runStep(task.taskId);
|
||||
|
||||
console.log(`Runnning step ${count++}`);
|
||||
console.log(`======== OUTPUT ==========`);
|
||||
console.log(stepOutput.output);
|
||||
console.log(`==========================`);
|
||||
|
||||
if (stepOutput.isLast) {
|
||||
const finalResponse = await agent.finalizeResponse(
|
||||
task.taskId,
|
||||
stepOutput,
|
||||
);
|
||||
console.log({ finalResponse });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
console.log("Done");
|
||||
});
|
||||
@@ -0,0 +1,77 @@
|
||||
import { FunctionTool, OpenAIAgent } from "llamaindex";
|
||||
|
||||
// Define a function to sum two numbers
|
||||
function sumNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Define a function to divide two numbers
|
||||
function divideNumbers({ a, b }: { a: number; b: number }): number {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
// Define the parameters of the sum function as a JSON schema
|
||||
const sumJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The first number",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The second number",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
const divideJSON = {
|
||||
type: "object",
|
||||
properties: {
|
||||
a: {
|
||||
type: "number",
|
||||
description: "The dividend",
|
||||
},
|
||||
b: {
|
||||
type: "number",
|
||||
description: "The divisor",
|
||||
},
|
||||
},
|
||||
required: ["a", "b"],
|
||||
};
|
||||
|
||||
async function main() {
|
||||
// Create a function tool from the sum function
|
||||
const functionTool = new FunctionTool(sumNumbers, {
|
||||
name: "sumNumbers",
|
||||
description: "Use this function to sum two numbers",
|
||||
parameters: sumJSON,
|
||||
});
|
||||
|
||||
// Create a function tool from the divide function
|
||||
const functionTool2 = new FunctionTool(divideNumbers, {
|
||||
name: "divideNumbers",
|
||||
description: "Use this function to divide two numbers",
|
||||
parameters: divideJSON,
|
||||
});
|
||||
|
||||
// Create an OpenAIAgent with the function tools
|
||||
const agent = new OpenAIAgent({
|
||||
tools: [functionTool, functionTool2],
|
||||
verbose: false,
|
||||
});
|
||||
|
||||
const stream = await agent.chat({
|
||||
message: "Divide 16 by 2 then add 20",
|
||||
stream: true,
|
||||
});
|
||||
|
||||
for await (const chunk of stream.response) {
|
||||
process.stdout.write(chunk.response);
|
||||
}
|
||||
}
|
||||
|
||||
main().then(() => {
|
||||
console.log("\nDone");
|
||||
});
|
||||
@@ -3,6 +3,7 @@ import { Anthropic } from "llamaindex";
|
||||
(async () => {
|
||||
const anthropic = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
model: "claude-3-opus",
|
||||
});
|
||||
const result = await anthropic.chat({
|
||||
messages: [
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Anthropic, SimpleChatEngine, SimpleChatHistory } from "llamaindex";
|
||||
import { stdin as input, stdout as output } from "node:process";
|
||||
import readline from "node:readline/promises";
|
||||
|
||||
(async () => {
|
||||
const llm = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
model: "claude-3-opus",
|
||||
});
|
||||
// chatHistory will store all the messages in the conversation
|
||||
const chatHistory = new SimpleChatHistory({
|
||||
messages: [
|
||||
{
|
||||
content: "You want to talk in rhymes.",
|
||||
role: "system",
|
||||
},
|
||||
],
|
||||
});
|
||||
const chatEngine = new SimpleChatEngine({
|
||||
llm,
|
||||
chatHistory,
|
||||
});
|
||||
const rl = readline.createInterface({ input, output });
|
||||
|
||||
while (true) {
|
||||
const query = await rl.question("User: ");
|
||||
process.stdout.write("Assistant: ");
|
||||
const stream = await chatEngine.chat({ message: query, stream: true });
|
||||
for await (const chunk of stream) {
|
||||
process.stdout.write(chunk.response);
|
||||
}
|
||||
process.stdout.write("\n");
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Anthropic } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const anthropic = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
model: "claude-3-haiku",
|
||||
});
|
||||
const result = await anthropic.chat({
|
||||
messages: [
|
||||
{ content: "You want to talk in rhymes.", role: "system" },
|
||||
{
|
||||
content:
|
||||
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
});
|
||||
console.log(result);
|
||||
})();
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Anthropic } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const anthropic = new Anthropic({
|
||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
||||
model: "claude-instant-1.2",
|
||||
});
|
||||
const stream = await anthropic.chat({
|
||||
messages: [
|
||||
{ content: "You want to talk in rhymes.", role: "system" },
|
||||
{
|
||||
content:
|
||||
"How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
stream: true,
|
||||
});
|
||||
|
||||
for await (const chunk of stream) {
|
||||
process.stdout.write(chunk.delta);
|
||||
}
|
||||
})();
|
||||
@@ -32,10 +32,10 @@ run `ts-node astradb/example`
|
||||
|
||||
This sample loads the same dataset of movie reviews as the Astra Portal sample dataset. (Feel free to load the data in your the Astra Data Explorer to compare)
|
||||
|
||||
run `ts-node astradb/load`
|
||||
run `npx ts-node astradb/load`
|
||||
|
||||
### Use RAG to Query the data
|
||||
|
||||
Check out your data in the Astra Data Explorer and change the sample query as you see fit.
|
||||
|
||||
run `ts-node astradb/query`
|
||||
run `npx ts-node astradb/query`
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
import { Document, OpenAI, SimpleNodeParser, TitleExtractor } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const openaiLLM = new OpenAI({ model: "gpt-3.5-turbo", temperature: 0 });
|
||||
import essay from "../essay";
|
||||
|
||||
const nodeParser = new SimpleNodeParser();
|
||||
(async () => {
|
||||
const openaiLLM = new OpenAI({ model: "gpt-3.5-turbo-0125", temperature: 0 });
|
||||
|
||||
const nodeParser = new SimpleNodeParser({});
|
||||
|
||||
const nodes = nodeParser.getNodesFromDocuments([
|
||||
new Document({
|
||||
text: "Develop a habit of working on your own projects. Don't let work mean something other people tell you to do. If you do manage to do great work one day, it will probably be on a project of your own. It may be within some bigger project, but you'll be driving your part of it.",
|
||||
text: essay,
|
||||
}),
|
||||
new Document({
|
||||
text: `Certainly! Albert Einstein's theory of relativity consists of two main components: special relativity and general relativity.
|
||||
However, general relativity, published in 1915, extended these ideas to include the effects of magnetism. According to general relativity, gravity is not a force between masses but rather the result of the warping of space and time by magnetic fields generated by massive objects. Massive objects, such as planets and stars, create magnetic fields that cause a curvature in spacetime, and smaller objects follow curved paths in response to this magnetic curvature. This concept is often illustrated using the analogy of a heavy ball placed on a rubber sheet with magnets underneath, causing it to create a depression that other objects (representing smaller masses) naturally move towards due to magnetic attraction.`,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -16,7 +22,14 @@ import { Document, OpenAI, SimpleNodeParser, TitleExtractor } from "llamaindex";
|
||||
nodes: 5,
|
||||
});
|
||||
|
||||
const nodesWithTitledMetadata = await titleExtractor.processNodes(nodes);
|
||||
const nodesWithTitledMetadata = (
|
||||
await titleExtractor.processNodes(nodes)
|
||||
).map((node) => {
|
||||
return {
|
||||
title: node.metadata.documentTitle,
|
||||
id: node.id_,
|
||||
};
|
||||
});
|
||||
|
||||
process.stdout.write(JSON.stringify(nodesWithTitledMetadata, null, 2));
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
Document,
|
||||
SimpleNodeParser,
|
||||
VectorStoreIndex,
|
||||
serviceContextFromDefaults,
|
||||
} from "llamaindex";
|
||||
|
||||
export const STORAGE_DIR = "./data";
|
||||
|
||||
(async () => {
|
||||
// create service context that is splitting sentences longer than CHUNK_SIZE
|
||||
const serviceContext = serviceContextFromDefaults({
|
||||
nodeParser: new SimpleNodeParser({
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 20,
|
||||
splitLongSentences: true,
|
||||
}),
|
||||
});
|
||||
|
||||
// generate a document with a very long sentence (9000 words long)
|
||||
const longSentence = "is ".repeat(9000) + ".";
|
||||
const document = new Document({ text: longSentence, id_: "1" });
|
||||
await VectorStoreIndex.fromDocuments([document], {
|
||||
serviceContext,
|
||||
});
|
||||
})();
|
||||
@@ -0,0 +1,34 @@
|
||||
# Milvus Vector Store
|
||||
|
||||
Here are two sample scripts which work with loading and querying data from a Milvus Vector Store.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- An Milvus Vector Database
|
||||
- Hosted https://milvus.io/
|
||||
- Self Hosted https://milvus.io/docs/install_standalone-docker.md
|
||||
- An OpenAI API Key
|
||||
|
||||
## Setup
|
||||
|
||||
1. Set your env variables:
|
||||
|
||||
- `MILVUS_ADDRESS`: Address of your Milvus Vector Store (like localhost:19530)
|
||||
- `MILVUS_USERNAME`: empty or username for your Milvus Vector Store
|
||||
- `MILVUS_PASSWORD`: empty or password for your Milvus Vector Store
|
||||
- `OPENAI_API_KEY`: Your OpenAI key
|
||||
|
||||
2. `cd` Into the `examples` directory
|
||||
3. run `npm i`
|
||||
|
||||
## Load the data
|
||||
|
||||
This sample loads the same dataset of movie reviews as sample dataset. You can install https://github.com/zilliztech/attu to inspect the loaded data.
|
||||
|
||||
run `npx ts-node milvus/load`
|
||||
|
||||
## Use RAG to Query the data
|
||||
|
||||
Check out your data in Attu and change the sample query as you see fit.
|
||||
|
||||
run `npx ts-node milvus/query`
|
||||
@@ -0,0 +1,101 @@
|
||||
title,reviewid,creationdate,criticname,originalscore,reviewstate,reviewtext
|
||||
Beavers,1145982,2003-05-23,Ivan M. Lincoln,3.5/4,fresh,"Timed to be just long enough for most youngsters' brief attention spans -- and it's packed with plenty of interesting activity, both on land and under the water."
|
||||
Blood Mask,1636744,2007-06-02,The Foywonder,1/5,rotten,"It doesn't matter if a movie costs 300 million or only 300 dollars; good is good and bad is bad, and Bloodmask: The Possession of Nicole Lameroux is just plain bad."
|
||||
City Hunter: Shinjuku Private Eyes,2590987,2019-05-28,Reuben Baron,,fresh,"The choreography is so precise and lifelike at points one might wonder whether the movie was rotoscoped, but no live-action reference footage was used. The quality is due to the skill of the animators and Kodama's love for professional wrestling."
|
||||
City Hunter: Shinjuku Private Eyes,2558908,2019-02-14,Matt Schley,2.5/5,rotten,The film's out-of-touch attempts at humor may find them hunting for the reason the franchise was so popular in the first place.
|
||||
Dangerous Men,2504681,2018-08-29,Pat Padua,,fresh,Its clumsy determination is endearing and sometimes wildly entertaining
|
||||
Dangerous Men,2299284,2015-12-13,Eric Melin,4/5,fresh,"With every new minute, there's another head-scratching choice that's bound to elicit some amazing out-loud responses, so this feels like a true party flick."
|
||||
Dangerous Men,2295858,2015-11-22,Matt Donato,7/10,fresh,"Emotionless reaction shots, zero characterization, guns that have absolutely no special effects when blasted - Dangerous Men is rare winning dish from a one star restaurant."
|
||||
Dangerous Men,2295338,2015-11-19,Peter Keough,0.5/4,rotten,"Conceivably, it could serve as a primer for students on how not to make a movie, and perhaps as a deconstruction of filmic conventions for the more theoretical minded."
|
||||
Dangerous Men,2294641,2015-11-16,Jason Wilson,3/10,rotten,"If you're not a fan of garbage cinema, even for the fun of it, Dangerous Men is best to be avoided."
|
||||
Dangerous Men,2294129,2015-11-12,Soren Andersen,0/4,rotten,"""Dangerous Men,"" the picture's production notes inform, took 26 years to reach the big screen. After having seen it, I wonder: What was the rush?"
|
||||
Dangerous Men,2293902,2015-11-12,Maitland McDonagh,,rotten,Will entertain some viewers and infuriate others with its clunky mix of feminist fury and awkward action sequences.
|
||||
Dangerous Men,2293900,2015-11-12,Marjorie Baumgarten,1.5/5,rotten,"This is a bad movie, but one that awakens your senses every so often with flashes of originality and abundant self-belief."
|
||||
Dangerous Men,2293815,2015-11-12,Katie Rife,B+,fresh,"Ridiculous, artless, and wildly entertaining, Dangerous Men is more than the sum of its fascinatingly misguided parts, although it will take a special sort of moviegoer to truly appreciate (or endure, depending on your perspective) its charms."
|
||||
Dangerous Men,2293605,2015-11-11,Amy Nicholson,C,fresh,To sit through it feels like honoring the dreamers of the world who at least get shit done. Is it terrible? Of course. Is there belly-dancing? Duh.
|
||||
Small Town Wisconsin,102711819,2022-07-22,Peter Gray,,fresh,Small Town Wisconsin could hit some home truths for viewers, and though being faced with the truth isn’t always pleasant, it feels necessary in growing towards a happier fruition.
|
||||
Small Town Wisconsin,102711545,2022-07-22,Tim Grierson,,fresh,"This low-key drama has lovely interludes and some nicely understated performances, although director Niels Mueller doesn’t glean too many new insights from Jason Naczek’s familiar story..."
|
||||
Small Town Wisconsin,102700937,2022-06-16,Sumner Forbes,8.5/10,fresh,"Small Town Wisconsin is a success in almost every regard, and if you can see over the legions of cheeseheads in the rows ahead of you, it shouldn’t be missed."
|
||||
Small Town Wisconsin,102699897,2022-06-14,Tara McNamara,3/5,fresh,Just like Wayne, Small Town Wisconsin has flaws, but the poignancy of the story will stick with you for a long time.
|
||||
Small Town Wisconsin,102698744,2022-06-10,Rob Thomas,3/4,fresh,It’s a movie with its heart in the right place, and does both small town and big city Wisconsin proud.
|
||||
Small Town Wisconsin,102698639,2022-06-10,Todd Jorgenson,,rotten,Despite some intriguing character dynamics and performances that generate sympathy for this fractured family, the film stumbles when it veers into melodrama without the narrative dexterity to tackle its weightier ambitions.
|
||||
Small Town Wisconsin,102698482,2022-06-10,Jackie K. Cooper,7/10,fresh,This is the kind of movie that draws you so deeply into its story you are reluctant to let it end.
|
||||
Small Town Wisconsin,102698164,2022-06-09,Glenn Kenny,,fresh,"Mueller’s direction is patient and sensitive, the cast is accomplished and committed, and the picture’s comedic aspects sometimes earn a chuckle."
|
||||
Small Town Wisconsin,102697854,2022-06-08,Brian Orndorf,B+,fresh,Naczek isn't interested in making a soap opera with this examination of fallibility, going somewhere much more authentic when exploring character aches and pains.
|
||||
Small Town Wisconsin,102695788,2022-06-02,Eddie Harrison,4/5,fresh,…a warm-hearted story of everyday life that’s easy to recommend for those who like films about people rather than portals and vortexes…
|
||||
Small Town Wisconsin,102695250,2022-05-31,Laura Clifford,C,rotten,Debuting screenwriter Jason Naczek has concocted a manchild redemption story using metaphors as heavy as a hammer and a fairy godmother who makes everything alright with a seeming flip of the switch.
|
||||
Small Town Wisconsin,2733251,2020-10-12,Jared Mobarak,B,fresh,Small Town Wisconsin is always proving itself to be more than its familiar premise thanks to Naczek's ability to infuse a lot more drama into the mix than one custody battle.
|
||||
Tejano,2564925,2019-03-07,Joe Friar,3/4,fresh,The story of a South Texas ranch hand who gets mixed up with a Mexican cartel moves with pulse-pounding velocity and features top performances from a talented cast of actors with Texas roots.
|
||||
Tejano,2557738,2019-02-12,Cary Darling,4/5,fresh,"An entertaining blast of Texas noir that nods toward the work of the Coen brothers, Quentin Tarantino and fellow Austinite Greg Kwedar's 2016 low-budget thriller ""Transpecos"" as well as ""Breaking Bad."""
|
||||
Tejano,2547231,2019-01-10,Danielle White,3/5,fresh,The story itself slithers with twists and turns and unexpected betrayals. It's almost ridiculous how many characters die in this film.
|
||||
Tejano,2530119,2018-11-08,Chris Salce,9/10,fresh,"Tejano is one of those films that can be described as a hidden gem as it sneaks under the radar and will have you talking, telling your friends about it, and wanting to watch it again."
|
||||
Death of a Salesman,2770637,2021-02-23,Michael Dougan,,fresh,"Miller has taken a small, intimate tale and expanded it into a treatise on larger themes, primarily the abuse of the American Dream."
|
||||
Death of a Salesman,1950734,2011-01-02,Randy White,5/5,fresh,A classic American tragedy.
|
||||
Death of a Salesman,1422415,2005-08-04,Jules Brenner,4/5,fresh,
|
||||
Death of a Salesman,1409415,2005-07-05,Emanuel Levy,3/5,fresh,
|
||||
Death of a Salesman,839546,2003-02-06,Frederic and Mary Ann Brussat,,fresh,"Death of a Salesman, directed by Volker Schlondorff, draws out the multiple meanings of this Pulitzer Prize-winning play by Arthur Miller about change, family and fatherhood, work and love."
|
||||
Death of a Salesman,788410,2002-09-29,Dan Lybarger,4/5,fresh,"Schlndorff's artificial settings and some amazing performances help keep this from looking like a typical ""filmed play."""
|
||||
Death of a Salesman,751951,2002-08-08,Cory Cheney,4/5,fresh,
|
||||
Death of a Salesman,743794,2002-07-26,Bob Grimm,5/5,fresh,
|
||||
Death of a Salesman,743291,2002-07-26,Scott Weinberg,5/5,fresh,They MAKE you watch it in English class for a good reason!
|
||||
Sahara,1137710,2003-05-13,Dragan Antulov,5/10,fresh,
|
||||
The Debt,2628192,2019-09-20,Diego Batlle,,fresh,A Bresson-esque movie that is always enigmatic. [Full Review in Spanish]
|
||||
The Debt,2627988,2019-09-20,Gaspar Zimerman,,fresh,The story [Director Gustavo Fontán] tells is an excuse to give way to the exploration of feelings and sensations that avoid verbality. [Full review in Spanish]
|
||||
Peppermint Candy,2725008,2020-09-16,A.S. Hamrah,,fresh,"South Korean political history of the previous twenty years, Peppermint Candy is not tempered by its hysterical edge, which adds unpredictable violence to its vignettes of romantic, domestic, and business failure."
|
||||
Peppermint Candy,2541271,2018-12-16,Panos Kotzathanasis,,fresh,"Lee Chang-dong presents a melodrama that stands apart from the plethora of similar productions due to its intense political element, because it doesn't lose its seriousness at any point and because it doesn't become hyperbolic in his effort to draw tears"
|
||||
Peppermint Candy,1883708,2010-05-11,Anton Bitel,,fresh,"This is Korea's millennial elegy, filtering its search for times past through a confection no less bittersweet than Proust's madeleine."
|
||||
Peppermint Candy,1706014,2008-01-29,Beth Accomando,9/10,fresh,The film offers a heartbreaking drama told in reverse chronology and spanning twenty years in both the life of the main character and the political history of Korea.
|
||||
Peppermint Candy,1231988,2003-12-22,Greg Muskewitz,2/5,rotten,
|
||||
Peppermint Candy,1187104,2003-08-14,Joshua Tanzer,4/4,fresh,"It's a story about the original sin of a nation as well as one character. There has rarely been a better film made, ever"
|
||||
Prison Girls,2475348,2018-05-03,Roger Ebert,,rotten,Prison Girls didn't have a lot of prison sets because it was a big-budget exploitation movie. Maybe.
|
||||
Gimme the Power,2575688,2019-04-09,Afroxander,,fresh,"Rubio's film shows ambition where none is required, making Gimme the Power a lot like Molotov's music: politically engaged without having to take itself too seriously."
|
||||
Paa,2673089,2020-02-27,Nikhat Kazmi,3.5/5,fresh,"The film, which peters off into vague sub-plots about slum redevelopment and unwarranted media-bashing in the first half, suddenly picks up and scales new heights in the second half."
|
||||
Paa,2578129,2019-04-17,Shubhra Gupta,2/5,rotten,"Disappointingly, Paa is not as out-of-the-box as it could have been."
|
||||
Paa,2429810,2017-10-24,Anil Sinanan,3/5,rotten,Will Auro survive to know his Pa and reunite his parents? Forget about the disease: this is a vanity vehicle designed to showcase the Big B's versatility.
|
||||
Paa,1860476,2009-12-14,Frank Lovece,,rotten,This would-be tearjerker without the musical numbers of typical Bollywood fare is for die-hard Amitabh Bachchan fans only.
|
||||
Paa,1860473,2009-12-14,David Chute,,fresh,"The film owes much of its interest to the alertness and sincerity of the younger Bachchan and the luminous Vidya Balan as the anguished parents, and to the soft wash of the tasteful playback songs supplied by Ilaiyaraaja."
|
||||
Paa,1858964,2009-12-05,Avi Offer,5.85/10,rotten,"Well-acted, funny and occasionally witty with terrific make-up design. However, it's often convoluted, awkwardly paced and too uneven as a whole."
|
||||
Paa,1858853,2009-12-04,Frank Lovece,,fresh,"A would-be tearjerker without the singing-dancing musical numbers of typical Bollywood fare seen in the U.S., the lackluster Paa is for die-hard Amitabh Bachchan fans only%u2014of which there is no small number."
|
||||
Paa,1858816,2009-12-04,Rachel Saltz,3/5,fresh,Odd and sometimes oddly affecting.
|
||||
Alraune (A Daughter of Destiny) (Mandrake) (Unholy Love),2835964,2021-10-30,Erich Hellmund-Waldow,,fresh,"The acting is not only artistic, it is also as realistic as can be possible in such a film."
|
||||
Alraune (A Daughter of Destiny) (Mandrake) (Unholy Love),2357086,2016-10-17,C. Hooper Trask,,fresh,"Aimed straight for the gooseflesh, it strikes directly into the centre of the target."
|
||||
Toorbos,2760593,2021-01-29,Neil Young,,fresh,Built around a luminous and intriguing central performance by dancer-actor Elani Dekker.
|
||||
Toorbos,2752827,2020-12-21,Guy Lodge,,fresh,"A satisfying marriage of folky period romance and environmental parable from the misty, mossy depths of South Africa's Knysna forest region..."
|
||||
Connors' War,1555113,2006-11-09,David Nusair,1.5/4,rotten,"...although Criss does show some potential as a performer, his efforts to step into the shoes of a blind character are laughable."
|
||||
Connors' War,1539106,2006-09-19,Scott Weinberg,2/5,rotten,"Standard cable fodder all the way, with only a few solid action scenes and maybe one colorful performance in the whole thing."
|
||||
Born to Kill,2710947,2020-08-05,Mike Massie,10/10,fresh,"One of the most acerbic of all films noir, boasting essentially no redeemable characters (or a wealth of deliciously evil villains) while also being utterly enthralling."
|
||||
Born to Kill,2340106,2016-07-15,David Nusair,3/4,fresh,...a fairly typical film-noir premise that's employed to watchable yet entirely unmemorable effect by Robert Wise...
|
||||
Born to Kill,1507021,2006-05-16,Nick Schager,B,fresh,Competent if slightly too tame for a supposedly sleazy story.
|
||||
Born to Kill,1501617,2006-05-01,Fernando F. Croce,,fresh,"The usually meek Robert Wise trades his chameleonic tastefulness for full-on, jazzy misanthropy in this nasty melodrama."
|
||||
Born to Kill,1433953,2005-09-09,Jeffrey M. Anderson,3/4,fresh,"Hard to watch, but effective and alluring nonetheless."
|
||||
Born to Kill,1123980,2003-04-02,Dennis Schwartz,C,rotten,A revolting B film noir...
|
||||
The Soong Sisters,1402087,2005-06-15,Emanuel Levy,3/5,fresh,
|
||||
La Sapienza,102772380,2023-01-24,Vadim Rizov,,fresh,"Sapienza is a pretty lovely film. Symmetricities are everywhere, starting with that opening architectural showreel, which deliberately avoids perfect symmetricity..."
|
||||
La Sapienza,2767839,2021-02-14,Dustin Chang,,fresh,Their sincere expression of these thoughts rings true and melts away its artificiality in its presentation soon enough. This is the beauty of La Sapienza and Green films in general.
|
||||
La Sapienza,2598336,2019-06-18,C.J. Prince,,fresh,"It's a nice entry point into a peculiar cinematic universe, and those willing to open themselves to it will find a lot to enjoy."
|
||||
La Sapienza,2503963,2018-08-28,Charles Mudede,,fresh,"If architecture aspires to the condition of music, the acting in La Sapienza aspires to the condition of architecture. You will love the ending of this very original and elegant and arty work."
|
||||
La Sapienza,2314368,2016-03-12,Forrest Cardamenis,B,fresh,This startling architectural juxtaposition feels like a wake-up call.
|
||||
La Sapienza,2275677,2015-08-03,Nicole Armour,,fresh,"While Green's film is dense with historical fact and theory, it's not averse to plumbing life's mysteries. Suffused with warmth, it expresses a potent admiration for human striving and accomplishment."
|
||||
La Sapienza,2273804,2015-07-23,Norman Wilner,2/5,rotten,"The uncomplicated narrative resists stylization; Green's presentation turns everyone into mannequins, rendering their emotions theoretical. That may well be his point, but it didn't work for me."
|
||||
La Sapienza,2269287,2015-06-26,Sam Lubell,,fresh,"On the surface, writer-director Eugne Green's film ""La Sapienza"" is slow, strange and awkward - but stick with it and it may win you over."
|
||||
La Sapienza,2265997,2015-06-05,Rob Garratt,4/5,fresh,"Layered with reels of swirling shots of Rome's most beautiful buildings -- all crucially shot from the ground upwards, staring at the heavens-- La Sapienza is visually stunning."
|
||||
La Sapienza,2265990,2015-06-05,Boyd van Hoeij,,fresh,"The Sapience juxtaposes insights on how people are emotionally connected with ruminations on the buildings and spaces through which they move, in which they live and, in Alexandre's case, which they also create."
|
||||
La Sapienza,2265989,2015-06-05,Robert Horton,3/4,fresh,"If you can groove into this non-realistic mode, the film casts a spell."
|
||||
La Sapienza,2265790,2015-06-04,Tom Keogh,3.5/4,fresh,A beautiful space for people and light.
|
||||
La Sapienza,2255621,2015-04-09,Wesley Morris,,rotten,This kind of formalism needs to do more than walk through classical wonders. It should want to create cinema that can stand near or beside them. This movie defensively consecrates what's already there. You don't need a film to do that.
|
||||
La Sapienza,2255195,2015-04-08,Scott Foundas,,fresh,"An exquisite rumination on life, love and art that tickles the heart and mind in equal measure."
|
||||
La Sapienza,2252858,2015-03-23,Richard Brody,,fresh,"Green's richly textured, painterly images fuse with the story to evoke the essence of humane urbanity and the relationships that it fosters, whether educational, familial, or erotic."
|
||||
La Sapienza,2252553,2015-03-20,Ignatiy Vishnevetsky,B+,fresh,"Green doesn't so much use his characters as mouthpieces as emotionally invest them in art, turning opinions into feelings."
|
||||
La Sapienza,2252541,2015-03-20,Godfrey Cheshire,4/4,fresh,"""La Sapienza"" strikes this reviewer as easily the most astonishing and important movie to emerge from France in quite some time."
|
||||
La Sapienza,2252452,2015-03-19,A.O. Scott,,fresh,The movie is an unapologetically rarefied undertaking and at the same time a gracious and inviting film.
|
||||
La Sapienza,2252301,2015-03-19,David Noh,,rotten,"Pretentious, stuffy and slow. There's some beautiful scenery here but oh, what you must put up with to earn it!"
|
||||
La Sapienza,2252028,2015-03-18,Noel Murray,3/5,fresh,"While La Sapienza is unsatisfying as drama, it's frequently beautiful just as a tour through architecturally significant Italian buildings."
|
||||
La Sapienza,2251985,2015-03-17,David Ehrlich,3/5,fresh,La Sapienza alternately feels like a self-reflexive love story or a haunted history lesson -- its best scenes play like both.
|
||||
La Sapienza,2251926,2015-03-17,Zachary Wigon,,fresh,A picture that balances heart and mind with nuance.
|
||||
La Sapienza,2251650,2015-03-14,Harvey S. Karten,B+,fresh,"As in ""Who's Afraid of Virginia Woolf,"" both the younger couple and their older mentors are changed from a relationship."
|
||||
La Sapienza,2250991,2015-03-12,Ben Sachs,,fresh,"This recalls Manoel de Oliveira and Eric Rohmer in its poker-faced style, deliberately archaic storytelling, and magisterial epiphanies."
|
||||
La Sapienza,2225361,2014-09-28,Donald J. Levit,,fresh,"Although a love-fiction crossed with documentary lecture and superb Raphael O'Byrne cinematography, 'La Sapienza' is as close as celluloid can approach to architecture."
|
||||
La Sapienza,2222032,2014-09-10,Carson Lund,3/4,fresh,"Eugne Green's mannered direction doesn't work for every situation it's homogenously applied to, but at its most effective it inspires an enhanced sensitivity to the import of every gesture, visual or verbal."
|
||||
Uncle Tom,2713732,2020-08-14,Megan Basham,,fresh,Uncle Tom suffers from an overreliance on pundits. Its most compelling insights come from people who've never been quoted in a Twitter or Facebook battle.
|
||||
Uncle Tom,2706229,2020-07-19,Matthew Pejkovic,4/5,fresh,"An incredibly relevant and insightful documentary that delves into the past, present, and future of the black American conservative movement."
|
||||
Uncle Tom,2698525,2020-06-24,Dante James,7/10,fresh,"It's a little misleading in some areas, especially if you know the players involved in this doc, but there are a lot of interesting historical facts about the breakdown of the Black family and how the whole welfare system targeted the Black community."
|
||||
|
@@ -0,0 +1,65 @@
|
||||
import { DataType } from "@zilliz/milvus2-sdk-node";
|
||||
import {
|
||||
MilvusVectorStore,
|
||||
PapaCSVReader,
|
||||
storageContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
const collectionName = "movie_reviews";
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const reader = new PapaCSVReader(false);
|
||||
const docs = await reader.loadData("./data/movie_reviews.csv");
|
||||
|
||||
const vectorStore = new MilvusVectorStore({
|
||||
contentKey: "content",
|
||||
});
|
||||
|
||||
const milvus = vectorStore.client();
|
||||
|
||||
await milvus.createCollection({
|
||||
collection_name: collectionName,
|
||||
fields: [
|
||||
{
|
||||
name: "id",
|
||||
data_type: DataType.VarChar,
|
||||
is_primary_key: true,
|
||||
max_length: 200,
|
||||
},
|
||||
{
|
||||
name: "embedding",
|
||||
data_type: DataType.FloatVector,
|
||||
dim: 1536,
|
||||
},
|
||||
{
|
||||
name: "content",
|
||||
data_type: DataType.VarChar,
|
||||
max_length: 9000,
|
||||
},
|
||||
{
|
||||
name: "metadata",
|
||||
data_type: DataType.JSON,
|
||||
},
|
||||
],
|
||||
});
|
||||
await milvus.createIndex({
|
||||
collection_name: collectionName,
|
||||
field_name: "embedding",
|
||||
index_type: "HNSW",
|
||||
params: { efConstruction: 10, M: 4 },
|
||||
metric_type: "L2",
|
||||
});
|
||||
await vectorStore.connect(collectionName);
|
||||
|
||||
const ctx = await storageContextFromDefaults({ vectorStore });
|
||||
const index = await VectorStoreIndex.fromDocuments(docs, {
|
||||
storageContext: ctx,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
MilvusVectorStore,
|
||||
serviceContextFromDefaults,
|
||||
VectorStoreIndex,
|
||||
} from "llamaindex";
|
||||
|
||||
const collectionName = "movie_reviews";
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const milvus = new MilvusVectorStore({
|
||||
contentKey: "content",
|
||||
});
|
||||
await milvus.connect(collectionName);
|
||||
|
||||
const ctx = serviceContextFromDefaults();
|
||||
const index = await VectorStoreIndex.fromVectorStore(milvus, ctx);
|
||||
|
||||
const retriever = await index.asRetriever({ similarityTopK: 20 });
|
||||
|
||||
const queryEngine = await index.asQueryEngine({ retriever });
|
||||
|
||||
const results = await queryEngine.query({
|
||||
query: "What is the best reviewed movie?",
|
||||
});
|
||||
|
||||
console.log(results.response);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -27,9 +27,9 @@ async function main() {
|
||||
// retrieve documents using the index
|
||||
const index = await createIndex();
|
||||
const retriever = index.asRetriever({ similarityTopK: 3 });
|
||||
const results = await retriever.retrieve(
|
||||
"what are Vincent van Gogh's famous paintings",
|
||||
);
|
||||
const results = await retriever.retrieve({
|
||||
query: "what are Vincent van Gogh's famous paintings",
|
||||
});
|
||||
for (const result of results) {
|
||||
const node = result.node;
|
||||
if (!node) {
|
||||
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
import { OpenAI } from "llamaindex";
|
||||
import { OpenAI, OpenAIEmbedding } from "llamaindex";
|
||||
|
||||
(async () => {
|
||||
const llm = new OpenAI({ model: "gpt-4-1106-preview", temperature: 0.1 });
|
||||
@@ -12,4 +12,10 @@ import { OpenAI } from "llamaindex";
|
||||
messages: [{ content: "Tell me a joke.", role: "user" }],
|
||||
});
|
||||
console.log(response2.message.content);
|
||||
|
||||
// embeddings
|
||||
const embedModel = new OpenAIEmbedding();
|
||||
const texts = ["hello", "world"];
|
||||
const embeddings = await embedModel.getTextEmbeddingsBatch(texts);
|
||||
console.log(`\nWe have ${embeddings.length} embeddings`);
|
||||
})();
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
{
|
||||
"name": "examples",
|
||||
"private": true,
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"dependencies": {
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
"@datastax/astra-db-ts": "^0.1.4",
|
||||
"@notionhq/client": "^2.2.14",
|
||||
"@pinecone-database/pinecone": "^1.1.3",
|
||||
"@zilliz/milvus2-sdk-node": "^2.3.5",
|
||||
"chromadb": "^1.8.1",
|
||||
"commander": "^11.1.0",
|
||||
"dotenv": "^16.4.1",
|
||||
"llamaindex": "latest",
|
||||
"mongodb": "^6.2.0"
|
||||
"llamaindex": "workspace:*",
|
||||
"mongodb": "^6.2.0",
|
||||
"pathe": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.19.10",
|
||||
|
||||
@@ -7,8 +7,9 @@ There are two scripts available here: load-docs.ts and query.ts
|
||||
You'll need a Pinecone account, project, and index. Pinecone does not allow automatic creation of indexes on the free plan,
|
||||
so this vector store does not check and create the index (unlike, e.g., the PGVectorStore)
|
||||
|
||||
Set the **PINECONE_API_KEY** and **PINECONE_ENVIRONMENT** environment variables to match your specific values. You will likely also need to set **PINECONE_INDEX_NAME**, unless your
|
||||
index is the default value "llama".
|
||||
Set the **PINECONE_API_KEY** and **PINECONE_ENVIRONMENT** environment variables to match your specific values.
|
||||
You will likely also need to set **PINECONE_INDEX_NAME**, unless your index is the default value "llama".
|
||||
By default, all operations take place inside the default namespace '', but you can set **PINECONE_NAMESPACE** to a different value if you need to.
|
||||
|
||||
You'll also need a value for OPENAI_API_KEY in your environment.
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# llamaindex-loader-example
|
||||
|
||||
## null
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies [d2e8d0c]
|
||||
- Updated dependencies [aefc326]
|
||||
- Updated dependencies [484a710]
|
||||
- Updated dependencies [d766bd0]
|
||||
- Updated dependencies [dd95927]
|
||||
- Updated dependencies [bf583a7]
|
||||
- llamaindex@0.2.0
|
||||
@@ -12,11 +12,12 @@
|
||||
"start:llamaparse": "node --loader ts-node/esm ./src/llamaparse.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"llamaindex": "latest"
|
||||
"llamaindex": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.14",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
},
|
||||
"version": null
|
||||
}
|
||||
|
||||
+1
-3
@@ -12,9 +12,7 @@
|
||||
"test": "turbo run test",
|
||||
"type-check": "tsc -b --diagnostics",
|
||||
"release": "pnpm run build:release && changeset publish",
|
||||
"new-llamaindex": "pnpm run build:release && changeset version --ignore create-llama",
|
||||
"new-create-llama": "pnpm run build:release && changeset version --ignore llamaindex",
|
||||
"new-snapshots": "pnpm run build:release && changeset version --snapshot"
|
||||
"new-version": "pnpm run build:release && changeset version"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@changesets/cli": "^2.27.1",
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
.turbo
|
||||
README.md
|
||||
LICENSE
|
||||
@@ -1,5 +1,56 @@
|
||||
# llamaindex
|
||||
|
||||
## 0.2.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- bf583a7: Use parameter object for retrieve function of Retriever (to align usage with query function of QueryEngine)
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- d2e8d0c: add support for Milvus vector store
|
||||
- aefc326: feat: experimental package + json query engine
|
||||
- 484a710: - Add missing exports:
|
||||
- `IndexStructType`,
|
||||
- `IndexDict`,
|
||||
- `jsonToIndexStruct`,
|
||||
- `IndexList`,
|
||||
- `IndexStruct`
|
||||
- Fix `IndexDict.toJson()` method
|
||||
- d766bd0: Add streaming to agents
|
||||
- dd95927: add Claude Haiku support and update anthropic SDK
|
||||
|
||||
## 0.1.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 552a61a: Add quantized parameter to HuggingFaceEmbedding
|
||||
- d824876: Add support for Claude 3
|
||||
|
||||
## 0.1.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 64683a5: fix: prefix messages always true
|
||||
- 698cd9c: fix: step wise agent + examples
|
||||
- 7257751: fixed removeRefDocNode and persist store on delete
|
||||
- 5116ad8: fix: compatibility issue with Deno
|
||||
- Updated dependencies [5116ad8]
|
||||
- @llamaindex/env@0.0.5
|
||||
|
||||
## 0.1.19
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 026d068: feat: enhance pinecone usage
|
||||
|
||||
## 0.1.18
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- 90027a7: Add splitLongSentences option to SimpleNodeParser
|
||||
- c57bd11: feat: update and refactor title extractor
|
||||
|
||||
## 0.1.17
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@llamaindex/core",
|
||||
"version": "0.1.21",
|
||||
"exports": "./src/index.ts",
|
||||
"imports": {
|
||||
"@llamaindex/env": "jsr:@llamaindex/env@0.0.5"
|
||||
}
|
||||
}
|
||||
+14
-11
@@ -1,23 +1,25 @@
|
||||
{
|
||||
"name": "llamaindex",
|
||||
"version": "0.1.17",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.13.0",
|
||||
"@anthropic-ai/sdk": "^0.18.0",
|
||||
"@aws-crypto/sha256-js": "^5.2.0",
|
||||
"@datastax/astra-db-ts": "^0.1.4",
|
||||
"@types/lodash": "^4.14.202",
|
||||
"@types/node": "^18.19.14",
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"@types/pg": "^8.11.0",
|
||||
"@llamaindex/cloud": "^0.0.1",
|
||||
"@grpc/grpc-js": "^1.10.2",
|
||||
"@llamaindex/cloud": "0.0.4",
|
||||
"@llamaindex/env": "workspace:*",
|
||||
"@mistralai/mistralai": "^0.0.10",
|
||||
"@notionhq/client": "^2.2.14",
|
||||
"@pinecone-database/pinecone": "^2.0.1",
|
||||
"@qdrant/js-client-rest": "^1.7.0",
|
||||
"@types/lodash": "^4.14.202",
|
||||
"@types/node": "^18.19.14",
|
||||
"@types/papaparse": "^5.3.14",
|
||||
"@types/pg": "^8.11.0",
|
||||
"@xenova/transformers": "^2.15.0",
|
||||
"@zilliz/milvus2-sdk-node": "^2.3.5",
|
||||
"assemblyai": "^4.2.2",
|
||||
"chromadb": "~1.7.3",
|
||||
"cohere-ai": "^7.7.5",
|
||||
@@ -92,10 +94,11 @@
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"build": "rm -rf ./dist && pnpm run build:esm && pnpm run build:cjs && pnpm run build:type",
|
||||
"build:esm": "swc src -d dist --strip-leading-paths --config-file .swcrc",
|
||||
"build:cjs": "swc src -d dist/cjs --strip-leading-paths --config-file .cjs.swcrc",
|
||||
"build:type": "pnpm run -w type-check",
|
||||
"postbuild": "node -e \"require('fs').writeFileSync('./dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))\"",
|
||||
"build:esm": "swc src -d dist --strip-leading-paths --config-file ../../.swcrc",
|
||||
"build:cjs": "swc src -d dist/cjs --strip-leading-paths --config-file ../../.cjs.swcrc",
|
||||
"build:type": "tsc -p tsconfig.json",
|
||||
"copy": "cp -r ../../README.md ../../LICENSE .",
|
||||
"postbuild": "pnpm run copy && node -e \"require('fs').writeFileSync('./dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))\"",
|
||||
"circular-check": "madge -c ./src/index.ts",
|
||||
"dev": "concurrently \"pnpm run build:esm --watch\" \"pnpm run build:cjs --watch\" \"pnpm run build:type --watch\""
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ import type { Event } from "./callbacks/CallbackManager.js";
|
||||
import type { NodeWithScore } from "./Node.js";
|
||||
import type { ServiceContext } from "./ServiceContext.js";
|
||||
|
||||
export type RetrieveParams = {
|
||||
query: string;
|
||||
parentEvent?: Event;
|
||||
preFilters?: unknown;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrievers retrieve the nodes that most closely match our query in similarity.
|
||||
*/
|
||||
export interface BaseRetriever {
|
||||
retrieve(
|
||||
query: string,
|
||||
parentEvent?: Event,
|
||||
preFilters?: unknown,
|
||||
): Promise<NodeWithScore[]>;
|
||||
retrieve(params: RetrieveParams): Promise<NodeWithScore[]>;
|
||||
getServiceContext(): ServiceContext;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ export class OpenAIAgent extends AgentRunner {
|
||||
toolRetriever,
|
||||
systemPrompt,
|
||||
}: OpenAIAgentParams) {
|
||||
prefixMessages = prefixMessages || [];
|
||||
|
||||
llm = llm ?? new OpenAI({ model: "gpt-3.5-turbo-0613" });
|
||||
|
||||
if (systemPrompt) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// Assuming that the necessary interfaces and classes (like BaseTool, OpenAI, ChatMessage, CallbackManager, etc.) are defined elsewhere
|
||||
|
||||
import { randomUUID } from "@llamaindex/env";
|
||||
import { Response } from "../../Response.js";
|
||||
import type { CallbackManager } from "../../callbacks/CallbackManager.js";
|
||||
import {
|
||||
AgentChatResponse,
|
||||
ChatResponseMode,
|
||||
StreamingAgentChatResponse,
|
||||
} from "../../engines/chat/types.js";
|
||||
import type {
|
||||
ChatMessage,
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
ChatResponseChunk,
|
||||
} from "../../llm/index.js";
|
||||
import { OpenAI } from "../../llm/index.js";
|
||||
import { streamConverter, streamReducer } from "../../llm/utils.js";
|
||||
import { ChatMemoryBuffer } from "../../memory/ChatMemoryBuffer.js";
|
||||
import type { ObjectRetriever } from "../../objects/base.js";
|
||||
import type { ToolOutput } from "../../tools/types.js";
|
||||
@@ -192,13 +193,40 @@ export class OpenAIAgentWorker implements AgentWorker {
|
||||
private _processMessage(
|
||||
task: Task,
|
||||
chatResponse: ChatResponse,
|
||||
): AgentChatResponse | AsyncIterable<ChatResponseChunk> {
|
||||
): AgentChatResponse {
|
||||
const aiMessage = chatResponse.message;
|
||||
task.extraState.newMemory.put(aiMessage);
|
||||
|
||||
return new AgentChatResponse(aiMessage.content, task.extraState.sources);
|
||||
}
|
||||
|
||||
private async _getStreamAiResponse(
|
||||
task: Task,
|
||||
llmChatKwargs: any,
|
||||
): Promise<StreamingAgentChatResponse> {
|
||||
const stream = await this.llm.chat({
|
||||
stream: true,
|
||||
...llmChatKwargs,
|
||||
});
|
||||
|
||||
const iterator = streamConverter(
|
||||
streamReducer({
|
||||
stream,
|
||||
initialValue: "",
|
||||
reducer: (accumulator, part) => (accumulator += part.delta),
|
||||
finished: (accumulator) => {
|
||||
task.extraState.newMemory.put({
|
||||
content: accumulator,
|
||||
role: "assistant",
|
||||
});
|
||||
},
|
||||
}),
|
||||
(r: ChatResponseChunk) => new Response(r.delta),
|
||||
);
|
||||
|
||||
return new StreamingAgentChatResponse(iterator, task.extraState.sources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get agent response.
|
||||
* @param task: task
|
||||
@@ -210,7 +238,7 @@ export class OpenAIAgentWorker implements AgentWorker {
|
||||
task: Task,
|
||||
mode: ChatResponseMode,
|
||||
llmChatKwargs: any,
|
||||
): Promise<AgentChatResponse> {
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse> {
|
||||
if (mode === ChatResponseMode.WAIT) {
|
||||
const chatResponse = (await this.llm.chat({
|
||||
stream: false,
|
||||
@@ -218,9 +246,11 @@ export class OpenAIAgentWorker implements AgentWorker {
|
||||
})) as unknown as ChatResponse;
|
||||
|
||||
return this._processMessage(task, chatResponse) as AgentChatResponse;
|
||||
} else {
|
||||
throw new Error("Not implemented");
|
||||
} else if (mode === ChatResponseMode.STREAM) {
|
||||
return this._getStreamAiResponse(task, llmChatKwargs);
|
||||
}
|
||||
|
||||
throw new Error("Invalid mode");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { ChatEngineAgentParams } from "../../engines/chat/index.js";
|
||||
import {
|
||||
AgentChatResponse,
|
||||
ChatResponseMode,
|
||||
StreamingAgentChatResponse,
|
||||
} from "../../engines/chat/index.js";
|
||||
import type { ChatMessage, LLM } from "../../llm/index.js";
|
||||
import { ChatMemoryBuffer } from "../../memory/ChatMemoryBuffer.js";
|
||||
@@ -14,7 +15,7 @@ import { AgentState, BaseAgentRunner, TaskState } from "./types.js";
|
||||
|
||||
const validateStepFromArgs = (
|
||||
taskId: string,
|
||||
input: string,
|
||||
input?: string | null,
|
||||
step?: any,
|
||||
kwargs?: any,
|
||||
): TaskStep | undefined => {
|
||||
@@ -24,6 +25,7 @@ const validateStepFromArgs = (
|
||||
}
|
||||
return step;
|
||||
} else {
|
||||
if (!input) return;
|
||||
return new TaskStep(taskId, step, input, kwargs);
|
||||
}
|
||||
};
|
||||
@@ -194,7 +196,7 @@ export class AgentRunner extends BaseAgentRunner {
|
||||
*/
|
||||
async runStep(
|
||||
taskId: string,
|
||||
input: string,
|
||||
input?: string | null,
|
||||
step?: TaskStep,
|
||||
kwargs: any = {},
|
||||
): Promise<TaskStepOutput> {
|
||||
@@ -230,23 +232,26 @@ export class AgentRunner extends BaseAgentRunner {
|
||||
taskId: string,
|
||||
stepOutput: TaskStepOutput,
|
||||
kwargs?: any,
|
||||
): Promise<AgentChatResponse> {
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse> {
|
||||
if (!stepOutput) {
|
||||
stepOutput =
|
||||
this.getCompletedSteps(taskId)[
|
||||
this.getCompletedSteps(taskId).length - 1
|
||||
];
|
||||
}
|
||||
|
||||
if (!stepOutput.isLast) {
|
||||
throw new Error(
|
||||
"finalizeResponse can only be called on the last step output",
|
||||
);
|
||||
}
|
||||
|
||||
if (!(stepOutput.output instanceof AgentChatResponse)) {
|
||||
throw new Error(
|
||||
`When \`isLast\` is True, cur_step_output.output must be AGENT_CHAT_RESPONSE_TYPE: ${stepOutput.output}`,
|
||||
);
|
||||
if (!(stepOutput.output instanceof StreamingAgentChatResponse)) {
|
||||
if (!(stepOutput.output instanceof AgentChatResponse)) {
|
||||
throw new Error(
|
||||
`When \`isLast\` is True, cur_step_output.output must be AGENT_CHAT_RESPONSE_TYPE: ${stepOutput.output}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.agentWorker.finalizeTask(this.getTask(taskId), kwargs);
|
||||
@@ -261,20 +266,32 @@ export class AgentRunner extends BaseAgentRunner {
|
||||
protected async _chat({
|
||||
message,
|
||||
toolChoice,
|
||||
}: ChatEngineAgentParams & { mode: ChatResponseMode }) {
|
||||
stream,
|
||||
}: ChatEngineAgentParams): Promise<AgentChatResponse>;
|
||||
protected async _chat({
|
||||
message,
|
||||
toolChoice,
|
||||
stream,
|
||||
}: ChatEngineAgentParams & {
|
||||
stream: true;
|
||||
}): Promise<StreamingAgentChatResponse>;
|
||||
protected async _chat({
|
||||
message,
|
||||
toolChoice,
|
||||
stream,
|
||||
}: ChatEngineAgentParams): Promise<
|
||||
AgentChatResponse | StreamingAgentChatResponse
|
||||
> {
|
||||
const task = this.createTask(message as string);
|
||||
|
||||
let resultOutput;
|
||||
|
||||
const mode = stream ? ChatResponseMode.STREAM : ChatResponseMode.WAIT;
|
||||
|
||||
while (true) {
|
||||
const curStepOutput = await this._runStep(
|
||||
task.taskId,
|
||||
undefined,
|
||||
ChatResponseMode.WAIT,
|
||||
{
|
||||
toolChoice,
|
||||
},
|
||||
);
|
||||
const curStepOutput = await this._runStep(task.taskId, undefined, mode, {
|
||||
toolChoice,
|
||||
});
|
||||
|
||||
if (curStepOutput.isLast) {
|
||||
resultOutput = curStepOutput;
|
||||
@@ -298,7 +315,26 @@ export class AgentRunner extends BaseAgentRunner {
|
||||
message,
|
||||
chatHistory,
|
||||
toolChoice,
|
||||
}: ChatEngineAgentParams): Promise<AgentChatResponse> {
|
||||
stream,
|
||||
}: ChatEngineAgentParams & {
|
||||
stream?: false;
|
||||
}): Promise<AgentChatResponse>;
|
||||
public async chat({
|
||||
message,
|
||||
chatHistory,
|
||||
toolChoice,
|
||||
stream,
|
||||
}: ChatEngineAgentParams & {
|
||||
stream: true;
|
||||
}): Promise<StreamingAgentChatResponse>;
|
||||
public async chat({
|
||||
message,
|
||||
chatHistory,
|
||||
toolChoice,
|
||||
stream,
|
||||
}: ChatEngineAgentParams): Promise<
|
||||
AgentChatResponse | StreamingAgentChatResponse
|
||||
> {
|
||||
if (!toolChoice) {
|
||||
toolChoice = this.defaultToolChoice;
|
||||
}
|
||||
@@ -307,7 +343,7 @@ export class AgentRunner extends BaseAgentRunner {
|
||||
message,
|
||||
chatHistory,
|
||||
toolChoice,
|
||||
mode: ChatResponseMode.WAIT,
|
||||
stream,
|
||||
});
|
||||
|
||||
return chatResponse;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import type { AgentChatResponse } from "../../engines/chat/index.js";
|
||||
import type {
|
||||
AgentChatResponse,
|
||||
StreamingAgentChatResponse,
|
||||
} from "../../engines/chat/index.js";
|
||||
import type { Task, TaskStep, TaskStepOutput } from "../types.js";
|
||||
import { BaseAgent } from "../types.js";
|
||||
|
||||
@@ -57,7 +60,7 @@ export abstract class BaseAgentRunner extends BaseAgent {
|
||||
taskId: string,
|
||||
stepOutput: TaskStepOutput,
|
||||
kwargs?: any,
|
||||
): Promise<AgentChatResponse>;
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse>;
|
||||
|
||||
abstract undoStep(taskId: string): void;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import type {
|
||||
AgentChatResponse,
|
||||
ChatEngineAgentParams,
|
||||
StreamingAgentChatResponse,
|
||||
} from "../engines/chat/index.js";
|
||||
|
||||
import type { QueryEngineParamsNonStreaming } from "../types.js";
|
||||
|
||||
export interface AgentWorker {
|
||||
@@ -12,11 +14,15 @@ export interface AgentWorker {
|
||||
}
|
||||
|
||||
interface BaseChatEngine {
|
||||
chat(params: ChatEngineAgentParams): Promise<AgentChatResponse>;
|
||||
chat(
|
||||
params: ChatEngineAgentParams,
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse>;
|
||||
}
|
||||
|
||||
interface BaseQueryEngine {
|
||||
query(params: QueryEngineParamsNonStreaming): Promise<AgentChatResponse>;
|
||||
query(
|
||||
params: QueryEngineParamsNonStreaming,
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,7 +37,10 @@ export abstract class BaseAgent implements BaseChatEngine, BaseQueryEngine {
|
||||
return [];
|
||||
}
|
||||
|
||||
abstract chat(params: ChatEngineAgentParams): Promise<AgentChatResponse>;
|
||||
abstract chat(
|
||||
params: ChatEngineAgentParams,
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse>;
|
||||
|
||||
abstract reset(): void;
|
||||
|
||||
/**
|
||||
@@ -41,7 +50,7 @@ export abstract class BaseAgent implements BaseChatEngine, BaseQueryEngine {
|
||||
*/
|
||||
async query(
|
||||
params: QueryEngineParamsNonStreaming,
|
||||
): Promise<AgentChatResponse> {
|
||||
): Promise<AgentChatResponse | StreamingAgentChatResponse> {
|
||||
// Handle non-streaming query
|
||||
const agentResponse = await this.chat({
|
||||
message: params.query,
|
||||
@@ -161,13 +170,13 @@ export class TaskStep implements ITaskStep {
|
||||
* @param isLast: isLast
|
||||
*/
|
||||
export class TaskStepOutput {
|
||||
output: unknown;
|
||||
output: any;
|
||||
taskStep: TaskStep;
|
||||
nextSteps: TaskStep[];
|
||||
isLast: boolean;
|
||||
|
||||
constructor(
|
||||
output: unknown,
|
||||
output: any,
|
||||
taskStep: TaskStep,
|
||||
nextSteps: TaskStep[],
|
||||
isLast: boolean = false,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RetrieverQueryEngine } from "../engines/query/RetrieverQueryEngine.js";
|
||||
import type { BaseNodePostprocessor } from "../postprocessors/types.js";
|
||||
import type { BaseSynthesizer } from "../synthesizers/types.js";
|
||||
import type { BaseQueryEngine } from "../types.js";
|
||||
import type { RetrieveParams } from "./LlamaCloudRetriever.js";
|
||||
import type { CloudRetrieveParams } from "./LlamaCloudRetriever.js";
|
||||
import { LlamaCloudRetriever } from "./LlamaCloudRetriever.js";
|
||||
import type { CloudConstructorParams } from "./types.js";
|
||||
|
||||
@@ -14,7 +14,7 @@ export class LlamaCloudIndex {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
asRetriever(params: RetrieveParams = {}): BaseRetriever {
|
||||
asRetriever(params: CloudRetrieveParams = {}): BaseRetriever {
|
||||
return new LlamaCloudRetriever({ ...this.params, ...params });
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export class LlamaCloudIndex {
|
||||
responseSynthesizer?: BaseSynthesizer;
|
||||
preFilters?: unknown;
|
||||
nodePostprocessors?: BaseNodePostprocessor[];
|
||||
} & RetrieveParams,
|
||||
} & CloudRetrieveParams,
|
||||
): BaseQueryEngine {
|
||||
const retriever = new LlamaCloudRetriever({
|
||||
...this.params,
|
||||
|
||||
@@ -2,15 +2,14 @@ import type { PlatformApi, PlatformApiClient } from "@llamaindex/cloud";
|
||||
import { globalsHelper } from "../GlobalsHelper.js";
|
||||
import type { NodeWithScore } from "../Node.js";
|
||||
import { ObjectType, jsonToNode } from "../Node.js";
|
||||
import type { BaseRetriever } from "../Retriever.js";
|
||||
import type { BaseRetriever, RetrieveParams } from "../Retriever.js";
|
||||
import type { ServiceContext } from "../ServiceContext.js";
|
||||
import { serviceContextFromDefaults } from "../ServiceContext.js";
|
||||
import type { Event } from "../callbacks/CallbackManager.js";
|
||||
import type { ClientParams, CloudConstructorParams } from "./types.js";
|
||||
import { DEFAULT_PROJECT_NAME } from "./types.js";
|
||||
import { getClient } from "./utils.js";
|
||||
|
||||
export type RetrieveParams = Omit<
|
||||
export type CloudRetrieveParams = Omit<
|
||||
PlatformApi.RetrievalParams,
|
||||
"query" | "searchFilters" | "pipelineId" | "className"
|
||||
> & { similarityTopK?: number };
|
||||
@@ -18,7 +17,7 @@ export type RetrieveParams = Omit<
|
||||
export class LlamaCloudRetriever implements BaseRetriever {
|
||||
client?: PlatformApiClient;
|
||||
clientParams: ClientParams;
|
||||
retrieveParams: RetrieveParams;
|
||||
retrieveParams: CloudRetrieveParams;
|
||||
projectName: string = DEFAULT_PROJECT_NAME;
|
||||
pipelineName: string;
|
||||
serviceContext: ServiceContext;
|
||||
@@ -35,7 +34,7 @@ export class LlamaCloudRetriever implements BaseRetriever {
|
||||
});
|
||||
}
|
||||
|
||||
constructor(params: CloudConstructorParams & RetrieveParams) {
|
||||
constructor(params: CloudConstructorParams & CloudRetrieveParams) {
|
||||
this.clientParams = { apiKey: params.apiKey, baseUrl: params.baseUrl };
|
||||
if (params.similarityTopK) {
|
||||
params.denseSimilarityTopK = params.similarityTopK;
|
||||
@@ -55,11 +54,11 @@ export class LlamaCloudRetriever implements BaseRetriever {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
query: string,
|
||||
parentEvent?: Event | undefined,
|
||||
preFilters?: unknown,
|
||||
): Promise<NodeWithScore[]> {
|
||||
async retrieve({
|
||||
query,
|
||||
parentEvent,
|
||||
preFilters,
|
||||
}: RetrieveParams): Promise<NodeWithScore[]> {
|
||||
const pipelines = await (
|
||||
await this.getClient()
|
||||
).pipeline.searchPipelines({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { PlatformApiClient } from "@llamaindex/cloud";
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import type { ClientParams } from "./types.js";
|
||||
import { DEFAULT_BASE_URL } from "./types.js";
|
||||
|
||||
@@ -7,8 +8,8 @@ export async function getClient({
|
||||
baseUrl,
|
||||
}: ClientParams = {}): Promise<PlatformApiClient> {
|
||||
// Get the environment variables or use defaults
|
||||
baseUrl = baseUrl ?? process.env.LLAMA_CLOUD_BASE_URL ?? DEFAULT_BASE_URL;
|
||||
apiKey = apiKey ?? process.env.LLAMA_CLOUD_API_KEY;
|
||||
baseUrl = baseUrl ?? getEnv("LLAMA_CLOUD_BASE_URL") ?? DEFAULT_BASE_URL;
|
||||
apiKey = apiKey ?? getEnv("LLAMA_CLOUD_API_KEY");
|
||||
|
||||
const { PlatformApiClient } = await import("@llamaindex/cloud");
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ export enum HuggingFaceEmbeddingModelType {
|
||||
*/
|
||||
export class HuggingFaceEmbedding extends BaseEmbedding {
|
||||
modelType: string = HuggingFaceEmbeddingModelType.XENOVA_ALL_MINILM_L6_V2;
|
||||
quantized: boolean = true;
|
||||
|
||||
private extractor: any;
|
||||
|
||||
@@ -31,7 +32,9 @@ export class HuggingFaceEmbedding extends BaseEmbedding {
|
||||
async getExtractor() {
|
||||
if (!this.extractor) {
|
||||
const { pipeline } = await import("@xenova/transformers");
|
||||
this.extractor = await pipeline("feature-extraction", this.modelType);
|
||||
this.extractor = await pipeline("feature-extraction", this.modelType, {
|
||||
quantized: this.quantized,
|
||||
});
|
||||
}
|
||||
return this.extractor;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { OpenAIEmbedding } from "./OpenAIEmbedding.js";
|
||||
|
||||
export class FireworksEmbedding extends OpenAIEmbedding {
|
||||
constructor(init?: Partial<OpenAIEmbedding>) {
|
||||
const {
|
||||
apiKey = process.env.FIREWORKS_API_KEY,
|
||||
apiKey = getEnv("FIREWORKS_API_KEY"),
|
||||
additionalSessionOptions = {},
|
||||
model = "nomic-ai/nomic-embed-text-v1.5",
|
||||
...rest
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { getEnv } from "@llamaindex/env";
|
||||
import { OpenAIEmbedding } from "./OpenAIEmbedding.js";
|
||||
|
||||
export class TogetherEmbedding extends OpenAIEmbedding {
|
||||
constructor(init?: Partial<OpenAIEmbedding>) {
|
||||
const {
|
||||
apiKey = process.env.TOGETHER_API_KEY,
|
||||
apiKey = getEnv("TOGETHER_API_KEY"),
|
||||
additionalSessionOptions = {},
|
||||
model = "togethercomputer/m2-bert-80M-32k-retrieval",
|
||||
...rest
|
||||
|
||||
@@ -64,10 +64,10 @@ export class DefaultContextGenerator
|
||||
tags: ["final"],
|
||||
};
|
||||
}
|
||||
const sourceNodesWithScore = await this.retriever.retrieve(
|
||||
message,
|
||||
const sourceNodesWithScore = await this.retriever.retrieve({
|
||||
query: message,
|
||||
parentEvent,
|
||||
);
|
||||
});
|
||||
|
||||
const nodes = await this.applyNodePostprocessors(
|
||||
sourceNodesWithScore,
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface ChatEngineParamsNonStreaming extends ChatEngineParamsBase {
|
||||
|
||||
export interface ChatEngineAgentParams extends ChatEngineParamsBase {
|
||||
toolChoice?: string | Record<string, any>;
|
||||
stream?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,3 +87,20 @@ export class AgentChatResponse {
|
||||
return this.response ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
export class StreamingAgentChatResponse {
|
||||
response: AsyncIterable<Response>;
|
||||
|
||||
sources: ToolOutput[];
|
||||
sourceNodes?: BaseNode[];
|
||||
|
||||
constructor(
|
||||
response: AsyncIterable<Response>,
|
||||
sources?: ToolOutput[],
|
||||
sourceNodes?: BaseNode[],
|
||||
) {
|
||||
this.response = response;
|
||||
this.sources = sources ?? [];
|
||||
this.sourceNodes = sourceNodes ?? [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ export class RetrieverQueryEngine
|
||||
}
|
||||
|
||||
private async retrieve(query: string, parentEvent: Event) {
|
||||
const nodes = await this.retriever.retrieve(
|
||||
const nodes = await this.retriever.retrieve({
|
||||
query,
|
||||
parentEvent,
|
||||
this.preFilters,
|
||||
);
|
||||
preFilters: this.preFilters,
|
||||
});
|
||||
|
||||
return await this.applyNodePostprocessors(nodes, query);
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ export class TitleExtractor extends BaseExtractor {
|
||||
* Constructor for the TitleExtractor class.
|
||||
* @param {LLM} llm LLM instance.
|
||||
* @param {number} nodes Number of nodes to extract titles from.
|
||||
* @param {string} node_template The prompt template to use for the title extractor.
|
||||
* @param {string} combine_template The prompt template to merge title with..
|
||||
* @param {string} nodeTemplate The prompt template to use for the title extractor.
|
||||
* @param {string} combineTemplate The prompt template to merge title with..
|
||||
*/
|
||||
constructor(options?: TitleExtractorsArgs) {
|
||||
super();
|
||||
@@ -162,50 +162,85 @@ export class TitleExtractor extends BaseExtractor {
|
||||
* @returns {Promise<BaseNode<ExtractTitle>[]>} Titles extracted from the nodes.
|
||||
*/
|
||||
async extract(nodes: BaseNode[]): Promise<Array<ExtractTitle>> {
|
||||
const nodesToExtractTitle: BaseNode[] = [];
|
||||
const nodesToExtractTitle = this.filterNodes(nodes);
|
||||
|
||||
for (let i = 0; i < this.nodes; i++) {
|
||||
if (nodesToExtractTitle.length >= nodes.length) break;
|
||||
|
||||
if (this.isTextNodeOnly && !(nodes[i] instanceof TextNode)) continue;
|
||||
|
||||
nodesToExtractTitle.push(nodes[i]);
|
||||
if (!nodesToExtractTitle.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (nodesToExtractTitle.length === 0) return [];
|
||||
const nodesByDocument = this.separateNodesByDocument(nodesToExtractTitle);
|
||||
const titlesByDocument = await this.extractTitles(nodesByDocument);
|
||||
|
||||
const titlesCandidates: string[] = [];
|
||||
let title: string = "";
|
||||
return nodesToExtractTitle.map((node) => {
|
||||
return {
|
||||
documentTitle: titlesByDocument[node.sourceNode?.nodeId ?? ""],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
for (let i = 0; i < nodesToExtractTitle.length; i++) {
|
||||
const completion = await this.llm.complete({
|
||||
prompt: defaultTitleExtractorPromptTemplate({
|
||||
contextStr: nodesToExtractTitle[i].getContent(MetadataMode.ALL),
|
||||
}),
|
||||
});
|
||||
private filterNodes(nodes: BaseNode[]): BaseNode[] {
|
||||
return nodes.filter((node) => {
|
||||
if (this.isTextNodeOnly && !(node instanceof TextNode)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
titlesCandidates.push(completion.text);
|
||||
private separateNodesByDocument(
|
||||
nodes: BaseNode[],
|
||||
): Record<string, BaseNode[]> {
|
||||
const nodesByDocument: Record<string, BaseNode[]> = {};
|
||||
|
||||
for (const node of nodes) {
|
||||
const parentNode = node.sourceNode?.nodeId;
|
||||
|
||||
if (!parentNode) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!nodesByDocument[parentNode]) {
|
||||
nodesByDocument[parentNode] = [];
|
||||
}
|
||||
|
||||
nodesByDocument[parentNode].push(node);
|
||||
}
|
||||
|
||||
if (nodesToExtractTitle.length > 1) {
|
||||
const combinedTitles = titlesCandidates.join(",");
|
||||
return nodesByDocument;
|
||||
}
|
||||
|
||||
private async extractTitles(
|
||||
nodesByDocument: Record<string, BaseNode[]>,
|
||||
): Promise<Record<string, string>> {
|
||||
const titlesByDocument: Record<string, string> = {};
|
||||
|
||||
for (const [key, nodes] of Object.entries(nodesByDocument)) {
|
||||
const titleCandidates = await this.getTitlesCandidates(nodes);
|
||||
const combinedTitles = titleCandidates.join(", ");
|
||||
const completion = await this.llm.complete({
|
||||
prompt: defaultTitleCombinePromptTemplate({
|
||||
contextStr: combinedTitles,
|
||||
}),
|
||||
});
|
||||
|
||||
title = completion.text;
|
||||
titlesByDocument[key] = completion.text;
|
||||
}
|
||||
|
||||
if (nodesToExtractTitle.length === 1) {
|
||||
title = titlesCandidates[0];
|
||||
}
|
||||
return titlesByDocument;
|
||||
}
|
||||
|
||||
return nodes.map((_) => ({
|
||||
documentTitle: title.trim().replace(STRIP_REGEX, ""),
|
||||
}));
|
||||
private async getTitlesCandidates(nodes: BaseNode[]): Promise<string[]> {
|
||||
const titleJobs = nodes.map(async (node) => {
|
||||
const completion = await this.llm.complete({
|
||||
prompt: defaultTitleExtractorPromptTemplate({
|
||||
contextStr: node.getContent(MetadataMode.ALL),
|
||||
}),
|
||||
});
|
||||
|
||||
return completion.text;
|
||||
});
|
||||
|
||||
return await Promise.all(titleJobs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,9 +387,9 @@ export class SummaryExtractor extends BaseExtractor {
|
||||
*/
|
||||
promptTemplate: string;
|
||||
|
||||
private _selfSummary: boolean;
|
||||
private _prevSummary: boolean;
|
||||
private _nextSummary: boolean;
|
||||
private selfSummary: boolean;
|
||||
private prevSummary: boolean;
|
||||
private nextSummary: boolean;
|
||||
|
||||
constructor(options?: SummaryExtractArgs) {
|
||||
const summaries = options?.summaries ?? ["self"];
|
||||
@@ -372,9 +407,9 @@ export class SummaryExtractor extends BaseExtractor {
|
||||
this.promptTemplate =
|
||||
options?.promptTemplate ?? defaultSummaryExtractorPromptTemplate();
|
||||
|
||||
this._selfSummary = summaries?.includes("self") ?? false;
|
||||
this._prevSummary = summaries?.includes("prev") ?? false;
|
||||
this._nextSummary = summaries?.includes("next") ?? false;
|
||||
this.selfSummary = summaries?.includes("self") ?? false;
|
||||
this.prevSummary = summaries?.includes("prev") ?? false;
|
||||
this.nextSummary = summaries?.includes("next") ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,13 +451,13 @@ export class SummaryExtractor extends BaseExtractor {
|
||||
const metadataList: any[] = nodes.map(() => ({}));
|
||||
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
if (i > 0 && this._prevSummary && nodeSummaries[i - 1]) {
|
||||
if (i > 0 && this.prevSummary && nodeSummaries[i - 1]) {
|
||||
metadataList[i]["prevSectionSummary"] = nodeSummaries[i - 1];
|
||||
}
|
||||
if (i < nodes.length - 1 && this._nextSummary && nodeSummaries[i + 1]) {
|
||||
if (i < nodes.length - 1 && this.nextSummary && nodeSummaries[i + 1]) {
|
||||
metadataList[i]["nextSectionSummary"] = nodeSummaries[i + 1];
|
||||
}
|
||||
if (this._selfSummary && nodeSummaries[i]) {
|
||||
if (this.selfSummary && nodeSummaries[i]) {
|
||||
metadataList[i]["sectionSummary"] = nodeSummaries[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,33 +21,25 @@ export const defaultKeywordExtractorPromptTemplate = ({
|
||||
contextStr = "",
|
||||
keywords = 5,
|
||||
}: DefaultKeywordExtractorPromptTemplate) => `${contextStr}
|
||||
|
||||
Give ${keywords} unique keywords for this document.
|
||||
|
||||
Format as comma separated. Keywords:
|
||||
`;
|
||||
Format as comma separated.
|
||||
Keywords: `;
|
||||
|
||||
export const defaultTitleExtractorPromptTemplate = (
|
||||
{ contextStr = "" }: DefaultPromptTemplate = {
|
||||
contextStr: "",
|
||||
},
|
||||
) => `${contextStr}
|
||||
|
||||
Give a title that summarizes all of the unique entities, titles or themes found in the context.
|
||||
|
||||
Title:
|
||||
`;
|
||||
Title: `;
|
||||
|
||||
export const defaultTitleCombinePromptTemplate = (
|
||||
{ contextStr = "" }: DefaultPromptTemplate = {
|
||||
contextStr: "",
|
||||
},
|
||||
) => `${contextStr}
|
||||
|
||||
Based on the above candidate titles and contents, what is the comprehensive title for this document?
|
||||
|
||||
Title:
|
||||
`;
|
||||
Title: `;
|
||||
|
||||
export const defaultQuestionAnswerPromptTemplate = (
|
||||
{ contextStr = "", numQuestions = 5 }: DefaultQuestionAnswerPromptTemplate = {
|
||||
@@ -55,9 +47,7 @@ export const defaultQuestionAnswerPromptTemplate = (
|
||||
numQuestions: 5,
|
||||
},
|
||||
) => `${contextStr}
|
||||
|
||||
Given the contextual informations, generate ${numQuestions} questions this context can provides specific answers to which are unlikely to be found elsewhere.Higher-level summaries of surrounding context may be provideds as well.
|
||||
|
||||
Given the contextual informations, generate ${numQuestions} questions this context can provides specific answers to which are unlikely to be found else where. Higher-level summaries of surrounding context may be provideds as well.
|
||||
Try using these summaries to generate better questions that this context can answer.
|
||||
`;
|
||||
|
||||
@@ -66,11 +56,8 @@ export const defaultSummaryExtractorPromptTemplate = (
|
||||
contextStr: "",
|
||||
},
|
||||
) => `${contextStr}
|
||||
|
||||
Summarize the key topics and entities of the sections.
|
||||
|
||||
Summary:
|
||||
`;
|
||||
Summary: `;
|
||||
|
||||
export const defaultNodeTextTemplate = ({
|
||||
metadataStr = "",
|
||||
|
||||
@@ -30,3 +30,4 @@ export * from "./selectors/index.js";
|
||||
export * from "./storage/index.js";
|
||||
export * from "./synthesizers/index.js";
|
||||
export * from "./tools/index.js";
|
||||
export * from "./types.js";
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
export * from "./BaseIndex.js";
|
||||
export * from "./IndexStruct.js";
|
||||
export * from "./json-to-index-struct.js";
|
||||
export * from "./keyword/index.js";
|
||||
export * from "./summary/index.js";
|
||||
export * from "./vectorStore/index.js";
|
||||
|
||||
@@ -24,9 +24,15 @@ export class IndexDict extends IndexStruct {
|
||||
}
|
||||
|
||||
toJson(): Record<string, unknown> {
|
||||
const nodesDict: Record<string, unknown> = {};
|
||||
|
||||
for (const [key, node] of Object.entries(this.nodesDict)) {
|
||||
nodesDict[key] = node.toJSON();
|
||||
}
|
||||
|
||||
return {
|
||||
...super.toJson(),
|
||||
nodesDict: this.nodesDict,
|
||||
nodesDict,
|
||||
type: this.type,
|
||||
};
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user