Skip to content

Commit 2cd1383

Browse files
authored
feat: align response-synthesizers & chat-engine module (run-llama#1169)
1 parent 72440c1 commit 2cd1383

47 files changed

Lines changed: 692 additions & 1006 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/ten-bottles-learn.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@llamaindex/core": patch
3+
"@llamaindex/experimental": patch
4+
"llamaindex": patch
5+
---
6+
7+
refactor: align `response-synthesizers` & `chat-engine` module
8+
9+
- builtin event system
10+
- correct class extends
11+
- aligin APIs, naming with llama-index python
12+
- move stream out of first parameter to second parameter for the better tyep checking
13+
- remove JSONQueryEngine in `@llamaindex/experimental`, as the code quality is not satisify and we will bring it back later

examples/huggingface/embedding.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ async function main() {
2727

2828
// Query the index
2929
const queryEngine = index.asQueryEngine();
30-
const stream = await queryEngine.query({
31-
query: "What did the author do in college?",
32-
stream: true,
33-
});
30+
const stream = await queryEngine.query(
31+
{
32+
query: "What did the author do in college?",
33+
},
34+
true,
35+
);
3436

3537
// Output response
3638
for await (const chunk of stream) {

examples/huggingface/embeddingApi.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ async function main() {
3737

3838
// Query the index
3939
const queryEngine = index.asQueryEngine();
40-
const stream = await queryEngine.query({
41-
query: "What did the author do in college?",
42-
stream: true,
43-
});
40+
const stream = await queryEngine.query(
41+
{
42+
query: "What did the author do in college?",
43+
},
44+
true,
45+
);
4446

4547
// Output response
4648
for await (const chunk of stream) {

examples/lowlevel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Document,
3+
getResponseSynthesizer,
34
NodeWithScore,
4-
ResponseSynthesizer,
55
SentenceSplitter,
66
TextNode,
77
} from "llamaindex";
@@ -14,7 +14,7 @@ import {
1414

1515
console.log(nodes);
1616

17-
const responseSynthesizer = new ResponseSynthesizer();
17+
const responseSynthesizer = getResponseSynthesizer("compact");
1818

1919
const nodesWithScore: NodeWithScore[] = [
2020
{
@@ -30,7 +30,7 @@ import {
3030
const stream = await responseSynthesizer.synthesize(
3131
{
3232
query: "What age am I?",
33-
nodesWithScore,
33+
nodes: nodesWithScore,
3434
},
3535
true,
3636
);

examples/multimodal/rag.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
MultiModalResponseSynthesizer,
2+
getResponseSynthesizer,
33
OpenAI,
44
Settings,
55
VectorStoreIndex,
@@ -27,13 +27,15 @@ async function main() {
2727
});
2828

2929
const queryEngine = index.asQueryEngine({
30-
responseSynthesizer: new MultiModalResponseSynthesizer(),
30+
responseSynthesizer: getResponseSynthesizer("multi_modal"),
3131
retriever: index.asRetriever({ topK: { TEXT: 3, IMAGE: 1 } }),
3232
});
33-
const stream = await queryEngine.query({
34-
query: "Tell me more about Vincent van Gogh's famous paintings",
35-
stream: true,
36-
});
33+
const stream = await queryEngine.query(
34+
{
35+
query: "Tell me more about Vincent van Gogh's famous paintings",
36+
},
37+
true,
38+
);
3739
for await (const chunk of stream) {
3840
process.stdout.write(chunk.response);
3941
}

examples/prompts/promptMixin.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {
22
Document,
3+
getResponseSynthesizer,
34
PromptTemplate,
4-
ResponseSynthesizer,
5-
TreeSummarize,
65
TreeSummarizePrompt,
76
VectorStoreIndex,
87
} from "llamaindex";
@@ -27,9 +26,7 @@ async function main() {
2726

2827
const query = "The quick brown fox jumps over the lazy dog";
2928

30-
const responseSynthesizer = new ResponseSynthesizer({
31-
responseBuilder: new TreeSummarize(),
32-
});
29+
const responseSynthesizer = getResponseSynthesizer("tree_summarize");
3330

3431
const queryEngine = index.asQueryEngine({
3532
responseSynthesizer,

examples/readers/src/csv.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import {
2-
CompactAndRefine,
2+
getResponseSynthesizer,
33
OpenAI,
44
PromptTemplate,
5-
ResponseSynthesizer,
65
Settings,
76
VectorStoreIndex,
87
} from "llamaindex";
@@ -29,8 +28,8 @@ Given the CSV file, generate me Typescript code to answer the question: {query}.
2928
`,
3029
});
3130

32-
const responseSynthesizer = new ResponseSynthesizer({
33-
responseBuilder: new CompactAndRefine(undefined, csvPrompt),
31+
const responseSynthesizer = getResponseSynthesizer("compact", {
32+
textQATemplate: csvPrompt,
3433
});
3534

3635
const queryEngine = index.asQueryEngine({ responseSynthesizer });

examples/readers/src/llamaparse-json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { createMessageContent } from "@llamaindex/core/utils";
12
import {
23
Document,
34
ImageNode,
@@ -6,7 +7,6 @@ import {
67
PromptTemplate,
78
VectorStoreIndex,
89
} from "llamaindex";
9-
import { createMessageContent } from "llamaindex/synthesizers/utils";
1010

1111
const reader = new LlamaParseReader();
1212
async function main() {

examples/vectorIndexAnthropic.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import fs from "node:fs/promises";
22

33
import {
44
Anthropic,
5-
CompactAndRefine,
65
Document,
7-
ResponseSynthesizer,
86
Settings,
97
VectorStoreIndex,
10-
anthropicTextQaPrompt,
8+
getResponseSynthesizer,
119
} from "llamaindex";
1210

1311
// Update llm to use Anthropic
@@ -23,9 +21,7 @@ async function main() {
2321
const document = new Document({ text: essay, id_: path });
2422

2523
// Split text and create embeddings. Store them in a VectorStoreIndex
26-
const responseSynthesizer = new ResponseSynthesizer({
27-
responseBuilder: new CompactAndRefine(undefined, anthropicTextQaPrompt),
28-
});
24+
const responseSynthesizer = getResponseSynthesizer("compact");
2925

3026
const index = await VectorStoreIndex.fromDocuments([document]);
3127

examples/vectorIndexFromVectorStore.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
2+
getResponseSynthesizer,
23
OpenAI,
34
OpenAIEmbedding,
4-
ResponseSynthesizer,
55
RetrieverQueryEngine,
66
Settings,
77
TextNode,
8-
TreeSummarize,
98
VectorIndexRetriever,
109
VectorStore,
1110
VectorStoreIndex,
@@ -165,10 +164,7 @@ async function main() {
165164
similarityTopK: 500,
166165
});
167166

168-
const responseSynthesizer = new ResponseSynthesizer({
169-
responseBuilder: new TreeSummarize(),
170-
});
171-
167+
const responseSynthesizer = getResponseSynthesizer("tree_summarize");
172168
return new RetrieverQueryEngine(retriever, responseSynthesizer, {
173169
filter,
174170
});

0 commit comments

Comments
 (0)