Fehlerbehebung & Start Vector Search

This commit is contained in:
2024-07-11 17:09:35 +02:00
parent 7bd5e1aaf8
commit b4644ea295
20 changed files with 381 additions and 245 deletions

View File

@@ -36,7 +36,7 @@
"@nestjs/serve-static": "^4.0.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.30.8",
"drizzle-orm": "^0.32.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",
"jwks-rsa": "^3.1.0",
@@ -44,13 +44,13 @@
"nest-winston": "^1.9.4",
"nodemailer": "^6.9.10",
"nodemailer-smtp-transport": "^2.7.4",
"openai": "^4.52.6",
"passport": "^0.7.0",
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.11.5",
"redis": "^4.6.13",
"redis-om": "^0.4.3",
"pgvector": "^0.2.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"sharp": "^0.33.2",
@@ -77,7 +77,7 @@
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"commander": "^12.0.0",
"drizzle-kit": "^0.20.16",
"drizzle-kit": "^0.23.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",

View File

@@ -2,6 +2,7 @@ import 'dotenv/config';
import { drizzle } from 'drizzle-orm/node-postgres';
import { existsSync, readFileSync, readdirSync, statSync, unlinkSync } from 'fs';
import fs from 'fs-extra';
import OpenAI from 'openai';
import { join } from 'path';
import pkg from 'pg';
import { rimraf } from 'rimraf';
@@ -11,6 +12,10 @@ import { emailToDirName } from 'src/models/main.model.js';
import * as schema from './schema.js';
const { Pool } = pkg;
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // Stellen Sie sicher, dass Sie Ihren API-Key als Umgebungsvariable setzen
});
const connectionString = process.env.DATABASE_URL;
// const pool = new Pool({connectionString})
const client = new Pool({ connectionString });
@@ -124,6 +129,14 @@ for (const commercial of commercialJsonData) {
//End
await client.end();
async function createEmbedding(text: string): Promise<number[]> {
const response = await openai.embeddings.create({
model: 'text-embedding-ada-002',
input: text,
});
return response.data[0].embedding;
}
function getRandomItem<T>(arr: T[]): T {
if (arr.length === 0) {
throw new Error('The array is empty.');

View File

@@ -1,6 +1,5 @@
import { boolean, char, doublePrecision, integer, jsonb, pgEnum, pgTable, serial, text, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
import { boolean, char, doublePrecision, integer, jsonb, pgEnum, pgTable, serial, text, timestamp, uuid, varchar, vector } from 'drizzle-orm/pg-core';
import { AreasServed, LicensedIn } from 'src/models/db.model';
export const PG_CONNECTION = 'PG_CONNECTION';
export const genderEnum = pgEnum('gender', ['male', 'female']);
export const customerTypeEnum = pgEnum('customerType', ['buyer', 'professional']);
@@ -58,6 +57,9 @@ export const businesses = pgTable('businesses', {
updated: timestamp('updated'),
visits: integer('visits'),
lastVisit: timestamp('lastVisit'),
// Neue Spalte für das OpenAI Embedding
embedding: vector('embedding', { dimensions: 1536 }),
// embedding: sql`vector(1536)`,
});
export const commercials = pgTable('commercials', {