Skip to content

Commit f452027

Browse files
committed
use pipeline transformation & upgrade llamaindex latest
1 parent 035e96e commit f452027

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

templates/types/streaming/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dotenv": "^16.3.1",
2121
"duck-duck-scrape": "^2.2.5",
2222
"express": "^4.18.2",
23-
"llamaindex": "0.4.3",
23+
"llamaindex": "0.4.4",
2424
"pdf2json": "3.0.5",
2525
"ajv": "^8.12.0",
2626
"@e2b/code-interpreter": "^0.0.5",

templates/types/streaming/nextjs/app/api/chat/embed/embeddings.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
1-
import { Document, MetadataMode, Settings, SimpleNodeParser } from "llamaindex";
1+
import {
2+
Document,
3+
IngestionPipeline,
4+
MetadataMode,
5+
Settings,
6+
SimpleNodeParser,
7+
} from "llamaindex";
28
import pdf from "pdf-parse";
39

410
export async function splitAndEmbed(content: string) {
5-
// const document = new Document({ text: content, id_: "123" });
6-
// const pipeline = new IngestionPipeline({
7-
// transformations: [
8-
// new SimpleNodeParser({
9-
// chunkSize: Settings.chunkSize,
10-
// chunkOverlap: Settings.chunkOverlap,
11-
// }),
12-
// Settings.embedModel,
13-
// ],
14-
// });
15-
// const nodes = await pipeline.run({ documents: [document] });
16-
// return nodes;
17-
18-
const nodeParser = new SimpleNodeParser({
19-
chunkSize: Settings.chunkSize,
20-
chunkOverlap: Settings.chunkOverlap,
11+
const document = new Document({ text: content });
12+
const pipeline = new IngestionPipeline({
13+
transformations: [
14+
new SimpleNodeParser({
15+
chunkSize: Settings.chunkSize,
16+
chunkOverlap: Settings.chunkOverlap,
17+
}),
18+
Settings.embedModel,
19+
],
2120
});
22-
const nodes = nodeParser.getNodesFromDocuments([
23-
new Document({ text: content }),
24-
]);
25-
const texts = nodes.map((node) => node.getContent(MetadataMode.EMBED));
26-
const embeddings = await Settings.embedModel.getTextEmbeddingsBatch(texts);
21+
const nodes = await pipeline.run({ documents: [document] });
2722
return nodes.map((node, i) => ({
2823
text: node.getContent(MetadataMode.NONE),
29-
embedding: embeddings[i],
24+
embedding: node.embedding,
3025
}));
3126
}
3227

templates/types/streaming/nextjs/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"duck-duck-scrape": "^2.2.5",
2525
"formdata-node": "^6.0.3",
2626
"got": "^14.4.1",
27-
"llamaindex": "0.4.3",
27+
"llamaindex": "0.4.4",
2828
"lucide-react": "^0.294.0",
2929
"next": "^14.2.4",
3030
"pdf2json": "3.0.5",
@@ -60,6 +60,7 @@
6060
"prettier-plugin-organize-imports": "^3.2.4",
6161
"tailwindcss": "^3.3.6",
6262
"tsx": "^4.7.2",
63-
"typescript": "^5.3.2"
63+
"typescript": "^5.3.2",
64+
"@types/pdf-parse": "^1.1.4"
6465
}
6566
}

0 commit comments

Comments
 (0)