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 { 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';
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user