Skip to content

Commit f5598f5

Browse files
Improve Embedded DB UX (#31)
1 parent 5316c92 commit f5598f5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/embedded/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ export class EmbeddedOptions {
2424
persistenceDataPath: string;
2525
host: string;
2626
port: number;
27-
clusterHostname: string;
2827
version: string;
2928
env: NodeJS.ProcessEnv;
3029

3130
constructor(cfg?: EmbeddedOptionsConfig) {
32-
this.clusterHostname = 'embedded';
3331
this.host = (cfg && cfg.host) || '127.0.0.1';
3432
this.port = (cfg && cfg.port) || 6666;
3533
this.version = this.parseVersion(cfg);
@@ -44,15 +42,16 @@ export class EmbeddedOptions {
4442
}
4543

4644
const env: NodeJS.ProcessEnv = {
47-
...process.env,
4845
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true',
4946
QUERY_DEFAULTS_LIMIT: '20',
5047
PERSISTENCE_DATA_PATH: this.persistenceDataPath,
51-
CLUSTER_HOSTNAME: this.clusterHostname,
48+
CLUSTER_HOSTNAME: `Embedded_at_${this.port}`,
5249
DEFAULT_VECTORIZER_MODULE: 'none',
5350
ENABLE_MODULES:
5451
'text2vec-openai,text2vec-cohere,text2vec-huggingface,' +
5552
'ref2vec-centroid,generative-openai,qna-openai',
53+
// Any above defaults can be overridden with export env vars
54+
...process.env,
5655
};
5756

5857
if (cfg && cfg.env) {

src/embedded/journey.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('embedded', () => {
1212
expect(opt.persistenceDataPath).toEqual(join(homedir(), '.local/share/weaviate'));
1313
expect(opt.host).toEqual('127.0.0.1');
1414
expect(opt.port).toEqual(6666);
15-
expect(opt.clusterHostname).toEqual('embedded');
15+
expect(opt.env).toHaveProperty('CLUSTER_HOSTNAME', 'Embedded_at_6666');
1616
});
1717

1818
it('creates EmbeddedOptions with custom options', () => {
@@ -33,10 +33,17 @@ describe('embedded', () => {
3333
expect(opt.env).toHaveProperty('ENABLE_MODULES', 'text2vec-contextionary');
3434
expect(opt.env).toHaveProperty('CONTEXTIONARY_URL', 'contextionary:9999');
3535
expect(opt.env).toHaveProperty('QUERY_DEFAULTS_LIMIT', 100);
36+
expect(opt.env).toHaveProperty('CLUSTER_HOSTNAME', 'Embedded_at_7777');
3637
expect(opt.host).toEqual('somehost.com');
3738
expect(opt.port).toEqual(7777);
3839
});
3940

41+
it('overrides default env vars with inherited exported ones', () => {
42+
process.env.CLUSTER_HOSTNAME = 'custom-hostname';
43+
const opt = new EmbeddedOptions();
44+
expect(opt.env).toHaveProperty('CLUSTER_HOSTNAME', 'custom-hostname');
45+
});
46+
4047
it('failed to create EmbeddedOptions with invalid version', () => {
4148
return expect(() => {
4249
const opt = new EmbeddedOptions({

0 commit comments

Comments
 (0)