implementing radio button option to select hybrid vs semantic
This commit is contained in:
@@ -129,9 +129,14 @@ async def vector_search_topics(
|
||||
int,
|
||||
Query(description="Maximum number of topics to return.", ge=1, le=100),
|
||||
] = 25,
|
||||
search_type: Annotated[
|
||||
str,
|
||||
Query(alias="searchType", description="Search approach: 'hybrid' or 'semantic'."),
|
||||
] = "hybrid",
|
||||
):
|
||||
return await logic.vector_search_topics(
|
||||
query=query,
|
||||
limit=limit,
|
||||
search_type=search_type,
|
||||
)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,37 @@
|
||||
<div class="hierarchy-container">
|
||||
@if (searchQuery) {
|
||||
<div
|
||||
class="search-mode-selector"
|
||||
style="
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.08);
|
||||
padding-bottom: 8px;
|
||||
">
|
||||
<span
|
||||
style="
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--sg-text);
|
||||
opacity: 0.8;
|
||||
"
|
||||
>Modus:</span
|
||||
>
|
||||
<mat-radio-group
|
||||
[value]="searchType()"
|
||||
(change)="onSearchTypeChange($event.value)"
|
||||
style="display: flex; gap: 16px">
|
||||
<mat-radio-button value="hybrid">
|
||||
<span style="font-size: 12px; color: var(--sg-text)">Hybrid</span>
|
||||
</mat-radio-button>
|
||||
<mat-radio-button value="semantic">
|
||||
<span style="font-size: 12px; color: var(--sg-text)">Semantisch</span>
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
</div>
|
||||
}
|
||||
@if (loading()) {
|
||||
<div class="loading-state">
|
||||
<mat-spinner diameter="24"></mat-spinner>
|
||||
|
||||
@@ -10,6 +10,7 @@ import { CommonModule } from '@angular/common';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { TopicsService } from '../../api/api/topics.service';
|
||||
import { Subject, of } from 'rxjs';
|
||||
import {
|
||||
@@ -53,6 +54,7 @@ interface FlatTopic {
|
||||
MatCheckboxModule,
|
||||
MatIconModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatRadioModule,
|
||||
],
|
||||
templateUrl: './topic-hierarchy.component.html',
|
||||
styleUrl: './topic-hierarchy.component.scss',
|
||||
@@ -80,38 +82,47 @@ export class TopicHierarchyComponent implements OnInit {
|
||||
flatTopics: FlatTopic[] = [];
|
||||
filteredFlatTopics: FlatTopic[] = [];
|
||||
loading = signal(true);
|
||||
searchType = signal<'hybrid' | 'semantic'>('hybrid');
|
||||
|
||||
// Set of names of expanded nodes (lazy content rendering)
|
||||
expandedDomains = new Set<string>();
|
||||
expandedFields = new Set<string>();
|
||||
expandedSubfields = new Set<string>();
|
||||
|
||||
private readonly searchSubject = new Subject<string>();
|
||||
private readonly searchSubject = new Subject<{
|
||||
query: string;
|
||||
searchType: 'hybrid' | 'semantic';
|
||||
}>();
|
||||
|
||||
constructor(private topicsService: TopicsService) {
|
||||
this.searchSubject
|
||||
.pipe(
|
||||
debounceTime(300),
|
||||
distinctUntilChanged(),
|
||||
switchMap((query) => {
|
||||
distinctUntilChanged(
|
||||
(prev, curr) =>
|
||||
prev.query === curr.query && prev.searchType === curr.searchType,
|
||||
),
|
||||
switchMap(({ query, searchType }) => {
|
||||
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: [] });
|
||||
}),
|
||||
);
|
||||
return this.topicsService
|
||||
.vectorSearchTopics(query, 50, searchType)
|
||||
.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) => {
|
||||
@@ -175,7 +186,15 @@ export class TopicHierarchyComponent implements OnInit {
|
||||
this.filteredFlatTopics = [];
|
||||
return;
|
||||
}
|
||||
this.searchSubject.next(this.searchQuery);
|
||||
this.searchSubject.next({
|
||||
query: this.searchQuery,
|
||||
searchType: this.searchType(),
|
||||
});
|
||||
}
|
||||
|
||||
onSearchTypeChange(type: 'hybrid' | 'semantic'): void {
|
||||
this.searchType.set(type);
|
||||
this.filterFlatTopics();
|
||||
}
|
||||
|
||||
toggleTopic(name: string): void {
|
||||
|
||||
Reference in New Issue
Block a user