add semantic search

This commit is contained in:
2024-05-31 01:31:37 -04:00
parent 53635f0d59
commit de9cccabda
19 changed files with 1398 additions and 105 deletions

File diff suppressed because one or more lines are too long

24
src/lib/utils/search.ts Normal file
View File

@@ -0,0 +1,24 @@
// src/lib/initModel.ts
import use, { UniversalSentenceEncoder } from '@tensorflow-models/universal-sentence-encoder';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import * as tf from '@tensorflow/tfjs-node';
export type Embedding = {
id: string;
vector: number[];
};
export type SearchResult = {
poem: Embedding;
similarity: number;
};
let model: UniversalSentenceEncoder | null = null;
export async function getModel(): Promise<UniversalSentenceEncoder> {
if (!model) {
model = await use.load();
console.log('Model loaded successfully!');
}
return model;
}