mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-12 20:02:28 +08:00
create note_embedding object for becca
This commit is contained in:
parent
8d7e5c8d43
commit
67766e3e9f
73
src/becca/entities/bnote_embedding.ts
Normal file
73
src/becca/entities/bnote_embedding.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
import AbstractBeccaEntity from "./abstract_becca_entity.js";
|
||||||
|
import dateUtils from "../../services/date_utils.js";
|
||||||
|
import type { NoteEmbeddingRow } from "./rows.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity representing a note's vector embedding for semantic search and AI features
|
||||||
|
*/
|
||||||
|
class BNoteEmbedding extends AbstractBeccaEntity<BNoteEmbedding> {
|
||||||
|
static get entityName() {
|
||||||
|
return "note_embeddings";
|
||||||
|
}
|
||||||
|
static get primaryKeyName() {
|
||||||
|
return "embedId";
|
||||||
|
}
|
||||||
|
static get hashedProperties() {
|
||||||
|
return ["embedId", "noteId", "providerId", "modelId", "dimension", "version"];
|
||||||
|
}
|
||||||
|
|
||||||
|
embedId!: string;
|
||||||
|
noteId!: string;
|
||||||
|
providerId!: string;
|
||||||
|
modelId!: string;
|
||||||
|
dimension!: number;
|
||||||
|
embedding!: Buffer;
|
||||||
|
version!: number;
|
||||||
|
|
||||||
|
constructor(row?: NoteEmbeddingRow) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (row) {
|
||||||
|
this.updateFromRow(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFromRow(row: NoteEmbeddingRow): void {
|
||||||
|
this.embedId = row.embedId;
|
||||||
|
this.noteId = row.noteId;
|
||||||
|
this.providerId = row.providerId;
|
||||||
|
this.modelId = row.modelId;
|
||||||
|
this.dimension = row.dimension;
|
||||||
|
this.embedding = row.embedding;
|
||||||
|
this.version = row.version;
|
||||||
|
this.dateCreated = row.dateCreated;
|
||||||
|
this.dateModified = row.dateModified;
|
||||||
|
this.utcDateCreated = row.utcDateCreated;
|
||||||
|
this.utcDateModified = row.utcDateModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeSaving() {
|
||||||
|
super.beforeSaving();
|
||||||
|
|
||||||
|
this.dateModified = dateUtils.localNowDateTime();
|
||||||
|
this.utcDateModified = dateUtils.utcNowDateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
getPojo(): NoteEmbeddingRow {
|
||||||
|
return {
|
||||||
|
embedId: this.embedId,
|
||||||
|
noteId: this.noteId,
|
||||||
|
providerId: this.providerId,
|
||||||
|
modelId: this.modelId,
|
||||||
|
dimension: this.dimension,
|
||||||
|
embedding: this.embedding,
|
||||||
|
version: this.version,
|
||||||
|
dateCreated: this.dateCreated!,
|
||||||
|
dateModified: this.dateModified!,
|
||||||
|
utcDateCreated: this.utcDateCreated,
|
||||||
|
utcDateModified: this.utcDateModified!
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BNoteEmbedding;
|
@ -139,3 +139,17 @@ export interface NoteRow {
|
|||||||
utcDateModified: string;
|
utcDateModified: string;
|
||||||
content?: string | Buffer;
|
content?: string | Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NoteEmbeddingRow {
|
||||||
|
embedId: string;
|
||||||
|
noteId: string;
|
||||||
|
providerId: string;
|
||||||
|
modelId: string;
|
||||||
|
dimension: number;
|
||||||
|
embedding: Buffer;
|
||||||
|
version: number;
|
||||||
|
dateCreated: string;
|
||||||
|
utcDateCreated: string;
|
||||||
|
dateModified: string;
|
||||||
|
utcDateModified: string;
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import BBlob from "./entities/bblob.js";
|
|||||||
import BBranch from "./entities/bbranch.js";
|
import BBranch from "./entities/bbranch.js";
|
||||||
import BEtapiToken from "./entities/betapi_token.js";
|
import BEtapiToken from "./entities/betapi_token.js";
|
||||||
import BNote from "./entities/bnote.js";
|
import BNote from "./entities/bnote.js";
|
||||||
|
import BNoteEmbedding from "./entities/bnote_embedding.js";
|
||||||
import BOption from "./entities/boption.js";
|
import BOption from "./entities/boption.js";
|
||||||
import BRecentNote from "./entities/brecent_note.js";
|
import BRecentNote from "./entities/brecent_note.js";
|
||||||
import BRevision from "./entities/brevision.js";
|
import BRevision from "./entities/brevision.js";
|
||||||
@ -19,6 +20,7 @@ const ENTITY_NAME_TO_ENTITY: Record<string, ConstructorData<any> & EntityClass>
|
|||||||
branches: BBranch,
|
branches: BBranch,
|
||||||
etapi_tokens: BEtapiToken,
|
etapi_tokens: BEtapiToken,
|
||||||
notes: BNote,
|
notes: BNote,
|
||||||
|
note_embeddings: BNoteEmbedding,
|
||||||
options: BOption,
|
options: BOption,
|
||||||
recent_notes: BRecentNote,
|
recent_notes: BRecentNote,
|
||||||
revisions: BRevision
|
revisions: BRevision
|
||||||
|
Loading…
x
Reference in New Issue
Block a user