This commit is contained in:
Morten Olsen
2025-12-09 20:32:08 +01:00
commit 2cfd54c344
54 changed files with 8794 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { cos_sim } from '@huggingface/transformers';
import { toSql } from 'pgvector';
class Vector {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
#value: any;
#dimentions: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(value: any, dimentions: number) {
this.#value = value;
this.#dimentions = dimentions;
}
public get value() {
return this.#value;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public set value(value: any) {
this.#value = value;
}
public get dimentions() {
return this.#dimentions;
}
public toSql = () => {
return toSql(this.#value);
};
public distanceTo = (other: Vector) => {
return cos_sim(this.#value, other.value);
};
}
export { Vector };