Skip to content

Commit

Permalink
Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
umeshma committed Feb 4, 2025
1 parent b6c63cc commit 7828ddf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
15 changes: 10 additions & 5 deletions ts/packages/knowPro/src/relatedTermsIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ export class TermToRelatedTermsIndex implements ITermToRelatedTermsIndex {
return this.termAliases.lookupTerm(termText);
}

public lookupTermFuzzy(termText: string): Promise<Term[] | undefined> {
public async lookupTermFuzzy(
termText: string,
): Promise<Term[] | undefined> {
if (this.termEmbeddingsIndex) {
return this.termEmbeddingsIndex.lookupTermsFuzzy(termText);
return await this.termEmbeddingsIndex.lookupTermsFuzzy(termText);
}
return Promise.resolve(undefined);
return undefined;
}

public serialize(): ITermsToRelatedTermsIndexData {
Expand Down Expand Up @@ -294,10 +296,13 @@ export type TextEmbeddingIndexSettings = {
retryPauseMs?: number;
};

export function createTextEmbeddingIndexSettings(): TextEmbeddingIndexSettings {
export function createTextEmbeddingIndexSettings(
maxMatches = 100,
minScore = 0.8,
): TextEmbeddingIndexSettings {
return {
embeddingModel: createEmbeddingCache(openai.createEmbeddingModel(), 64),
minScore: 0.8,
minScore,
retryMaxAttempts: 2,
retryPauseMs: 2000,
};
Expand Down
21 changes: 11 additions & 10 deletions ts/packages/knowPro/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export async function searchConversation(
return undefined;
}
const queryBuilder = new SearchQueryBuilder(conversation);
const query = queryBuilder.compile(
const query = await queryBuilder.compile(
searchTerms,
propertyTerms,
filter,
maxMatches,
);
const queryResults = await query.eval(new q.QueryEvalContext(conversation));
const queryResults = query.eval(new q.QueryEvalContext(conversation));
return toGroupedSearchResults(queryResults);
}

Expand All @@ -95,13 +95,20 @@ class SearchQueryBuilder {

constructor(public conversation: IConversation) {}

public compile(
public async compile(
terms: SearchTerm[],
propertyTerms?: Record<string, string>,
filter?: SearchFilter,
maxMatches?: number,
) {
let selectExpr = this.compileSelect(terms, propertyTerms, filter);
// Resolve related terms for all search terms, as needed
if (this.conversation.termToRelatedTermsIndex) {
await resolveRelatedTerms(
this.conversation.termToRelatedTermsIndex,
this.allSearchTerms,
);
}
this.prepareSearchTerms(this.allSearchTerms);
const query = new q.SelectTopNKnowledgeGroupExpr(
new q.GroupByKnowledgeTypeExpr(selectExpr),
Expand Down Expand Up @@ -184,13 +191,7 @@ class SearchQueryBuilder {
return predicates;
}

private async prepareSearchTerms(searchTerms: SearchTerm[]): Promise<void> {
if (this.conversation.termToRelatedTermsIndex) {
await resolveRelatedTerms(
this.conversation.termToRelatedTermsIndex,
searchTerms,
);
}
private prepareSearchTerms(searchTerms: SearchTerm[]): void {
for (const searchTerm of searchTerms) {
this.prepareTerm(searchTerm.term);
if (searchTerm.relatedTerms) {
Expand Down

0 comments on commit 7828ddf

Please sign in to comment.