mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:39:37 -05:00 
			
		
		
		
	chore(server): change upsert signature for search repo (#8210)
* upsert embedding * remove unused imports
This commit is contained in:
		
							parent
							
								
									787eebcf1e
								
							
						
					
					
						commit
						b07a565e34
					
				@ -1,7 +1,6 @@
 | 
				
			|||||||
import { AssetFaceEntity } from 'src/entities/asset-face.entity';
 | 
					import { AssetFaceEntity } from 'src/entities/asset-face.entity';
 | 
				
			||||||
import { AssetEntity, AssetType } from 'src/entities/asset.entity';
 | 
					import { AssetEntity, AssetType } from 'src/entities/asset.entity';
 | 
				
			||||||
import { GeodataPlacesEntity } from 'src/entities/geodata-places.entity';
 | 
					import { GeodataPlacesEntity } from 'src/entities/geodata-places.entity';
 | 
				
			||||||
import { SmartInfoEntity } from 'src/entities/smart-info.entity';
 | 
					 | 
				
			||||||
import { Paginated } from 'src/utils/pagination';
 | 
					import { Paginated } from 'src/utils/pagination';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const ISearchRepository = 'ISearchRepository';
 | 
					export const ISearchRepository = 'ISearchRepository';
 | 
				
			||||||
@ -188,7 +187,7 @@ export interface ISearchRepository {
 | 
				
			|||||||
  searchMetadata(pagination: SearchPaginationOptions, options: AssetSearchOptions): Paginated<AssetEntity>;
 | 
					  searchMetadata(pagination: SearchPaginationOptions, options: AssetSearchOptions): Paginated<AssetEntity>;
 | 
				
			||||||
  searchSmart(pagination: SearchPaginationOptions, options: SmartSearchOptions): Paginated<AssetEntity>;
 | 
					  searchSmart(pagination: SearchPaginationOptions, options: SmartSearchOptions): Paginated<AssetEntity>;
 | 
				
			||||||
  searchFaces(search: FaceEmbeddingSearch): Promise<FaceSearchResult[]>;
 | 
					  searchFaces(search: FaceEmbeddingSearch): Promise<FaceSearchResult[]>;
 | 
				
			||||||
  upsert(smartInfo: Partial<SmartInfoEntity>, embedding?: Embedding): Promise<void>;
 | 
					  upsert(assetId: string, embedding: number[]): Promise<void>;
 | 
				
			||||||
  searchPlaces(placeName: string): Promise<GeodataPlacesEntity[]>;
 | 
					  searchPlaces(placeName: string): Promise<GeodataPlacesEntity[]>;
 | 
				
			||||||
  getAssetsByCity(userIds: string[]): Promise<AssetEntity[]>;
 | 
					  getAssetsByCity(userIds: string[]): Promise<AssetEntity[]>;
 | 
				
			||||||
  deleteAllSearchEmbeddings(): Promise<void>;
 | 
					  deleteAllSearchEmbeddings(): Promise<void>;
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,6 @@ import { SmartSearchEntity } from 'src/entities/smart-search.entity';
 | 
				
			|||||||
import { DatabaseExtension } from 'src/interfaces/database.interface';
 | 
					import { DatabaseExtension } from 'src/interfaces/database.interface';
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  AssetSearchOptions,
 | 
					  AssetSearchOptions,
 | 
				
			||||||
  Embedding,
 | 
					 | 
				
			||||||
  FaceEmbeddingSearch,
 | 
					  FaceEmbeddingSearch,
 | 
				
			||||||
  FaceSearchResult,
 | 
					  FaceSearchResult,
 | 
				
			||||||
  ISearchRepository,
 | 
					  ISearchRepository,
 | 
				
			||||||
@ -247,16 +246,7 @@ export class SearchRepository implements ISearchRepository {
 | 
				
			|||||||
    return items;
 | 
					    return items;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async upsert(smartInfo: Partial<SmartInfoEntity>, embedding?: Embedding): Promise<void> {
 | 
					  async upsert(assetId: string, embedding: number[]): Promise<void> {
 | 
				
			||||||
    await this.repository.upsert(smartInfo, { conflictPaths: ['assetId'] });
 | 
					 | 
				
			||||||
    if (!smartInfo.assetId || !embedding) {
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await this.upsertEmbedding(smartInfo.assetId, embedding);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  private async upsertEmbedding(assetId: string, embedding: number[]): Promise<void> {
 | 
					 | 
				
			||||||
    await this.smartSearchRepository.upsert(
 | 
					    await this.smartSearchRepository.upsert(
 | 
				
			||||||
      { assetId, embedding: () => asVector(embedding, true) },
 | 
					      { assetId, embedding: () => asVector(embedding, true) },
 | 
				
			||||||
      { conflictPaths: ['assetId'] },
 | 
					      { conflictPaths: ['assetId'] },
 | 
				
			||||||
 | 
				
			|||||||
@ -104,7 +104,6 @@ describe(SmartInfoService.name, () => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    it('should save the returned objects', async () => {
 | 
					    it('should save the returned objects', async () => {
 | 
				
			||||||
      searchMock.upsert.mockResolvedValue();
 | 
					 | 
				
			||||||
      machineMock.encodeImage.mockResolvedValue([0.01, 0.02, 0.03]);
 | 
					      machineMock.encodeImage.mockResolvedValue([0.01, 0.02, 0.03]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      await sut.handleEncodeClip({ id: asset.id });
 | 
					      await sut.handleEncodeClip({ id: asset.id });
 | 
				
			||||||
@ -114,12 +113,7 @@ describe(SmartInfoService.name, () => {
 | 
				
			|||||||
        { imagePath: 'path/to/resize.ext' },
 | 
					        { imagePath: 'path/to/resize.ext' },
 | 
				
			||||||
        { enabled: true, modelName: 'ViT-B-32__openai' },
 | 
					        { enabled: true, modelName: 'ViT-B-32__openai' },
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      expect(searchMock.upsert).toHaveBeenCalledWith(
 | 
					      expect(searchMock.upsert).toHaveBeenCalledWith('asset-1', [0.01, 0.02, 0.03]);
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
          assetId: 'asset-1',
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        [0.01, 0.02, 0.03],
 | 
					 | 
				
			||||||
      );
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -98,7 +98,7 @@ export class SmartInfoService {
 | 
				
			|||||||
      await this.databaseRepository.wait(DatabaseLock.CLIPDimSize);
 | 
					      await this.databaseRepository.wait(DatabaseLock.CLIPDimSize);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await this.repository.upsert({ assetId: asset.id }, clipEmbedding);
 | 
					    await this.repository.upsert(asset.id, clipEmbedding);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return JobStatus.SUCCESS;
 | 
					    return JobStatus.SUCCESS;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user