Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes clasess and examples #349

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion JS/edgechains/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
.env
dist
5 changes: 5 additions & 0 deletions JS/edgechains/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Installation

```
npm install arakoodev
```
1 change: 0 additions & 1 deletion JS/edgechains/arakooserver/index.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions JS/edgechains/arakooserver/index.js

This file was deleted.

1 change: 0 additions & 1 deletion JS/edgechains/arakooserver/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions JS/edgechains/arakooserver/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ArakooServer } from "./lib/hono/hono.js";
13 changes: 0 additions & 13 deletions JS/edgechains/arakooserver/src/lib/hono/hono.d.ts

This file was deleted.

26 changes: 0 additions & 26 deletions JS/edgechains/arakooserver/src/lib/hono/hono.js

This file was deleted.

4 changes: 3 additions & 1 deletion JS/edgechains/arakooserver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"jsxImportSource": "hono/jsx",
"noImplicitAny": false,
"moduleResolution": "NodeNext",
"declaration": true
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
},
"exclude": ["node_modules", "dist", "./**/*.test.ts"]
}
3 changes: 3 additions & 0 deletions JS/edgechains/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.env
dist
31 changes: 1 addition & 30 deletions JS/edgechains/db/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
// Generated by dts-bundle-generator v9.3.1

export declare class PostgresClient {
wordEmbeddings: number[][];
metric: PostgresDistanceMetric;
topK: number;
probes: number;
tableName: string;
namespace: string;
arkRequest: any;
upperLimit: number;
constructor(
wordEmbeddings: number[][],
metric: PostgresDistanceMetric,
topK: number,
probes: number,
tableName: string,
namespace: string,
arkRequest: any,
upperLimit: number
);
dbQuery(): Promise<any>;
}
declare enum PostgresDistanceMetric {
COSINE = "COSINE",
IP = "IP",
L2 = "L2",
}

