Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/docker-compose-azure-cc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:1.18.0
image: semitechnologies/weaviate:1.18.2
ports:
- 8081:8081
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-okta-cc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:1.18.0
image: semitechnologies/weaviate:1.18.2
ports:
- 8082:8082
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose-okta-users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:1.18.0
image: semitechnologies/weaviate:1.18.2
ports:
- 8083:8083
restart: on-failure:0
Expand Down
23 changes: 23 additions & 0 deletions ci/docker-compose-openai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
version: '3.4'
services:
weaviate_openai:
command:
- --host
- 0.0.0.0
- --port
- '8086'
- --scheme
- http
image: semitechnologies/weaviate:1.18.2
ports:
- 8086:8086
restart: on-failure:0
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
DEFAULT_VECTORIZER_MODULE: 'text2vec-openai'
ENABLE_MODULES: 'text2vec-openai,generative-openai'
CLUSTER_HOSTNAME: 'node1'
...
27 changes: 0 additions & 27 deletions ci/docker-compose-wcs-noscope.yml

This file was deleted.

2 changes: 1 addition & 1 deletion ci/docker-compose-wcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- --scheme
- http
- --write-timeout=600s
image: semitechnologies/weaviate:1.18.0
image: semitechnologies/weaviate:1.18.2
ports:
- 8085:8085
restart: on-failure:0
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version: '3.4'
services:
weaviate:
image: semitechnologies/weaviate:1.18.0
image: semitechnologies/weaviate:1.18.2
restart: on-failure:0
ports:
- "8080:8080"
Expand Down
4 changes: 2 additions & 2 deletions src/cluster/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const {
SOUP_CLASS_NAME,
} = require('../utils/testData');

const EXPECTED_WEAVIATE_VERSION = '1.18.0';
const EXPECTED_WEAVIATE_GIT_HASH = '8606543';
const EXPECTED_WEAVIATE_VERSION = '1.18.2';
const EXPECTED_WEAVIATE_GIT_HASH = '723b88a';

