From 43ae67c86518c32af7f33feb1432583c80bd0cfe Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Fri, 24 Oct 2025 14:11:08 -0700 Subject: [PATCH] feat: align search service with full UrlMetadata props Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) --- .../cards/domain/value-objects/UrlMetadata.ts | 2 +- src/modules/search/domain/IVectorDatabase.ts | 13 +++-------- .../search/domain/services/SearchService.ts | 22 ++++++++++++------- .../infrastructure/UpstashVectorDatabase.ts | 18 ++++++++++----- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/modules/cards/domain/value-objects/UrlMetadata.ts b/src/modules/cards/domain/value-objects/UrlMetadata.ts index 8352e19e..ab9ccd23 100644 --- a/src/modules/cards/domain/value-objects/UrlMetadata.ts +++ b/src/modules/cards/domain/value-objects/UrlMetadata.ts @@ -1,7 +1,7 @@ import { ValueObject } from '../../../../shared/domain/ValueObject'; import { Result, ok, err } from '../../../../shared/core/Result'; -interface UrlMetadataProps { +export interface UrlMetadataProps { url: string; title?: string; description?: string; diff --git a/src/modules/search/domain/IVectorDatabase.ts b/src/modules/search/domain/IVectorDatabase.ts index 687bf39f..bfe27f0b 100644 --- a/src/modules/search/domain/IVectorDatabase.ts +++ b/src/modules/search/domain/IVectorDatabase.ts @@ -1,10 +1,7 @@ import { Result } from '../../../shared/core/Result'; +import { UrlMetadataProps } from '../../cards/domain/value-objects/UrlMetadata'; -export interface IndexUrlParams { - url: string; - title?: string; - description?: string; - author?: string; +export interface IndexUrlParams extends UrlMetadataProps { content: string; // Combined text for embedding } @@ -17,11 +14,7 @@ export interface FindSimilarUrlsParams { export interface UrlSearchResult { url: string; similarity: number; - metadata: { - title?: string; - description?: string; - author?: string; - }; + metadata: UrlMetadataProps; } export interface IVectorDatabase { diff --git a/src/modules/search/domain/services/SearchService.ts b/src/modules/search/domain/services/SearchService.ts index 64ee71fa..587e042a 100644 --- a/src/modules/search/domain/services/SearchService.ts +++ b/src/modules/search/domain/services/SearchService.ts @@ -5,6 +5,7 @@ import { ICardQueryRepository } from '../../../cards/domain/ICardQueryRepository import { IVectorDatabase, FindSimilarUrlsParams } from '../IVectorDatabase'; import { UrlView } from '@semble/types/api/responses'; import { CardSortField, SortOrder } from '@semble/types/api/common'; +import { UrlMetadataProps } from 'src/modules/cards/domain/value-objects/UrlMetadata'; export class SearchService { constructor( @@ -29,11 +30,17 @@ export class SearchService { // 2. Index in vector database const indexResult = await this.vectorDatabase.indexUrl({ - url: url.value, + url: metadata.url, title: metadata.title, description: metadata.description, author: metadata.author, - content: '', // Let the vector database implementation handle content preparation + publishedDate: metadata.publishedDate, + siteName: metadata.siteName, + imageUrl: metadata.imageUrl, + type: metadata.type, + content: [metadata.title, metadata.description] + .filter(Boolean) + .join(' '), }); if (indexResult.isErr()) { @@ -96,11 +103,7 @@ export class SearchService { searchResults: Array<{ url: string; similarity: number; - metadata: { - title?: string; - description?: string; - author?: string; - }; + metadata: UrlMetadataProps; }>, callingUserId?: string, ): Promise { @@ -133,7 +136,10 @@ export class SearchService { title: result.metadata.title, description: result.metadata.description, author: result.metadata.author, - thumbnailUrl: undefined, // Could be enriched from metadata service if needed + siteName: result.metadata.siteName, + imageUrl: result.metadata.imageUrl, + type: result.metadata.type, + thumbnailUrl: result.metadata.imageUrl, // Use imageUrl as thumbnailUrl }, urlLibraryCount, urlInLibrary, diff --git a/src/modules/search/infrastructure/UpstashVectorDatabase.ts b/src/modules/search/infrastructure/UpstashVectorDatabase.ts index ce004943..0d1aa1ea 100644 --- a/src/modules/search/infrastructure/UpstashVectorDatabase.ts +++ b/src/modules/search/infrastructure/UpstashVectorDatabase.ts @@ -6,12 +6,10 @@ import { FindSimilarUrlsParams, UrlSearchResult, } from '../domain/IVectorDatabase'; +import { UrlMetadataProps } from '../../cards/domain/value-objects/UrlMetadata'; -interface UpstashMetadata { - title?: string; - description?: string; - author?: string; - [key: string]: any; // Add this index signature +interface UpstashMetadata extends UrlMetadataProps { + [key: string]: any; // Add this index signature for additional flexibility } export class UpstashVectorDatabase implements IVectorDatabase { @@ -35,9 +33,14 @@ export class UpstashVectorDatabase implements IVectorDatabase { id: params.url, data: dataContent || params.url, // Fallback to URL if no content metadata: { + url: params.url, title: params.title, description: params.description, author: params.author, + publishedDate: params.publishedDate, + siteName: params.siteName, + imageUrl: params.imageUrl, + type: params.type, }, }); return ok(undefined); @@ -84,9 +87,14 @@ export class UpstashVectorDatabase implements IVectorDatabase { url: result.id as string, // Cast to string since we use URLs as IDs similarity: result.score, metadata: { + url: result.metadata?.url || (result.id as string), title: result.metadata?.title, description: result.metadata?.description, author: result.metadata?.author, + publishedDate: result.metadata?.publishedDate, + siteName: result.metadata?.siteName, + imageUrl: result.metadata?.imageUrl, + type: result.metadata?.type, }, }); } -- 2.51.2