-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from weaviate-tutorials/new-client
Adding new Client
- Loading branch information
Showing
28 changed files
with
847 additions
and
2,573 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
version: '3.4' | ||
--- | ||
services: | ||
weaviate: | ||
image: semitechnologies/weaviate:1.22.2 | ||
restart: on-failure:0 | ||
command: | ||
- --host | ||
- 0.0.0.0 | ||
- --port | ||
- '8080' | ||
- --scheme | ||
- http | ||
image: cr.weaviate.io/semitechnologies/weaviate:1.25.2 | ||
ports: | ||
- "8080:8080" | ||
- 8080:8080 | ||
- 50051:50051 | ||
restart: on-failure:0 | ||
environment: | ||
QUERY_DEFAULTS_LIMIT: 25 | ||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' | ||
PERSISTENCE_DATA_PATH: '/var/lib/weaviate' | ||
DEFAULT_VECTORIZER_MODULE: 'multi2vec-bind' | ||
ENABLE_MODULES: 'multi2vec-bind' | ||
BIND_INFERENCE_API: 'http://multi2vec-bind:8080' | ||
CLUSTER_HOSTNAME: 'node1' | ||
BIND_INFERENCE_API: 'http://multi2vec-bind:8080' | ||
QUERY_DEFAULTS_LIMIT: 25 | ||
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true' | ||
PERSISTENCE_DATA_PATH: '/var/lib/weaviate' | ||
DEFAULT_VECTORIZER_MODULE: 'multi2vec-bind' | ||
ENABLE_MODULES: 'multi2vec-bind' | ||
CLUSTER_HOSTNAME: 'node1' | ||
multi2vec-bind: | ||
image: semitechnologies/multi2vec-bind:imagebind | ||
image: cr.weaviate.io/semitechnologies/multi2vec-bind:imagebind | ||
environment: | ||
ENABLE_CUDA: '0' | ||
ENABLE_CUDA: '0' | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import weaviate, { WeaviateClient } from 'weaviate-ts-client'; | ||
import weaviate, { type WeaviateClient } from 'weaviate-client'; | ||
import 'dotenv/config' | ||
|
||
let client: WeaviateClient; | ||
|
||
export const getWeaviateClient = () => { | ||
export const getWeaviateClient = async () => { | ||
if (!client) { | ||
client = weaviate.client({ | ||
scheme: 'http', | ||
host: 'localhost:8080', | ||
}); | ||
client = await weaviate.connectToWeaviateCloud(process.env.WEAVIATE_HOST_URL || '',{ | ||
authCredentials: new weaviate.ApiKey(process.env.WEAVIATE_API_KEY || ''), | ||
headers: { | ||
'X-Palm-Api-Key': process.env.GOOGLE_KEY || '' | ||
} | ||
}, | ||
) | ||
}; | ||
|
||
// client.misc.readyChecker().do().then(console.log) | ||
|
||
return client; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,61 @@ | ||
import { WeaviateClient } from 'weaviate-ts-client'; | ||
import { getWeaviateClient } from './client'; | ||
import weaviate, { type WeaviateClient } from 'weaviate-client'; | ||
import { getWeaviateClient } from './client.ts'; | ||
|
||
const client: WeaviateClient = getWeaviateClient(); | ||
const client: WeaviateClient = await getWeaviateClient(); | ||
|
||
const collectionExists = async (name: string) => { | ||
return client.schema.exists(name); | ||
return client.collections.exists(name); | ||
} | ||
|
||
export const createBindCollection = async (name: string) => { | ||
if(await collectionExists(name)) { | ||
export const createCollection = async (name: string) => { | ||
if (await collectionExists(name)) { | ||
console.log(`The collection [${name}] already exists. No need to create it.`); | ||
return; | ||
} | ||
|
||
console.log(`Creating collection [${name}].`); | ||
|
||
const bindSchema = { | ||
class: name, | ||
moduleConfig: { | ||
'multi2vec-bind': { | ||
// textFields: ['name'], | ||
imageFields: ['image'], | ||
audioFields: ['audio'], | ||
videoFields: ['video'], | ||
} | ||
const newCollection = await client.collections.create({ | ||
name: name, | ||
vectorizers: weaviate.configure.vectorizer.multi2VecPalm({ | ||
projectId: 'semi-random-dev', | ||
location: 'us-central1', | ||
imageFields: ['image'], | ||
videoFields: ['video'], | ||
}, | ||
), | ||
properties: [ | ||
{ | ||
name: 'name', | ||
dataType: ['text'], | ||
moduleConfig: { | ||
'multi2vec-bind': { skip: true }, | ||
}, | ||
dataType: 'text', | ||
}, | ||
{ | ||
name: 'media', | ||
dataType: ['text'], | ||
moduleConfig: { | ||
'multi2vec-bind': { skip: true }, | ||
}, | ||
dataType: 'text', | ||
}, | ||
{ | ||
name: 'image', | ||
dataType: ['blob'], | ||
dataType: 'blob', | ||
}, | ||
{ | ||
name: 'audio', | ||
dataType: ['blob'], | ||
dataType: 'blob', | ||
}, | ||
{ | ||
name: 'video', | ||
dataType: ['blob'], | ||
dataType: 'blob', | ||
} | ||
], | ||
vectorIndexType: 'hnsw', | ||
vectorizer: 'multi2vec-bind' | ||
} | ||
|
||
const res = await client | ||
.schema.classCreator() | ||
.withClass(bindSchema) | ||
.do(); | ||
}) | ||
|
||
console.log(JSON.stringify(res, null, 2)); | ||
|
||
|
||
console.log(JSON.stringify(newCollection, null, 2)); | ||
} | ||
|
||
export const deleteCollection = async (name: string) => { | ||
console.log(`Deleting collection ${name}...`); | ||
await client.schema | ||
.classDeleter() | ||
.withClassName(name) | ||
.do(); | ||
await client.collections.delete(name); | ||
|
||
console.log(`Deleted collection ${name}.`); | ||
} | ||
} |
Oops, something went wrong.