describe('cluster nodes endpoint', () => {
const client = weaviate.client({
Expand Down
25 changes: 0 additions & 25 deletions src/connection/journey.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,6 @@ describe('connection', () => {
});
});

it('makes a scopeless WCS logged-in request with username/password', () => {
if (process.env.WCS_DUMMY_CI_PW == undefined || process.env.WCS_DUMMY_CI_PW == '') {
console.warn('Skipping because `WCS_DUMMY_CI_PW` is not set');
return;
}
const client = weaviate.client({
scheme: 'http',
host: 'localhost:8086',
authClientSecret: new AuthUserPasswordCredentials({
username: 'ms_2d0e007e7136de11d5f29fce7a53dae219a51458@existiert.net',
password: process.env.WCS_DUMMY_CI_PW,
}),
});

return client.misc
.metaGetter()
.do()
.then((res: any) => {
expect(res.version).toBeDefined();
})
.catch((e: any) => {
throw new Error('it should not have errord: ' + e);
});
});

it('makes a logged-in request with API key', () => {
const client = weaviate.client({
scheme: 'http',
Expand Down
49 changes: 49 additions & 0 deletions src/graphql/generate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export interface GenerateArgs {
groupedTask?: string;
singlePrompt?: string;
}

export interface GenerateParts {
singleResult?: string;
groupedResult?: string;
results: string[];
}

export class GraphQLGenerate {
private groupedTask?: string;
private singlePrompt?: string;

constructor(args: GenerateArgs) {
this.groupedTask = args.groupedTask;
this.singlePrompt = args.singlePrompt;
}

toString(): string {
this.validate();

let str = 'generate(';
const results = ['error'];
if (this.singlePrompt) {
str += `singleResult:{prompt:"${this.singlePrompt.replace(/[\n\r]+/g, '')}"}`;
results.push('singleResult');
}
if (this.groupedTask) {
str += `groupedResult:{task:"${this.groupedTask.replace(/[\n\r]+/g, '')}"}`;
results.push('groupedResult');
}
str += `){${results.join(' ')}}`;
return str;
}

private validate() {
if (!this.groupedTask && !this.singlePrompt) {
throw new Error('must provide at least one of `singlePrompt` or `groupTask`');
}
if (this.groupedTask !== undefined && this.groupedTask == '') {
throw new Error('groupedTask must not be empty');
}
if (this.singlePrompt !== undefined && this.singlePrompt == '') {
throw new Error('singlePrompt must not be empty');
}
}
}
97 changes: 97 additions & 0 deletions src/graphql/getter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,100 @@ describe('hybrid valid searchers', () => {
expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});
});

describe('generative search', () => {
const mockClient: any = {
query: jest.fn(),
};

test('singlePrompt', () => {
const expectedQuery =
'{Get{Mammal{name taxonomy _additional{generate(singleResult:' +
'{prompt:"When did dogs become mans best friend?"}){error singleResult}}}}}';
new Getter(mockClient)
.withClassName('Mammal')
.withGenerate({
singlePrompt: 'When did dogs become mans best friend?',
})
.withFields('name taxonomy')
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test('singlePrompt with newlines', () => {
const expectedQuery =
'{Get{Mammal{name taxonomy _additional{generate(singleResult:' +
'{prompt:"Which mammals can survive in Antarctica?"}){error singleResult}}}}}';

new Getter(mockClient)
.withClassName('Mammal')
.withGenerate({
singlePrompt: `Which mammals
can survive
in Antarctica?`,
})
.withFields('name taxonomy')
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test('groupedTask', () => {
const expectedQuery =
'{Get{Mammal{name taxonomy _additional{generate(groupedResult:' +
'{task:"Explain why platypi can lay eggs"}){error groupedResult}}}}}';

new Getter(mockClient)
.withClassName('Mammal')
.withGenerate({
groupedTask: 'Explain why platypi can lay eggs',
})
.withFields('name taxonomy')
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test('groupedTask with newlines', () => {
const expectedQuery =
'{Get{Mammal{name taxonomy _additional{generate(groupedResult:' +
'{task:"Tell me about how polar bears keep warm"}){error groupedResult}}}}}';

new Getter(mockClient)
.withClassName('Mammal')
.withFields('name taxonomy')
.withGenerate({
groupedTask: `Tell
me
about
how
polar
bears
keep
warm`,
})
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});

test('single prompt and grouped task', () => {
const expectedQuery =
'{Get{Mammal{name taxonomy _additional{generate(singleResult:' +
'{prompt:"How tall is a baby giraffe?"}groupedResult:{task:' +
'"Explain how the heights of mammals relate to their prefferred food sources"})' +
'{error singleResult groupedResult}}}}}';

new Getter(mockClient)
.withClassName('Mammal')
.withFields('name taxonomy')
.withGenerate({
singlePrompt: 'How tall is a baby giraffe?',
groupedTask: 'Explain how the heights of mammals relate to their prefferred food sources',
})
.do();

expect(mockClient.query).toHaveBeenCalledWith(expectedQuery);
});
});
15 changes: 15 additions & 0 deletions src/graphql/getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Sort, { SortArgs } from './sort';
import Connection from '../connection';
import { CommandBase } from '../validation/commandBase';
import { WhereFilter } from '../openapi/types';
import { GenerateArgs, GraphQLGenerate } from './generate';

export default class GraphQLGetter extends CommandBase {
private after?: string;
Expand All @@ -29,6 +30,7 @@ export default class GraphQLGetter extends CommandBase {
private offset?: number;
private sortString?: string;
private whereString?: string;
private generateString?: string;

constructor(client: Connection) {
super(client);
Expand Down Expand Up @@ -169,6 +171,11 @@ export default class GraphQLGetter extends CommandBase {
return this;
};

withGenerate = (args: GenerateArgs) => {
this.generateString = new GraphQLGenerate(args).toString();
return this;
};

validateIsSet = (prop: string | undefined | null, name: string, setter: string) => {
if (prop == undefined || prop == null || prop.length == 0) {
this.addError(`${name} must be set - set with ${setter}`);
Expand Down Expand Up @@ -241,6 +248,14 @@ export default class GraphQLGetter extends CommandBase {
args = [...args, `after:"${this.after}"`];
}

if (this.generateString) {
if (this.fields?.includes('_additional')) {
this.fields.replace('_additional{', `_additional{${this.generateString}`);
} else {
this.fields = this.fields?.concat(` _additional{${this.generateString}}`);
}
}

if (args.length > 0) {
params = `(${args.join(',')})`;
}
Expand Down
Loading