Skip to content

Commit f7065e2

Browse files
committed
Added /purgeDB endpoint
1 parent 6c3ada2 commit f7065e2

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

ai-assistant/src/RocketChatterApp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { SuggestCommand } from "./commands/SuggestCommand";
2626
import { TranslateCommand } from "./commands/TranslateCommand";
2727
import { WhyUsedCommand } from "./commands/WhyUsedCommand";
2828
import { IngestEndpoint } from "./endpoints/ingest";
29+
import { PurgeDBEndpoint } from "./endpoints/purgeDB";
2930
import { handleModalViewSubmit } from "./utils/handleModalViewSubmit";
3031

3132
export class RocketChatterApp extends App {
@@ -65,7 +66,11 @@ export class RocketChatterApp extends App {
6566
await configuration.api.provideApi({
6667
visibility: ApiVisibility.PUBLIC,
6768
security: ApiSecurity.UNSECURE,
68-
endpoints: [new IngestEndpoint(this)],
69+
endpoints: [
70+
new IngestEndpoint(this),
71+
new PurgeDBEndpoint(this),
72+
],
6973
});
74+
7075
}
7176
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import {
2+
IHttp,
3+
IModify,
4+
IPersistence,
5+
IRead,
6+
} from "@rocket.chat/apps-engine/definition/accessors";
7+
import {
8+
ApiEndpoint,
9+
IApiEndpointInfo,
10+
IApiRequest,
11+
IApiResponse,
12+
} from "@rocket.chat/apps-engine/definition/api";
13+
import { IDB } from "../core/db/db.types";
14+
import { Neo4j } from "../core/db/neo4j";
15+
16+
export class PurgeDBEndpoint extends ApiEndpoint {
17+
public path = "purgeDB";
18+
19+
async emptyDB(db: IDB) {
20+
const query = `MATCH (n) DETACH DELETE n`;
21+
await db.run(query);
22+
console.error("Failed to empty DB");
23+
}
24+
25+
async setupIndices(db: IDB) {
26+
const query = [
27+
// Drop existing indices
28+
"DROP INDEX `nameEmbeddings`;",
29+
"DROP INDEX `codeEmbeddings`;",
30+
31+
// Create indices for name embeddings
32+
"CREATE VECTOR INDEX `nameEmbeddings`",
33+
"FOR (n: Node) ON (n.nameEmbeddings)",
34+
"OPTIONS {indexConfig: {",
35+
" `vector.dimensions`: 768,",
36+
" `vector.similarity_function`: 'COSINE'",
37+
"}};",
38+
39+
// Create indices for code embeddings
40+
"CREATE VECTOR INDEX `codeEmbeddings`",
41+
"FOR (n: Node) ON (n.codeEmbeddings)",
42+
"OPTIONS {indexConfig: {",
43+
" `vector.dimensions`: 768,",
44+
" `vector.similarity_function`: 'COSINE'",
45+
"}};",
46+
47+
].join("\n");
48+
await db.run(query);
49+
}
50+
51+
public async post(
52+
request: IApiRequest,
53+
endpoint: IApiEndpointInfo,
54+
read: IRead,
55+
modify: IModify,
56+
http: IHttp,
57+
persis: IPersistence
58+
): Promise<IApiResponse> {
59+
const db = new Neo4j(http);
60+
61+
await this.emptyDB(db)
62+
await this.setupIndices(db)
63+
64+
return this.success();
65+
}
66+
}

0 commit comments

Comments
 (0)