Skip to content

Commit e49a86c

Browse files
committed
Add hybrid fusion type support
1 parent ebad76d commit e49a86c

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

src/graphql/getter.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Getter from './getter';
1+
import Getter, { FusionType } from './getter';
22
import { WhereFilter } from '../openapi/types';
33
import { NearObjectArgs } from './nearObject';
44
import { AskArgs } from './ask';
@@ -1242,6 +1242,19 @@ describe('hybrid valid searchers', () => {
12421242

12431243
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
12441244
});
1245+
1246+
test('query and alpha 0 and fusionType', () => {
1247+
const subQuery = `(hybrid:{query:"accountant",alpha:0,fusionType:rankedFusion})`;
1248+
const expectedQuery = `{Get{Person` + subQuery + `{name}}}`;
1249+
1250+
new Getter(mockClient)
1251+
.withClassName('Person')
1252+
.withFields('name')
1253+
.withHybrid({ query: 'accountant', alpha: 0, fusionType: FusionType.rankedFusion })
1254+
.do();
1255+
1256+
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
1257+
});
12451258
});
12461259

12471260
describe('generative search', () => {

src/graphql/getter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { GenerateArgs, GraphQLGenerate } from './generate';
1515
import { ConsistencyLevel } from '../data';
1616
import GroupBy, { GroupByArgs } from './groupBy';
1717

18+
export { FusionType } from './hybrid';
1819
export default class GraphQLGetter extends CommandBase {
1920
private after?: string;
2021
private askString?: string;

src/graphql/hybrid.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ export interface HybridArgs {
33
query: string;
44
vector?: number[];
55
properties?: string[];
6+
fusionType?: FusionType;
7+
}
8+
9+
export enum FusionType {
10+
rankedFusion = 'rankedFusion',
11+
relativeScoreFusion = 'relativeScoreFusion',
612
}
713

814
export default class GraphQLHybrid {
915
private alpha?: number;
1016
private query: string;
1117
private vector?: number[];
1218
private properties?: string[];
19+
private fusionType?: FusionType;
1320

1421
constructor(args: HybridArgs) {
1522
this.alpha = args.alpha;
1623
this.query = args.query;
1724
this.vector = args.vector;
1825
this.properties = args.properties;
26+
this.fusionType = args.fusionType;
1927
}
2028

2129
toString() {
@@ -34,6 +42,10 @@ export default class GraphQLHybrid {
3442
args = [...args, `properties:["${props}"]`];
3543
}
3644

45+
if (this.fusionType !== undefined) {
46+
args = [...args, `fusionType:${this.fusionType}`];
47+
}
48+
3749
return `{${args.join(',')}}`;
3850
}
3951
}

src/graphql/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ export { default as Aggregator } from './aggregator';
2525
export { default as GraphQLGetter } from './getter';
2626
export { default as Explorer } from './explorer';
2727
export { default as Raw } from './raw';
28+
export { FusionType } from './getter';

src/graphql/journey.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import weaviate, {
99
Tenant,
1010
ReferenceCreator,
1111
} from '..';
12+
import { FusionType } from './hybrid';
1213

1314
describe('the graphql journey', () => {
1415
let client: WeaviateClient;
@@ -372,6 +373,41 @@ describe('the graphql journey', () => {
372373
});
373374
});
374375

376+
test('graphql get hybrid with query, alpha, properties and fushionType: rankedFusion', () => {
377+
return client.graphql
378+
.get()
379+
.withClassName('Article')
380+
.withHybrid({ query: 'Apple', properties: ['title'], alpha: 0, fusionType: FusionType.rankedFusion })
381+
.withFields('_additional { id }')
382+
.do()
383+
.then((res: any) => {
384+
expect(res.data.Get.Article.length).toBe(1);
385+
})
386+
.catch((e: any) => {
387+
throw new Error('it should not have errord' + e);
388+
});
389+
});
390+
391+
test('graphql get hybrid with query, alpha, properties and fushionType: relativeScoreFusion', () => {
392+
return client.graphql
393+
.get()
394+
.withClassName('Article')
395+
.withHybrid({
396+
query: 'Apple',
397+
properties: ['title'],
398+
alpha: 0,
399+
fusionType: FusionType.relativeScoreFusion,
400+
})
401+
.withFields('_additional { id }')
402+
.do()
403+
.then((res: any) => {
404+
expect(res.data.Get.Article.length).toBe(1);
405+
})
406+
.catch((e: any) => {
407+
throw new Error('it should not have errord' + e);
408+
});
409+
});
410+
375411
test('graphql get with nearText (with certainty)', () => {
376412
return client.graphql
377413
.get()

0 commit comments

Comments
 (0)