Implemented Sentence-Transformer (Setup, Backend & Frontend) => downloading custom torch wheel to not pull gpu packages
This commit is contained in:
@@ -702,4 +702,126 @@ export class TopicsService
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Semantic / vector search for topics using a keyword/sentence.
|
||||
* @endpoint get /api/topics/vector-search
|
||||
* @param query Word or sentence to search by similarity.
|
||||
* @param limit Maximum number of topics to return.
|
||||
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
|
||||
* @param reportProgress flag to report request and response progress.
|
||||
*/
|
||||
public vectorSearchTopics(
|
||||
query: string,
|
||||
limit?: number,
|
||||
observe?: 'body',
|
||||
reportProgress?: boolean,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<TopicsListResponse>;
|
||||
public vectorSearchTopics(
|
||||
query: string,
|
||||
limit?: number,
|
||||
observe?: 'response',
|
||||
reportProgress?: boolean,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<HttpResponse<TopicsListResponse>>;
|
||||
public vectorSearchTopics(
|
||||
query: string,
|
||||
limit?: number,
|
||||
observe?: 'events',
|
||||
reportProgress?: boolean,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<HttpEvent<TopicsListResponse>>;
|
||||
public vectorSearchTopics(
|
||||
query: string,
|
||||
limit?: number,
|
||||
observe: any = 'body',
|
||||
reportProgress: boolean = false,
|
||||
options?: {
|
||||
httpHeaderAccept?: 'application/json';
|
||||
context?: HttpContext;
|
||||
transferCache?: boolean;
|
||||
},
|
||||
): Observable<any> {
|
||||
if (query === null || query === undefined) {
|
||||
throw new Error(
|
||||
'Required parameter query was null or undefined when calling vectorSearchTopics.',
|
||||
);
|
||||
}
|
||||
|
||||
let localVarQueryParameters = new HttpParams({ encoder: this.encoder });
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>query,
|
||||
'query',
|
||||
);
|
||||
if (limit !== undefined && limit !== null) {
|
||||
localVarQueryParameters = this.addToHttpParams(
|
||||
localVarQueryParameters,
|
||||
<any>limit,
|
||||
'limit',
|
||||
);
|
||||
}
|
||||
|
||||
let localVarHeaders = this.defaultHeaders;
|
||||
|
||||
const localVarHttpHeaderAcceptSelected: string | undefined =
|
||||
options?.httpHeaderAccept ??
|
||||
this.configuration.selectHeaderAccept(['application/json']);
|
||||
if (localVarHttpHeaderAcceptSelected !== undefined) {
|
||||
localVarHeaders = localVarHeaders.set(
|
||||
'Accept',
|
||||
localVarHttpHeaderAcceptSelected,
|
||||
);
|
||||
}
|
||||
|
||||
const localVarHttpContext: HttpContext =
|
||||
options?.context ?? new HttpContext();
|
||||
|
||||
const localVarTransferCache: boolean = options?.transferCache ?? true;
|
||||
|
||||
let responseType_: 'text' | 'json' | 'blob' = 'json';
|
||||
if (localVarHttpHeaderAcceptSelected) {
|
||||
if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
|
||||
responseType_ = 'text';
|
||||
} else if (
|
||||
this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)
|
||||
) {
|
||||
responseType_ = 'json';
|
||||
} else {
|
||||
responseType_ = 'blob';
|
||||
}
|
||||
}
|
||||
|
||||
let localVarPath = `/api/topics/vector-search`;
|
||||
const { basePath, withCredentials } = this.configuration;
|
||||
return this.httpClient.request<TopicsListResponse>(
|
||||
'get',
|
||||
`${basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
params: localVarQueryParameters,
|
||||
responseType: <any>responseType_,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
...(localVarTransferCache !== undefined
|
||||
? { transferCache: localVarTransferCache }
|
||||
: {}),
|
||||
reportProgress: reportProgress,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,4 +97,17 @@ export interface TopicsServiceInterface {
|
||||
select?: string,
|
||||
extraHttpRequestParams?: any,
|
||||
): Observable<TopicsListResponse>;
|
||||
|
||||
/**
|
||||
* Semantic / vector search for topics using a keyword/sentence.
|
||||
*
|
||||
* @endpoint get /api/topics/vector-search
|
||||
* @param query Word or sentence to search by similarity.
|
||||
* @param limit Maximum number of topics to return.
|
||||
*/
|
||||
vectorSearchTopics(
|
||||
query: string,
|
||||
limit?: number,
|
||||
extraHttpRequestParams?: any,
|
||||
): Observable<TopicsListResponse>;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { TopicsService } from '../../api/api/topics.service';
|
||||
import { Subject, of } from 'rxjs';
|
||||
import {
|
||||
debounceTime,
|
||||
distinctUntilChanged,
|
||||
switchMap,
|
||||
catchError,
|
||||
} from 'rxjs/operators';
|
||||
|
||||
export interface TopicItem {
|
||||
id: string;
|
||||
@@ -79,7 +86,54 @@ export class TopicHierarchyComponent implements OnInit {
|
||||
expandedFields = new Set<string>();
|
||||
expandedSubfields = new Set<string>();
|
||||
|
||||
constructor(private topicsService: TopicsService) {}
|
||||
private readonly searchSubject = new Subject<string>();
|
||||
|
||||
constructor(private topicsService: TopicsService) {
|
||||
this.searchSubject
|
||||
.pipe(
|
||||
debounceTime(300),
|
||||
distinctUntilChanged(),
|
||||
switchMap((query) => {
|
||||
if (!query) {
|
||||
this.filteredFlatTopics = [];
|
||||
return of({ results: [] });
|
||||
}
|
||||
this.loading.set(true);
|
||||
return this.topicsService.vectorSearchTopics(query, 50).pipe(
|
||||
catchError((err) => {
|
||||
console.error('Error in semantic topic search:', err);
|
||||
// Fallback to local filtering
|
||||
const q = query.toLowerCase();
|
||||
this.filteredFlatTopics = this.flatTopics.filter(
|
||||
(t) =>
|
||||
t.name.toLowerCase().includes(q) ||
|
||||
t.path.toLowerCase().includes(q),
|
||||
);
|
||||
return of({ results: [] });
|
||||
}),
|
||||
);
|
||||
}),
|
||||
)
|
||||
.subscribe((response) => {
|
||||
this.loading.set(false);
|
||||
if (response && response.results) {
|
||||
this.filteredFlatTopics = response.results.map((topic) => {
|
||||
const parts = [];
|
||||
if (topic.domain?.display_name)
|
||||
parts.push(topic.domain.display_name);
|
||||
if (topic.field?.display_name) parts.push(topic.field.display_name);
|
||||
if (topic.subfield?.display_name)
|
||||
parts.push(topic.subfield.display_name);
|
||||
return {
|
||||
id: topic.id || '',
|
||||
name: topic.display_name || '',
|
||||
path:
|
||||
parts.length > 0 ? parts.join(' > ') : topic.description || '',
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.topicsService.getTopicHierarchy().subscribe({
|
||||
@@ -121,12 +175,7 @@ export class TopicHierarchyComponent implements OnInit {
|
||||
this.filteredFlatTopics = [];
|
||||
return;
|
||||
}
|
||||
const query = this.searchQuery.toLowerCase();
|
||||
this.filteredFlatTopics = this.flatTopics.filter(
|
||||
(t) =>
|
||||
t.name.toLowerCase().includes(query) ||
|
||||
t.path.toLowerCase().includes(query),
|
||||
);
|
||||
this.searchSubject.next(this.searchQuery);
|
||||
}
|
||||
|
||||
toggleTopic(name: string): void {
|
||||
|
||||
Reference in New Issue
Block a user