export {};
export { PostgresClient } from "./lib/postgres-client/PostgresClient.js";
122 changes: 4 additions & 118 deletions JS/edgechains/db/dist/index.js
Original file line number Diff line number Diff line change
@@ -1,119 +1,5 @@
"use strict";
var g = Object.create;
var E = Object.defineProperty;
var _ = Object.getOwnPropertyDescriptor;
var b = Object.getOwnPropertyNames;
var S = Object.getPrototypeOf,
f = Object.prototype.hasOwnProperty;
var p = (t, i) => () => (i || t((i = { exports: {} }).exports, i), i.exports),
C = (t, i) => {
for (var s in i) E(t, s, { get: i[s], enumerable: !0 });
},
h = (t, i, s, m) => {
if ((i && typeof i == "object") || typeof i == "function")
for (let e of b(i))
!f.call(t, e) &&
e !== s &&
E(t, e, { get: () => i[e], enumerable: !(m = _(i, e)) || m.enumerable });
return t;
};
var D = (t, i, s) => (
(s = t != null ? g(S(t)) : {}),
h(i || !t || !t.__esModule ? E(s, "default", { value: t, enumerable: !0 }) : s, t)
),
$ = (t) => h(E({}, "__esModule", { value: !0 }), t);
var u = p((d) => {
"use strict";
Object.defineProperty(d, "__esModule", { value: !0 });
d.PostgresDistanceMetric = d.PostgresClient = void 0;
var c = require("typeorm"),
o = class {
wordEmbeddings;
metric;
topK;
probes;
tableName;
namespace;
arkRequest;
upperLimit;
constructor(i, s, m, e, R, n, a, O) {
(this.wordEmbeddings = i),
(this.metric = s),
(this.topK = m),
(this.probes = e),
(this.tableName = R),
(this.namespace = n),
(this.arkRequest = a),
(this.upperLimit = O);
}
async dbQuery() {
let i = await (0, c.createConnection)(),
s = await (0, c.getManager)();
try {
let m = `SET LOCAL ivfflat.probes = ${this.probes};`;
await s.query(m);
let e = "";
for (let n = 0; n < this.wordEmbeddings.length; n++) {
let a = JSON.stringify(this.wordEmbeddings[n]);
switch (
((e += `( SELECT id, raw_text, document_date, metadata, namespace, filename, timestamp,
${this.arkRequest.textWeight.baseWeight} / (ROW_NUMBER() OVER (ORDER BY text_rank DESC) + ${this.arkRequest.textWeight.fineTuneWeight}) +
${this.arkRequest.similarityWeight.baseWeight} / (ROW_NUMBER() OVER (ORDER BY similarity DESC) + ${this.arkRequest.similarityWeight.fineTuneWeight}) +
${this.arkRequest.dateWeight.baseWeight} / (ROW_NUMBER() OVER (ORDER BY date_rank DESC) + ${this.arkRequest.dateWeight.fineTuneWeight}) AS rrf_score
FROM ( SELECT sv.id, sv.raw_text, sv.namespace, sv.filename, sv.timestamp, svtm.document_date, svtm.metadata, ts_rank_cd(sv.tsv, plainto_tsquery('english', '${this.arkRequest.query}')) AS text_rank, `),
this.metric === r.COSINE &&
(e += `1 - (sv.embedding <=> '${a}') AS similarity, `),
this.metric === r.IP &&
(e += `(sv.embedding <#> '${a}') * -1 AS similarity, `),
this.metric === r.L2 &&
(e += `sv.embedding <-> '${a}' AS similarity, `),
(e += `CASE WHEN svtm.document_date IS NULL THEN 0 ELSE EXTRACT(YEAR FROM svtm.document_date) * 365 + EXTRACT(DOY FROM svtm.document_date) END AS date_rank FROM (SELECT id, raw_text, embedding, tsv, namespace, filename, timestamp from ${this.tableName} WHERE namespace = '${this.namespace}'`),
this.metric === r.COSINE &&
(e += ` ORDER BY embedding <=> '${a}' LIMIT ${this.topK}`),
this.metric === r.IP &&
(e += ` ORDER BY embedding <#> '${a}' LIMIT ${this.topK}`),
this.metric === r.L2 &&
(e += ` ORDER BY embedding <-> '${a}' LIMIT ${this.topK}`),
(e += `) sv JOIN ${this.tableName}_join_${this.arkRequest.metadataTable} jtm ON sv.id = jtm.id JOIN ${this.tableName}_${this.arkRequest.metadataTable} svtm ON jtm.metadata_id = svtm.metadata_id) subquery `),
this.arkRequest.orderRRF)
) {
case "text_rank":
e += "ORDER BY text_rank DESC, rrf_score DESC";
break;
case "similarity":
e += "ORDER BY similarity DESC, rrf_score DESC";
break;
case "date_rank":
e += "ORDER BY date_rank DESC, rrf_score DESC";
break;
case "default":
e += "ORDER BY rrf_score DESC";
break;
}
(e += ` LIMIT ${this.topK})`),
n < this.wordEmbeddings.length - 1 &&
(e += ` UNION ALL
`);
}
return (
this.wordEmbeddings.length > 1
? (e = `SELECT * FROM (SELECT DISTINCT ON (result.id) * FROM ( ${e} ) result) subquery ORDER BY rrf_score DESC LIMIT ${this.upperLimit};`)
: (e += ` ORDER BY rrf_score DESC LIMIT ${this.topK};`),
await s.query(e)
);
} finally {
await i.close();
}
}
};
d.PostgresClient = o;
var r;
(function (t) {
(t.COSINE = "COSINE"), (t.IP = "IP"), (t.L2 = "L2");
})(r || (d.PostgresDistanceMetric = r = {}));
});
var I = {};
C(I, { PostgresClient: () => l.PostgresClient });
module.exports = $(I);
var l = D(u());
0 && (module.exports = { PostgresClient });
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostgresClient = void 0;
var PostgresClient_js_1 = require("./lib/postgres-client/PostgresClient.js");
Object.defineProperty(exports, "PostgresClient", { enumerable: true, get: function () { return PostgresClient_js_1.PostgresClient; } });
1 change: 0 additions & 1 deletion JS/edgechains/db/index.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions JS/edgechains/db/index.js

This file was deleted.

1 change: 0 additions & 1 deletion JS/edgechains/db/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions JS/edgechains/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PostgresClient } from "./lib/postgres-client/PostgresClient.js";
26 changes: 0 additions & 26 deletions JS/edgechains/db/src/lib/postgres-client/PostgresClient.d.ts

This file was deleted.

98 changes: 0 additions & 98 deletions JS/edgechains/db/src/lib/postgres-client/PostgresClient.js

This file was deleted.

4 changes: 3 additions & 1 deletion JS/edgechains/db/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"jsxImportSource": "hono/jsx",
"noImplicitAny": false,
"moduleResolution": "NodeNext",
"declaration": true
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
},
"exclude": ["node_modules", "dist", "./**/*.test.ts"]
}
Loading
Loading