Skip to content

Commit 5365704

Browse files
committed
Fixed problems in ingestion in ai-assistant
1 parent 2fbcf01 commit 5365704

File tree

2 files changed

+11
-39
lines changed

2 files changed

+11
-39
lines changed

ai-assistant/src/core/db/neo4j.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ export class Neo4j implements IDB {
119119
this.transactionUrl = undefined;
120120
}
121121

122-
async run(
123-
query: string,
124-
params?: any
125-
): Promise<Record<string, any>[] | null> {
122+
async run(query: string, params?: any): Promise<Record<string, any>[]> {
126123
const data = {
127124
statements: [
128125
{
@@ -152,7 +149,9 @@ export class Neo4j implements IDB {
152149
}
153150

154151
if (response.errors.length) {
155-
return null;
152+
throw new Error(
153+
response.errors.map((x) => JSON.stringify(x)).join("\n\n")
154+
);
156155
}
157156

158157
const nodes: Record<string, any>[] = [];

ai-assistant/src/endpoints/ingest.ts

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ import {
2222
namespace Helpers {
2323
async function insertNode(db: IDB, node: DBNode) {
2424
const query = new DBNode(node).getDBInsertQuery();
25-
try {
26-
await db.run(query);
27-
} catch (e) {
28-
console.log(e);
29-
console.error("Failed to insert node");
30-
}
25+
await db.run(query, node);
3126
}
3227

3328
export async function insertNodes(db: IDB, nodes: DBNode[]) {
@@ -41,35 +36,15 @@ export class IngestEndpoint extends ApiEndpoint {
4136
makeBodies(
4237
content: any
4338
): [IngestEndpointRequestBody, IngestEndpointResponseBody] {
44-
const requestBody = JSON.parse(content) as IngestEndpointRequestBody;
39+
const requestBody = content as IngestEndpointRequestBody;
4540
const responseBody: IngestEndpointResponseBody = {
46-
batchID: requestBody.batchID,
41+
batchID: "hey",
4742
status: 200,
4843
};
4944

5045
return [requestBody, responseBody];
5146
}
5247

53-
async commitProgress(
54-
db: IDB
55-
): Promise<IngestEndpointResponseBody["status"]> {
56-
try {
57-
try {
58-
await db.commitTransaction();
59-
} catch (e) {
60-
console.error(e);
61-
await db.rollbackTransaction();
62-
63-
return 500;
64-
}
65-
} catch (e) {
66-
console.error(e);
67-
return 500;
68-
}
69-
70-
return 200;
71-
}
72-
7348
public async post(
7449
request: IApiRequest,
7550
endpoint: IApiEndpointInfo,
@@ -85,15 +60,13 @@ export class IngestEndpoint extends ApiEndpoint {
8560
nodes = nodes.map((node) => new DBNode(node));
8661
await Promise.all(nodes.map((x) => x.fillEmbeddings(embeddingModel)));
8762
// -----------------------------------------------------------------------------------
88-
8963
const db = new Neo4j(http);
9064
await db.verifyConnectivity();
9165
// -----------------------------------------------------------------------------------
92-
await db.beginTransaction();
93-
// -----------------------------------------------------------------------------------
94-
await Helpers.insertNodes(db, nodes);
95-
// -----------------------------------------------------------------------------------
96-
responseBody.status = await this.commitProgress(db);
66+
const jobs = nodes.map((node) =>
67+
db.run(new DBNode(node).getDBInsertQuery(), node)
68+
);
69+
await Promise.all(jobs);
9770
// -----------------------------------------------------------------------------------
9871

9972
return this.success(JSON.stringify(responseBody));

0 commit comments

Comments
 (0)