init
This commit is contained in:
37
packages/server/src/services/embeddings/embeddings.vector.ts
Normal file
37
packages/server/src/services/embeddings/embeddings.vector.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user