fix: issue in document matching
This commit is contained in:
@@ -2,7 +2,6 @@ import { DatabaseService, tableNames, type TableRows } from '../database/databas
|
||||
import { EmbeddingsService } from '../embeddings/embeddings.js';
|
||||
import type { Services } from '../../utils/utils.services.js';
|
||||
import { EMBEDDING_MODEL } from '../../utils/utils.consts.js';
|
||||
import type { ExplicitAny } from '../../global.js';
|
||||
import { applyQueryFilter } from '../../utils/utils.query.js';
|
||||
|
||||
import type { DocumentChunkFilter, DocumentChunksFindResult } from './document-chunks.schemas.js';
|
||||
|
||||
@@ -191,7 +191,7 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
|
||||
|
||||
const result = await db.transaction(async (trx) => {
|
||||
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)
|
||||
.where('source', document.source)
|
||||
.andWhere('sourceId', document.sourceId)
|
||||
@@ -203,6 +203,8 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
|
||||
const now = new Date();
|
||||
const [current] = await trx<TableRows['documents']>(tableNames.documents).where('id', id).limit(1);
|
||||
if (current) {
|
||||
id = current.id;
|
||||
document.id = id;
|
||||
if (
|
||||
compareObjectKeys(current, document, [
|
||||
'sourceId',
|
||||
@@ -249,7 +251,7 @@ class DocumentsService extends EventEmitter<DocumentsServiceEvents> {
|
||||
updatedAt: now,
|
||||
});
|
||||
const resultDocument: Document = mapFromDocumentRow({
|
||||
type: 'raw',
|
||||
type: null,
|
||||
text: null,
|
||||
owner: null,
|
||||
contentType: null,
|
||||
|
||||
@@ -8,6 +8,9 @@ const compareObjectKeys = <A extends Record<string, unknown>, B extends Record<s
|
||||
for (const key of keys) {
|
||||
const avalue = a[key as keyof A];
|
||||
const bvalue = b[key as keyof B];
|
||||
if (bvalue === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (!deepEqual(avalue, bvalue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user