fix: issue in document matching
Some checks failed
Build and release / Build (push) Failing after 1m11s
Build and release / update-release-draft (push) Has been skipped
Build and release / Release (push) Has been skipped

This commit is contained in:
Morten Olsen
2025-12-11 08:47:58 +01:00
parent 68abe3ce79
commit f6799586f4
3 changed files with 7 additions and 3 deletions

View File

@@ -2,7 +2,6 @@ import { DatabaseService, tableNames, type TableRows } from '../database/databas
import { EmbeddingsService } from '../embeddings/embeddings.js'; import { EmbeddingsService } from '../embeddings/embeddings.js';
import type { Services } from '../../utils/utils.services.js'; import type { Services } from '../../utils/utils.services.js';
import { EMBEDDING_MODEL } from '../../utils/utils.consts.js'; import { EMBEDDING_MODEL } from '../../utils/utils.consts.js';
import type { ExplicitAny } from '../../global.js';
import { applyQueryFilter } from '../../utils/utils.query.js'; import { applyQueryFilter } from '../../utils/utils.query.js';
import type { DocumentChunkFilter, DocumentChunksFindResult } from './document-chunks.schemas.js'; import type { DocumentChunkFilter, DocumentChunksFindResult } from './document-chunks.schemas.js';

View File

@@ -191,7 +191,7 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
const result = await db.transaction(async (trx) => { const result = await db.transaction(async (trx) => {
let id = document.id || crypto.randomUUID(); let id = document.id || crypto.randomUUID();
if (document.source && document.sourceId) { if (!document.id && document.source && document.sourceId) {
const [currentSourceDocument] = await trx<TableRows['documents']>(tableNames.documents) const [currentSourceDocument] = await trx<TableRows['documents']>(tableNames.documents)
.where('source', document.source) .where('source', document.source)
.andWhere('sourceId', document.sourceId) .andWhere('sourceId', document.sourceId)
@@ -203,6 +203,8 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
const now = new Date(); const now = new Date();
const [current] = await trx<TableRows['documents']>(tableNames.documents).where('id', id).limit(1); const [current] = await trx<TableRows['documents']>(tableNames.documents).where('id', id).limit(1);
if (current) { if (current) {
id = current.id;
document.id = id;
if ( if (
compareObjectKeys(current, document, [ compareObjectKeys(current, document, [
'sourceId', 'sourceId',
@@ -249,7 +251,7 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
updatedAt: now, updatedAt: now,
}); });
const resultDocument: Document = mapFromDocumentRow({ const resultDocument: Document = mapFromDocumentRow({
type: 'raw', type: null,
text: null, text: null,
owner: null, owner: null,
contentType: null, contentType: null,

View File

@@ -8,6 +8,9 @@ const compareObjectKeys = <A extends Record<string, unknown>, B extends Record<s
for (const key of keys) { for (const key of keys) {
const avalue = a[key as keyof A]; const avalue = a[key as keyof A];
const bvalue = b[key as keyof B]; const bvalue = b[key as keyof B];
if (bvalue === undefined) {
continue;
}
if (!deepEqual(avalue, bvalue)) { if (!deepEqual(avalue, bvalue)) {
return false; return false;
} }