diff --git a/.vscode/markdown.code-snippets b/.vscode/markdown.code-snippets index 95c36f9a2..d9b5255ec 100644 --- a/.vscode/markdown.code-snippets +++ b/.vscode/markdown.code-snippets @@ -110,7 +110,7 @@ "```", "", "", - "", + "", "", "```js", "", @@ -261,7 +261,7 @@ "import TabItem from '@theme/TabItem';", "", "", - "", + "", "", "```python", "# Python v4 example goes here", @@ -269,13 +269,6 @@ "# without the empty line the code won't render", "```", "", - "", - "", - "```python", - "# Python v3 example goes here", - "```", - "", - "", "", ], "description": "Adds the tabs section for code examples" diff --git a/_includes/clients/ts-client-intro.mdx b/_includes/clients/ts-client-intro.mdx index 5bedc7680..4f2ef7ab7 100644 --- a/_includes/clients/ts-client-intro.mdx +++ b/_includes/clients/ts-client-intro.mdx @@ -1,9 +1,9 @@ The TypeScript client supports code that is written in TypeScript or JavaScript. -The **v3 client** is the current TypeScript client. If you have code written for the v2 client, you should [migrate it to v3](/weaviate/client-libraries/typescript/v2_v3_migration) as the v2 client is no longer maintained. +The **v3 client** is the current TypeScript client. If you have code written for the [v2 client](/weaviate/client-libraries/typescript#javascripttypescript-client-v2-deprecation), you should migrate it to v3 as the v2 client is no longer maintained. :::note -The v3 client supports server side development (Node.js hosted). If your application is browser based, you might consider using the [TypeScript client v2](/weaviate/client-libraries/typescript/typescript-v2). Keep in mind that the v2 client is outdated and no longer officially maintained. +The v3 client supports server side development (Node.js hosted). If your application is browser based, you might consider using the [TypeScript client v2](/weaviate/client-libraries/typescript#javascripttypescript-client-v2-deprecation). Keep in mind that the v2 client is outdated and no longer officially maintained. ::: diff --git a/_includes/code/EMPTY.mdx b/_includes/code/EMPTY.mdx index da7b611bb..22af5ccf0 100644 --- a/_includes/code/EMPTY.mdx +++ b/_includes/code/EMPTY.mdx @@ -15,13 +15,6 @@ import TabItem from '@theme/TabItem'; ``` - - - -```js - -``` - diff --git a/_includes/code/configuration/replication-consistency.mdx b/_includes/code/configuration/replication-consistency.mdx index 8209c4767..3052baaba 100644 --- a/_includes/code/configuration/replication-consistency.mdx +++ b/_includes/code/configuration/replication-consistency.mdx @@ -1,14 +1,12 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.collections-v3.py'; import TSCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.ts'; -import TSCodeLegacy from '!!raw-loader!/_includes/code/howto/manage-data.collections-v2.ts'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - - + - - - ```bash diff --git a/_includes/code/connections/oidc-connect.mdx b/_includes/code/connections/oidc-connect.mdx index e0d64f3a0..b46b5a9b2 100644 --- a/_includes/code/connections/oidc-connect.mdx +++ b/_includes/code/connections/oidc-connect.mdx @@ -3,14 +3,12 @@ import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyV4Code from '!!raw-loader!/_includes/code/connections/connect-python-v4.py'; -import PyV3Code from '!!raw-loader!/_includes/code/connections/connect-python-v3.py'; import TsV3Code from '!!raw-loader!/_includes/code/connections/connect-ts-v3.ts'; -import TsV2Code from '!!raw-loader!/_includes/code/connections/connect-ts-v2.ts'; import JavaCode from '!!raw-loader!/_includes/code/connections/connect.java'; import GoCode from '!!raw-loader!/_includes/code/connections/connect.go'; - + - - - - + - - - - + - + - + - + - + - + - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.c11y - .extensionCreator() - .withConcept('weaviate') - .withDefinition('Open source cloud native real time vector database') - .withWeight(1) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/contextionary.get.mdx b/_includes/code/contextionary.get.mdx index 4506e4003..8d8b35a08 100644 --- a/_includes/code/contextionary.get.mdx +++ b/_includes/code/contextionary.get.mdx @@ -13,24 +13,6 @@ concept_info = client.contextionary.get_concept_vector("fashionMagazine") print(concept_info) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.c11y - .conceptsGetter() - .withConcept('fashionMagazine') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/core.client.openai.apikey.mdx b/_includes/code/core.client.openai.apikey.mdx index 4a9dde640..38c7cf627 100644 --- a/_includes/code/core.client.openai.apikey.mdx +++ b/_includes/code/core.client.openai.apikey.mdx @@ -18,25 +18,6 @@ client = weaviate.Client( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', - // highlight-start - // Replace with your API key - headers: { - 'X-OpenAI-Api-Key': 'YOUR-OPENAI-API-KEY', - 'X-Azure-Api-Key': 'YOUR-AZURE-API-KEY', - }, - // highlight-end -}); -``` - diff --git a/_includes/code/embedded.instantiate.custom.mdx b/_includes/code/embedded.instantiate.custom.mdx index c67f9cc1d..e5c52cb5e 100644 --- a/_includes/code/embedded.instantiate.custom.mdx +++ b/_includes/code/embedded.instantiate.custom.mdx @@ -2,12 +2,9 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/install/embedded.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/install/embedded-v3.py'; -import TsCodeV2 from '!!raw-loader!/_includes/code/install/embedded-v2.ts'; -import TsCodeV2CustomModules from '!!raw-loader!/_includes/code/install/embedded-v2-custommodules.ts'; - + - - - - - - diff --git a/_includes/code/embedded.instantiate.mdx b/_includes/code/embedded.instantiate.mdx index 44c532495..f32467645 100644 --- a/_includes/code/embedded.instantiate.mdx +++ b/_includes/code/embedded.instantiate.mdx @@ -2,11 +2,9 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/install/embedded.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/install/embedded-v3.py'; -import TsCodeV2 from '!!raw-loader!/_includes/code/install/embedded-v2.ts'; - + - - - - - - diff --git a/_includes/code/embedded.instantiate.module.mdx b/_includes/code/embedded.instantiate.module.mdx index ee7e30718..c984df649 100644 --- a/_includes/code/embedded.instantiate.module.mdx +++ b/_includes/code/embedded.instantiate.module.mdx @@ -2,12 +2,9 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/install/embedded.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/install/embedded-v3.py'; -import TsCodeV2 from '!!raw-loader!/_includes/code/install/embedded-v2.ts'; -import TsCodeV2CustomModules from '!!raw-loader!/_includes/code/install/embedded-v2-custommodules.ts'; - + - - - - - - diff --git a/_includes/code/embedded.instantiate.simple.mdx b/_includes/code/embedded.instantiate.simple.mdx index bf89bac05..10d4f89f6 100644 --- a/_includes/code/embedded.instantiate.simple.mdx +++ b/_includes/code/embedded.instantiate.simple.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - + - - - ```python - import weaviate - from weaviate.embedded import EmbeddedOptions - - client = weaviate.Client( - embedded_options=EmbeddedOptions() - ) - ``` - - - - + ```js // Coming soon @@ -35,19 +22,4 @@ import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - - - ```js - import weaviate, { EmbeddedOptions } from 'weaviate-ts-embedded'; - - const client = weaviate.client(new EmbeddedOptions()); - - await client.embedded.start(); - - // Work with Weaviate - - client.embedded.stop(); - ``` - - diff --git a/_includes/code/generative.anyscale.groupedresult.mdx b/_includes/code/generative.anyscale.groupedresult.mdx index edfe9796d..a1f7d0999 100644 --- a/_includes/code/generative.anyscale.groupedresult.mdx +++ b/_includes/code/generative.anyscale.groupedresult.mdx @@ -65,39 +65,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Anyscale-Api-Key': process.env['ANYSCALE_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Please answer the question: What is ref2vec? based on the following search results. IMPORTANT! Please make sure your answer is supported by the information in the search results and provide references to the provided content when possible.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withNearText({ - concepts: ['What is ref2vec?'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.anyscale.singleresult.mdx b/_includes/code/generative.anyscale.singleresult.mdx index fa9416767..7c74852da 100644 --- a/_includes/code/generative.anyscale.singleresult.mdx +++ b/_includes/code/generative.anyscale.singleresult.mdx @@ -58,36 +58,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Anyscale-Api-Key': process.env['ANYSCALE_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Please summarize the following podcast clip into one sentence. Speaker: {speaker} said {content}.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(1) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.aws.groupedresult.mdx b/_includes/code/generative.aws.groupedresult.mdx index e385fabc8..efb472b88 100644 --- a/_includes/code/generative.aws.groupedresult.mdx +++ b/_includes/code/generative.aws.groupedresult.mdx @@ -4,83 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.groupedtask.examples import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-AWS-Access-Key": "YOUR_ACCESS_KEY", - "X-AWS-Secret-Key": "YOUR_SECRET_KEY", - } -) - -# highlight-start -# instruction for the generative module -generateTask = "Explain why these magazines or newspapers are about finance" -# highlight-end - -result = ( - client.query - .get("Publication", ["name"]) - # highlight-start - .with_generate(grouped_task=generateTask) - # highlight-end - .with_near_text({ - "concepts": ["magazine or newspaper about finance"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { - 'X-AWS-Access-Key': 'YOUR_ACCESS_KEY', - 'X-AWS-Secret-Key': 'YOUR_SECRET_KEY' - }, -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Explain why these magazines or newspapers are about finance'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withNearText({ - concepts: ['magazine or newspaper about finance'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.aws.singleresult.mdx b/_includes/code/generative.aws.singleresult.mdx index 9f9abe823..1f0e123b1 100644 --- a/_includes/code/generative.aws.singleresult.mdx +++ b/_includes/code/generative.aws.singleresult.mdx @@ -4,83 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.singleprompt.example import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-AWS-Access-Key": "YOUR_ACCESS_KEY", - "X-AWS-Secret-Key": "YOUR_SECRET_KEY", - } -) - -# highlight-start -# instruction for the generative module -generatePrompt = "Describe the following as a Facebook Ad: {summary}" -# highlight-end - -result = ( - client.query - .get("Article", ["title", "summary"]) - # highlight-start - .with_generate(single_prompt=generatePrompt) - # highlight-end - .with_near_text({ - "concepts": ["Italian food"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { - 'X-AWS-Access-Key': 'YOUR_ACCESS_KEY', - 'X-AWS-Secret-Key': 'YOUR_SECRET_KEY' - }, -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Describe the following as a Facebook Ad: {summary}'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withNearText({ - concepts: ['Italian food'], - }) - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.cohere.groupedresult.mdx b/_includes/code/generative.cohere.groupedresult.mdx index c6ed107a2..5c2316d8c 100644 --- a/_includes/code/generative.cohere.groupedresult.mdx +++ b/_includes/code/generative.cohere.groupedresult.mdx @@ -4,79 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.groupedtask.examples import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-Cohere-Api-Key": "YOUR-COHERE-API-KEY" - } -) - -# highlight-start -# instruction for the generative module -generateTask = "Explain why these magazines or newspapers are about finance" -# highlight-end - -result = ( - client.query - .get("Publication", ["name"]) - # highlight-start - .with_generate(grouped_task=generateTask) - # highlight-end - .with_near_text({ - "concepts": ["magazine or newspaper about finance"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Cohere-Api-Key': process.env['COHERE_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Explain why these magazines or newspapers are about finance'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withNearText({ - concepts: ['magazine or newspaper about finance'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.cohere.singleresult.mdx b/_includes/code/generative.cohere.singleresult.mdx index 74ad2228a..83a58eb6b 100644 --- a/_includes/code/generative.cohere.singleresult.mdx +++ b/_includes/code/generative.cohere.singleresult.mdx @@ -4,79 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.singleprompt.example import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-Cohere-Api-Key": "YOUR-COHERE-API-KEY" - } -) - -# highlight-start -# instruction for the generative module -generatePrompt = "Describe the following as a Facebook Ad: {summary}" -# highlight-end - -result = ( - client.query - .get("Article", ["title", "summary"]) - # highlight-start - .with_generate(single_prompt=generatePrompt) - # highlight-end - .with_near_text({ - "concepts": ["Italian food"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Cohere-Api-Key': process.env['COHERE_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Describe the following as a Facebook Ad: {summary}'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withNearText({ - concepts: ['Italian food'], - }) - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.local.groupedresult.mdx b/_includes/code/generative.local.groupedresult.mdx index 8d81cbadf..bc0950670 100644 --- a/_includes/code/generative.local.groupedresult.mdx +++ b/_includes/code/generative.local.groupedresult.mdx @@ -62,38 +62,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Please answer the question: What is ref2vec? based on the following search results. IMPORTANT! Please make sure your answer is supported by the information in the search results and provide references to the provided content when possible.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withNearText({ - concepts: ['What is ref2vec?'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.local.singleresult.mdx b/_includes/code/generative.local.singleresult.mdx index 5a58dd4db..af6caeedb 100644 --- a/_includes/code/generative.local.singleresult.mdx +++ b/_includes/code/generative.local.singleresult.mdx @@ -55,35 +55,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Please summarize the following podcast clip into one sentence. Speaker: {speaker} said {content}.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(1) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.mistral.groupedresult.mdx b/_includes/code/generative.mistral.groupedresult.mdx index 2526efade..8c264ca01 100644 --- a/_includes/code/generative.mistral.groupedresult.mdx +++ b/_includes/code/generative.mistral.groupedresult.mdx @@ -65,39 +65,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Mistral-Api-Key': process.env['MISTRAL_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Please answer the question: What is ref2vec? based on the following search results. IMPORTANT! Please make sure your answer is supported by the information in the search results and provide references to the provided content when possible.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withNearText({ - concepts: ['What is ref2vec?'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.mistral.singleresult.mdx b/_includes/code/generative.mistral.singleresult.mdx index 87daa0552..5b7e65f2c 100644 --- a/_includes/code/generative.mistral.singleresult.mdx +++ b/_includes/code/generative.mistral.singleresult.mdx @@ -58,36 +58,6 @@ result = ( print(result) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-Mistral-Api-Key': process.env['MISTRAL_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Please summarize the following podcast clip into one sentence. Speaker: {speaker} said {content}.'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('PodClip') - .withFields('speaker content') - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(1) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.openai.groupedresult.mdx b/_includes/code/generative.openai.groupedresult.mdx index 9fd99e55e..24409cf05 100644 --- a/_includes/code/generative.openai.groupedresult.mdx +++ b/_includes/code/generative.openai.groupedresult.mdx @@ -4,79 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.groupedtask.examples import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" - } -) - -# highlight-start -# instruction for the generative module -generateTask = "Explain why these magazines or newspapers are about finance" -# highlight-end - -result = ( - client.query - .get("Publication", ["name"]) - # highlight-start - .with_generate(grouped_task=generateTask) - # highlight-end - .with_near_text({ - "concepts": ["magazine or newspaper about finance"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client= weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Explain why these magazines or newspapers are about finance'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withNearText({ - concepts: ['magazine or newspaper about finance'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.openai.singleresult.mdx b/_includes/code/generative.openai.singleresult.mdx index 80d3af04e..8845cd979 100644 --- a/_includes/code/generative.openai.singleresult.mdx +++ b/_includes/code/generative.openai.singleresult.mdx @@ -4,79 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.singleprompt.example import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" - } -) - -# highlight-start -# instruction for the generative module -generatePrompt = "Describe the following as a Facebook Ad: {summary}" -# highlight-end - -result = ( - client.query - .get("Article", ["title", "summary"]) - # highlight-start - .with_generate(single_prompt=generatePrompt) - # highlight-end - .with_near_text({ - "concepts": ["Italian food"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```js -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Describe the following as a Facebook Ad: {summary}'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withNearText({ - concepts: ['Italian food'], - }) - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.palm.groupedresult.mdx b/_includes/code/generative.palm.groupedresult.mdx index 19eba2fea..de168e08e 100644 --- a/_includes/code/generative.palm.groupedresult.mdx +++ b/_includes/code/generative.palm.groupedresult.mdx @@ -4,80 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.groupedtask.examples import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL/", # Replace WEAVIATE_INSTANCE_URL with your instance URL - additional_headers={ - "X-Goog-Vertex-Api-Key": "YOUR-VERTEX-API-KEY", - "X-Goog-Studio-Api-Key": "YOUR-AI-STUDIO-API-KEY", - } -) - -# highlight-start -# instruction for the generative module -generateTask = "Explain why these magazines or newspapers are about finance" -# highlight-end - -result = ( - client.query - .get("Publication", ["name"]) - # highlight-start - .with_generate(grouped_task=generateTask) - # highlight-end - .with_near_text({ - "concepts": ["magazine or newspaper about finance"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate API key - headers: { 'X-PaLM-Api-Key': process.env['PALM_API_KEY'] }, // Replace with your GOOGLE API key -}); - -// highlight-start -// instruction for the generative module -const generateTask = 'Explain why these magazines or newspapers are about finance'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('name') - .withNearText({ - concepts: ['magazine or newspaper about finance'], - }) - .withGenerate({ - groupedTask: generateTask, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/generative.palm.singleresult.mdx b/_includes/code/generative.palm.singleresult.mdx index 5d9e987af..80fef7586 100644 --- a/_includes/code/generative.palm.singleresult.mdx +++ b/_includes/code/generative.palm.singleresult.mdx @@ -4,80 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/generative.singleprompt.example import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL", # Replace WEAVIATE_INSTANCE_URL with the URL - additional_headers={ - "X-Goog-Vertex-Api-Key": "YOUR-VERTEX-API-KEY", - "X-Goog-Studio-Api-Key": "YOUR-AI-STUDIO-API-KEY", - } -) - -# highlight-start -# instruction for the generative module -generatePrompt = "Describe the following as a Facebook Ad: {summary}" -# highlight-end - -result = ( - client.query - .get("Article", ["title", "summary"]) - # highlight-start - .with_generate(single_prompt=generatePrompt) - # highlight-end - .with_near_text({ - "concepts": ["Italian food"] - }) - .with_limit(5) -).do() - -print(result) -``` - - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate API key - headers: { 'X-PaLM-Api-Key': process.env['PALM_API_KEY'] }, // Replace with your GOOGLE API key -}); - -// highlight-start -// instruction for the generative module -const generatePrompt = 'Describe the following as a Facebook Ad: {summary}'; -// highlight-end - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withNearText({ - concepts: ['Italian food'], - }) - .withGenerate({ - singlePrompt: generatePrompt, - }) - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.aggregate.groupby.mdx b/_includes/code/graphql.aggregate.groupby.mdx index 1d5cc8a53..2dfe83ae8 100644 --- a/_includes/code/graphql.aggregate.groupby.mdx +++ b/_includes/code/graphql.aggregate.groupby.mdx @@ -5,53 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -response = ( - client.query - .aggregate("Article") - .with_group_by_filter(["inPublication"]) - .with_meta_count() - .with_fields("meta { count } wordCount { mean } groupedBy { path value }") - .do() -) - -print(response) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .aggregate() - .withClassName('Article') - .withGroupBy(['inPublication']) - .withFields('meta { count } wordCount { mean } groupedBy { value path }') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.aggregate.nearObject.mdx b/_includes/code/graphql.aggregate.nearObject.mdx index 1b6013169..311c6fe35 100644 --- a/_includes/code/graphql.aggregate.nearObject.mdx +++ b/_includes/code/graphql.aggregate.nearObject.mdx @@ -5,57 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -result = ( - client.query - .aggregate("Article") - .with_meta_count() - .with_fields("wordCount { count maximum mean median minimum mode sum type } inPublication { pointingTo type }") - # prior to v1.14, use certainty instead of distance - .with_near_object({"id": "00037775-1432-35e5-bc59-443baaef7d80", "distance": 0.6}) - .with_object_limit(200) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .aggregate() - .withClassName('Article') - .withFields('meta { count } wordCount { count maximum mean median minimum mode sum type } inPublication { pointingTo type }') - // prior to v1.14, use certainty instead of distance - .withNearObject({ id: '00037775-1432-35e5-bc59-443baaef7d80', distance: 0.6 }) - .withObjectLimit(100) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.aggregate.nearText.mdx b/_includes/code/graphql.aggregate.nearText.mdx index 3e17a5d84..d90053387 100644 --- a/_includes/code/graphql.aggregate.nearText.mdx +++ b/_includes/code/graphql.aggregate.nearText.mdx @@ -5,55 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -result = ( - client.query - .aggregate("Article") - .with_meta_count() - .with_fields("wordCount {count maximum mean median minimum mode sum type} inPublication {pointingTo type}") - .with_near_text({"concepts": ["apple iphone"], "distance": 0.7}) # prior to v1.14 use "certainty" instead of "distance" - .with_object_limit(200) # at least one of "objectLimit", - .do() # and/or "distance" must be set -) # when using near media filters - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .aggregate() - .withClassName('Article') - .withFields('meta { count } wordCount {count maximum mean median minimum mode sum type}') - .withNearText({ concepts: ['apple iphone'], distance: 0.7 }) // prior to v1.14 use "certainty" instead of "distance" - .withObjectLimit(100) // at least one of "objectLimit", and/or "distance" must be set when using near media filters - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.aggregate.nearVector.mdx b/_includes/code/graphql.aggregate.nearVector.mdx index 19817fead..5662ed2d0 100644 --- a/_includes/code/graphql.aggregate.nearVector.mdx +++ b/_includes/code/graphql.aggregate.nearVector.mdx @@ -5,55 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -result = ( - client.query - .aggregate("Article") - .with_meta_count() - .with_fields("wordCount {count maximum mean median minimum mode sum type}") - .with_near_vector({"vector": [0.1, 0.2, -0.3], "certainty": 0.7}) - .with_object_limit(100) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .aggregate() - .withClassName('Article') - .withFields('meta { count } wordCount {count maximum mean median minimum mode sum type}') - .withNearVector({ vector: [0.1, 0.2, -0.3], certainty: 0.7 }) - .withObjectLimit(100) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.aggregate.simple.mdx b/_includes/code/graphql.aggregate.simple.mdx index 208b61e64..d1bde9214 100644 --- a/_includes/code/graphql.aggregate.simple.mdx +++ b/_includes/code/graphql.aggregate.simple.mdx @@ -5,51 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -response = ( - client.query - .aggregate("Article") - .with_meta_count() - .with_fields("wordCount {count maximum mean median minimum mode sum type}") - .do() -) - -print(response) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .aggregate() - .withClassName('Article') - .withFields('meta { count } wordCount {count maximum mean median minimum mode sum type}') - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.explore.simple.mdx b/_includes/code/graphql.explore.simple.mdx index 27a1734ad..ed3f7341c 100644 --- a/_includes/code/graphql.explore.simple.mdx +++ b/_includes/code/graphql.explore.simple.mdx @@ -64,30 +64,6 @@ query_result = client.query.raw(explore_articles_query) print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .explore() - .withNearText({ - concepts: ['New Yorkers'], - moveTo: { concepts: ['publisher', 'articles'], force: 0.5 }, - moveAwayFrom: { concepts: ['fashion', 'shop'], force: 0.2 }, - distance: 0.95, // prior to v1.14, use certainty - }) - .withFields('beacon certainty distance className') // certainty is only supported if distance==cosine - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.explore.vector.mdx b/_includes/code/graphql.explore.vector.mdx index f48f12e64..e12858534 100644 --- a/_includes/code/graphql.explore.vector.mdx +++ b/_includes/code/graphql.explore.vector.mdx @@ -2,52 +2,6 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -explore_articles_query = """ - { - Explore ( - nearVector: { - vector: [-0.36840257,0.13973749,-0.28994447,-0.18607682,0.20019795,0.15541431,-0.42353877,0.30262852,0.2724561,0.07069917,0.4877447,0.038771532,0.64523,-0.15907241,-0.3413626,-0.026682584,-0.63310874,-0.33411884,0.082939014,0.30305764,0.045918174,-0.21439327,-0.5005205,0.6210859,-0.2729049,-0.51221114,0.09680918,0.094923325,-0.15688285,-0.07325482,0.6588305,0.0523736,-0.14173415,-0.27428055,0.25526586,0.057506185,-0.3103442,0.028601522,0.124522656,0.66984487,0.12160647,-0.5090515,-0.540393,-0.39546522,-0.2201204,0.34625968,-0.21068871,0.21132985,0.048714135,0.09043683,0.3176081,-0.056684002,-0.12117501,-0.6591976,-0.26731065,0.42615625,0.33333477,-0.3240578,-0.18771006,0.2328068,-0.17239179,-0.33583146,-0.6556605,-0.10608161,-0.5135395,-0.25123677,-0.23004892,0.7036331,0.04456794,0.41253626,0.27872285,-0.28226635,0.11927197,-0.4677766,0.4343466,-0.17538455,0.10621233,0.95815116,0.23587844,-0.006406698,-0.10512518,-1.1125883,-0.37921682,0.040789194,0.676718,0.3369762,0.040712647,0.580487,0.20063736,-0.021220192,-0.09071747,-0.0023735985,0.30007777,-0.039925132,0.4035474,-0.2518212,-0.17846306,0.12371392,-0.0703354,-0.3752431,-0.652917,0.5952828,1.3426708,-0.08167235,-0.38515738,0.058423538,-0.08100355,-0.192886,0.3745164,-0.23291737,0.33326542,-0.6019264,-0.42822492,-0.6524583,-0.15210791,-0.5073593,0.022548754,-0.058033653,-0.47369233,-0.30890635,0.6338296,0.0017854869,0.1954949,0.99348027,-0.26558784,-0.058124136,1.149388,0.02915948,0.013422121,0.25484946,-0.030017598,-0.23879935,0.053123385,-0.36463016,-0.0024245526,0.1202083,-0.45966506,-0.34140104,-0.08484162,-0.03537422,-0.2817959,0.25044164,-0.5060605,0.1252808,-0.032539487,0.110069446,-0.20679846,-0.46421885,-0.4141739,0.26994973,-0.070687145,0.16862138,-0.20162229,0.22199251,-0.2771402,0.23653336,0.16585203,-0.08286354,-0.15343396,0.23893964,-0.7453282,-0.16549355,-0.1947069,0.46136436,0.22064126,0.28654936,-0.038697664,0.037633028,-0.80988157,0.5094175,-0.0920082,0.25405347,-0.64169943,0.43366328,-0.2999211,-0.4090591,0.11957859,0.00803617,-0.0433745,0.12818244,0.28464508,-0.31760025,0.16558012,-0.33553946,-0.3943465,0.59569097,-0.6524206,0.3683173,-0.60456693,0.2046492,0.46010277,0.24695799,0.2946015,0.11376746,-0.027988048,0.03749422,-0.16577742,0.23407385,-0.0231737,-0.023245076,0.08752677,0.2299883,0.35467404,0.046193745,-0.39828986,0.21079691,0.38396686,-0.0018698421,0.16047359,-0.057517264,-0.203534,0.23438136,-0.84250915,0.22371331,0.0058325706,0.30733636,0.19518353,-0.108008966,0.6509316,0.070131645,-0.24023099,0.28779706,0.2326336,0.07004021,-0.45955566,0.20426086,-0.37472793,-0.049604423,0.4537271,0.6133582,-1.0527759,-0.5472505,0.15193434,0.5296606,-0.11560251,0.07279209,0.40557706,0.2505283,0.24490519,0.017602902,-0.004647707,0.16608049,0.12576887,0.118216865,0.4403996,0.39552462,-0.22196701,-0.061155193,0.03693534,-0.4022908,0.3842317,-0.0831345,0.01930883,0.3446575,-0.2167439,-0.23994556,-0.09370326,-0.3671856,0.044011243,0.017895095,-0.019855855,-0.16416992,0.17858285,0.31287143,0.38368022,-0.006513525,0.45780763,-0.23027879,0.108570844,-0.4449492,-0.035763215,0.03818417,0.040017277,-0.17022872,-0.2622464,0.65610534,0.16720143,0.2515769,-0.23535803,0.62484455,0.16771325,-0.62404263,0.19176348,-0.72786695,0.18485649,-0.30914405,-0.3230534,-0.24064465,0.28841522,0.39792386,0.15618932,0.03928854,0.18277727,-0.101632096,0.1868196,-0.33366352,0.086561844,0.48557812,-0.6198209,-0.07978742] - } - ) { - beacon - certainty // only supported if distance==cosine - distance // always supported - className - } - } -""" - -query_result = client.query.raw(explore_articles_query) -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .explore() - .withNearVector({ vector: [-0.36840257,0.13973749,-0.28994447,-0.18607682,0.20019795,0.15541431,-0.42353877,0.30262852,0.2724561,0.07069917,0.4877447,0.038771532,0.64523,-0.15907241,-0.3413626,-0.026682584,-0.63310874,-0.33411884,0.082939014,0.30305764,0.045918174,-0.21439327,-0.5005205,0.6210859,-0.2729049,-0.51221114,0.09680918,0.094923325,-0.15688285,-0.07325482,0.6588305,0.0523736,-0.14173415,-0.27428055,0.25526586,0.057506185,-0.3103442,0.028601522,0.124522656,0.66984487,0.12160647,-0.5090515,-0.540393,-0.39546522,-0.2201204,0.34625968,-0.21068871,0.21132985,0.048714135,0.09043683,0.3176081,-0.056684002,-0.12117501,-0.6591976,-0.26731065,0.42615625,0.33333477,-0.3240578,-0.18771006,0.2328068,-0.17239179,-0.33583146,-0.6556605,-0.10608161,-0.5135395,-0.25123677,-0.23004892,0.7036331,0.04456794,0.41253626,0.27872285,-0.28226635,0.11927197,-0.4677766,0.4343466,-0.17538455,0.10621233,0.95815116,0.23587844,-0.006406698,-0.10512518,-1.1125883,-0.37921682,0.040789194,0.676718,0.3369762,0.040712647,0.580487,0.20063736,-0.021220192,-0.09071747,-0.0023735985,0.30007777,-0.039925132,0.4035474,-0.2518212,-0.17846306,0.12371392,-0.0703354,-0.3752431,-0.652917,0.5952828,1.3426708,-0.08167235,-0.38515738,0.058423538,-0.08100355,-0.192886,0.3745164,-0.23291737,0.33326542,-0.6019264,-0.42822492,-0.6524583,-0.15210791,-0.5073593,0.022548754,-0.058033653,-0.47369233,-0.30890635,0.6338296,0.0017854869,0.1954949,0.99348027,-0.26558784,-0.058124136,1.149388,0.02915948,0.013422121,0.25484946,-0.030017598,-0.23879935,0.053123385,-0.36463016,-0.0024245526,0.1202083,-0.45966506,-0.34140104,-0.08484162,-0.03537422,-0.2817959,0.25044164,-0.5060605,0.1252808,-0.032539487,0.110069446,-0.20679846,-0.46421885,-0.4141739,0.26994973,-0.070687145,0.16862138,-0.20162229,0.22199251,-0.2771402,0.23653336,0.16585203,-0.08286354,-0.15343396,0.23893964,-0.7453282,-0.16549355,-0.1947069,0.46136436,0.22064126,0.28654936,-0.038697664,0.037633028,-0.80988157,0.5094175,-0.0920082,0.25405347,-0.64169943,0.43366328,-0.2999211,-0.4090591,0.11957859,0.00803617,-0.0433745,0.12818244,0.28464508,-0.31760025,0.16558012,-0.33553946,-0.3943465,0.59569097,-0.6524206,0.3683173,-0.60456693,0.2046492,0.46010277,0.24695799,0.2946015,0.11376746,-0.027988048,0.03749422,-0.16577742,0.23407385,-0.0231737,-0.023245076,0.08752677,0.2299883,0.35467404,0.046193745,-0.39828986,0.21079691,0.38396686,-0.0018698421,0.16047359,-0.057517264,-0.203534,0.23438136,-0.84250915,0.22371331,0.0058325706,0.30733636,0.19518353,-0.108008966,0.6509316,0.070131645,-0.24023099,0.28779706,0.2326336,0.07004021,-0.45955566,0.20426086,-0.37472793,-0.049604423,0.4537271,0.6133582,-1.0527759,-0.5472505,0.15193434,0.5296606,-0.11560251,0.07279209,0.40557706,0.2505283,0.24490519,0.017602902,-0.004647707,0.16608049,0.12576887,0.118216865,0.4403996,0.39552462,-0.22196701,-0.061155193,0.03693534,-0.4022908,0.3842317,-0.0831345,0.01930883,0.3446575,-0.2167439,-0.23994556,-0.09370326,-0.3671856,0.044011243,0.017895095,-0.019855855,-0.16416992,0.17858285,0.31287143,0.38368022,-0.006513525,0.45780763,-0.23027879,0.108570844,-0.4449492,-0.035763215,0.03818417,0.040017277,-0.17022872,-0.2622464,0.65610534,0.16720143,0.2515769,-0.23535803,0.62484455,0.16771325,-0.62404263,0.19176348,-0.72786695,0.18485649,-0.30914405,-0.3230534,-0.24064465,0.28841522,0.39792386,0.15618932,0.03928854,0.18277727,-0.101632096,0.1868196,-0.33366352,0.086561844,0.48557812,-0.6198209,-0.07978742]}) - .withFields('beacon certainty className') - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.filters.after.mdx b/_includes/code/graphql.filters.after.mdx index 3e56e5655..33ddd596d 100644 --- a/_includes/code/graphql.filters.after.mdx +++ b/_includes/code/graphql.filters.after.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.additional.py'; - + - - - -```py -response = ( - client.query.get("Article", ["title"]) - .with_additional(["id"]) - .with_limit(5) - .with_after("002d5cb3-298b-380d-addb-2e026b76c8ed") - .do() -) - -print(response) -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional { id }') - .withAfter('002d5cb3-298b-380d-addb-2e026b76c8ed') - .withLimit(5) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - - ```graphql diff --git a/_includes/code/graphql.filters.bm25.filter.example.mdx b/_includes/code/graphql.filters.bm25.filter.example.mdx index 56b862eb1..06e7758f9 100644 --- a/_includes/code/graphql.filters.bm25.filter.example.mdx +++ b/_includes/code/graphql.filters.bm25.filter.example.mdx @@ -5,56 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -# highlight-start -where_filter = { - "path": ["wordCount"], - "operator": "LessThan", - "valueInt": "1000" -} -# highlight-end - -query_result = ( - client.query - .get("Article", ["title", "summary"]) - .with_where(where_filter) - .with_bm25(query="how to fish") - .do() -) -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withBm25({ - query: 'how to fish', - }) - // highlight-start - .withWhere({ - operator: 'LessThan', - path: ['wordCount'], - valueInt: 1000, - }) - // highlight-end - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.filters.bm25.mdx b/_includes/code/graphql.filters.bm25.mdx index 8b64c6655..d2f32b19e 100644 --- a/_includes/code/graphql.filters.bm25.mdx +++ b/_includes/code/graphql.filters.bm25.mdx @@ -5,59 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -bm25 = { - "query": "fox", - "properties": ["title"], # by default, all properties are searched -} - -result = ( - client.query - .get("Article", ["title", "_additional {score} "]) - .with_bm25(**bm25) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional {score}') - .withBm25({ - query: 'fox', - properties: ['title'], - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.group.mdx b/_includes/code/graphql.filters.group.mdx index f06f2de89..1b1aeb2bd 100644 --- a/_includes/code/graphql.filters.group.mdx +++ b/_includes/code/graphql.filters.group.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.additional.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -get_articles_group = """ - { - Get { - Publication( - group:{ - type: merge, - force:0.05 - } - ) { - name - } - } - } -""" - -query_result = client.query.raw(get_articles_group) -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name') - .withGroup({ - type: 'merge', - force: 0.05, - }) - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.filters.hybrid.filter.example.mdx b/_includes/code/graphql.filters.hybrid.filter.example.mdx index f69b5424c..f13fec401 100644 --- a/_includes/code/graphql.filters.hybrid.filter.example.mdx +++ b/_includes/code/graphql.filters.hybrid.filter.example.mdx @@ -5,56 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -# highlight-start -where_filter = { - "path": ["wordCount"], - "operator": "LessThan", - "valueInt": "1000" -} -# highlight-end -query_result = ( - client.query - .get("Article", ["title", "summary"]) - .with_where(where_filter) - .with_hybrid(query= "How to catch an Alaskan Pollock",alpha=0.5) - .do() -) -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary') - .withHybrid({ - query: 'How to catch Alaskan Pollock', - alpha: 0.5, - }) - // highlight-start - .withWhere({ - operator: 'LessThan', - path: ['wordCount'], - valueInt: 1000, - }) - // highlight-end - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.filters.hybrid.mdx b/_includes/code/graphql.filters.hybrid.mdx index 0b5778376..898121092 100644 --- a/_includes/code/graphql.filters.hybrid.mdx +++ b/_includes/code/graphql.filters.hybrid.mdx @@ -5,44 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python - -result = ( - client.query - .get("Article", ["title", "summary"]) - .with_additional(["score", "explainScore"]) - .with_hybrid("Fisherman that catches salmon", alpha=0.5) - .do() - ) - -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary _additional { score explainScore }') - .withHybrid({ - query: 'Fisherman that catches salmon', - alpha: 0.5, // optional, defaults to 0.75 - }) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.filters.hybrid.properties.mdx b/_includes/code/graphql.filters.hybrid.properties.mdx index 670c3456f..ace638b55 100644 --- a/_includes/code/graphql.filters.hybrid.properties.mdx +++ b/_includes/code/graphql.filters.hybrid.properties.mdx @@ -7,55 +7,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -result = ( - client.query - .get("JeopardyQuestion", ["question", "answer"]) - .with_additional(["score"]) - .with_hybrid( - "Venus", - alpha=0.25, # closer to pure keyword search -# highlight-start - properties=["question"] # changing to "answer" will yield a different result set -# highlight-end - ) - .with_limit(3)do() -) - -print(json.dumps(result, indent=4)) -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('JeopardyQuestion') - .withFields('question answer _additional{ score }') - .withHybrid({ - query: 'Venus', - alpha: 0.25, // closer to pure keyword search -// highlight-start - properties: ['question'], // changing to "answer" will yield a different set of results -// highlight-end - }) - withLimit(3) - .do(); - -console.log(response['data']['Get']['JeopardyQuestion']); -``` - diff --git a/_includes/code/graphql.filters.hybrid.vector.mdx b/_includes/code/graphql.filters.hybrid.vector.mdx index 088d6c23a..8663f2520 100644 --- a/_includes/code/graphql.filters.hybrid.vector.mdx +++ b/_includes/code/graphql.filters.hybrid.vector.mdx @@ -5,43 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -result = ( - client.query - .get("Article", ["title", "summary"]) - .with_additional(["score"]) - .with_hybrid("Fisherman that catches salmon", alpha=0.5, vector=[1, 2, 3]) - .do() - ) -``` - - - - -```js -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary _additional { score }') - .withHybrid({ - query: 'Fisherman that catches salmon', - vector: [1, 2, 3], // optional. Not needed if Weaviate handles the vectorization. - alpha: 0.5, // optional, defaults to 0.75 - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.limit.mdx b/_includes/code/graphql.filters.limit.mdx index 102b25071..33b70d7c6 100644 --- a/_includes/code/graphql.filters.limit.mdx +++ b/_includes/code/graphql.filters.limit.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.additional.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -result = client.query.get("Article", ["title"]).with_limit(5).do() -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withLimit(5) - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.filters.nearObject.mdx b/_includes/code/graphql.filters.nearObject.mdx index caeafa6cf..a9ed59e27 100644 --- a/_includes/code/graphql.filters.nearObject.mdx +++ b/_includes/code/graphql.filters.nearObject.mdx @@ -5,62 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -nearObject = { - "id": "32d5a368-ace8-3bb7-ade7-9f7ff03eddb6", # or {"beacon": "weaviate://localhost/32d5a368-ace8-3bb7-ade7-9f7ff03eddb6"} - "distance": 0.6, -} - -result = ( - client.query - .get("Publication", "name") - .with_additional("distance") # "certainty" only supported if distance==cosine - .with_near_object(nearObject) - .with_limit(5) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional {certainty distance}}') // certainty only supported if distance==cosine - .withNearObject({ - id: '32d5a368-ace8-3bb7-ade7-9f7ff03eddb6', - distance: 0.6, - }) - .withLimit(5) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.2obj.mdx b/_includes/code/graphql.filters.nearText.2obj.mdx index 790073a5a..e019610e0 100644 --- a/_includes/code/graphql.filters.nearText.2obj.mdx +++ b/_includes/code/graphql.filters.nearText.2obj.mdx @@ -5,68 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -nearText = { - "concepts": ["travelling in Asia"], - "certainty": 0.7, - "moveTo": { - "objects": [{"id": "c4209549-7981-3699-9648-61a78c2124b9"}], - "force": 0.85 - } -} - -result = ( - client.query - .get("Article", ["title", "summary", "_additional { certainty }"]) - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title summary _additional { certainty }') - .withNearText({ - concepts: ['travelling in Asia'], - certainty: 0.7, - moveTo: { - // this ID is of the article: "Tohoku: A Japan destination for all seasons." - objects: [{ id: 'c4209549-7981-3699-9648-61a78c2124b9' }], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.aws.mdx b/_includes/code/graphql.filters.nearText.aws.mdx index 7d6a12ace..a572329ff 100644 --- a/_includes/code/graphql.filters.nearText.aws.mdx +++ b/_includes/code/graphql.filters.nearText.aws.mdx @@ -4,7 +4,7 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-AWS-Access-Key": "YOUR_ACCESS_KEY", - "X-AWS-Secret-Key": "YOUR_SECRET_KEY", - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL - apiKey: new ApiKey('YOUR-API-KEY'), - headers: { - 'X-AWS-Access-Key': 'YOUR_ACCESS_KEY', - 'X-AWS-Secret-Key': 'YOUR_SECRET_KEY' - }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional{certainty distance}') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.filters.nearText.cohere.mdx b/_includes/code/graphql.filters.nearText.cohere.mdx index d79586ce2..69b3fb23e 100644 --- a/_includes/code/graphql.filters.nearText.cohere.mdx +++ b/_includes/code/graphql.filters.nearText.cohere.mdx @@ -4,82 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-Cohere-Api-Key": "YOUR-COHERE-API-KEY" - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-Cohere-Api-Key': 'YOUR-COHERE-API-KEY' }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional{certainty distance}') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.huggingface.mdx b/_includes/code/graphql.filters.nearText.huggingface.mdx index e869a58dc..68bb04018 100644 --- a/_includes/code/graphql.filters.nearText.huggingface.mdx +++ b/_includes/code/graphql.filters.nearText.huggingface.mdx @@ -4,82 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-HuggingFace-Api-Key": "YOUR-HUGGINGFACE-API-KEY" - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-HuggingFace-Api-Key': 'YOUR-HUGGINGFACE-API-KEY' }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional{ certainty distance }') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.jinaai.mdx b/_includes/code/graphql.filters.nearText.jinaai.mdx index 782d7c6c7..edcdc1bfc 100644 --- a/_includes/code/graphql.filters.nearText.jinaai.mdx +++ b/_includes/code/graphql.filters.nearText.jinaai.mdx @@ -4,83 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-Jinaai-Api-Key": "YOUR-JINAAI-API-KEY" - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note certainty is only supported - # if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-Jinaai-Api-Key': process.env['YOUR_JINAAI_API_KEY'] }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional { certainty distance }') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.mdx b/_includes/code/graphql.filters.nearText.mdx index 061f132e1..a5bc24eeb 100644 --- a/_includes/code/graphql.filters.nearText.mdx +++ b/_includes/code/graphql.filters.nearText.mdx @@ -4,74 +4,11 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.generi import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional{certainty distance}') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.openai.mdx b/_includes/code/graphql.filters.nearText.openai.mdx index ab20fdc94..cca8b0b99 100644 --- a/_includes/code/graphql.filters.nearText.openai.mdx +++ b/_includes/code/graphql.filters.nearText.openai.mdx @@ -4,82 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional { certainty distance }') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.palm.mdx b/_includes/code/graphql.filters.nearText.palm.mdx index 4312a5c1c..9f100ef87 100644 --- a/_includes/code/graphql.filters.nearText.palm.mdx +++ b/_includes/code/graphql.filters.nearText.palm.mdx @@ -4,83 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-Goog-Vertex-Api-Key": "YOUR-VERTEX-API-KEY", - "X-Goog-Studio-Api-Key": "YOUR-AI-STUDIO-API-KEY", - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-PaLM-Api-Key': 'YOUR-PALM-API-KEY' }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional { certainty distance }') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearText.voyageai.mdx b/_includes/code/graphql.filters.nearText.voyageai.mdx index 31d7fb21b..be8f20fb4 100644 --- a/_includes/code/graphql.filters.nearText.voyageai.mdx +++ b/_includes/code/graphql.filters.nearText.voyageai.mdx @@ -4,82 +4,13 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.py'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - -```python -import weaviate - -client = weaviate.Client( - url="http://localhost:8080", - additional_headers={ - "X-VoyageAI-Api-Key": "YOUR-VOYAGEAI-API-KEY" - } -) - -nearText = { - "concepts": ["fashion"], - "distance": 0.6, # prior to v1.14 use "certainty" instead of "distance" - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -result = ( - client.query - .get("Publication", "name") - .with_additional(["certainty OR distance"]) # note that certainty is only supported if distance==cosine - .with_near_text(nearText) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-VoyageAI-Api-Key': 'YOUR-VOYAGEAI-API-KEY' }, -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional{certainty distance}') // note that certainty is only supported if distance==cosine - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty instead of distance - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.nearVector.mdx b/_includes/code/graphql.filters.nearVector.mdx index 997d9a6d6..85c3eb769 100644 --- a/_includes/code/graphql.filters.nearVector.mdx +++ b/_includes/code/graphql.filters.nearVector.mdx @@ -5,58 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -nearVector = { - "vector": [0.1, -0.15, 0.3.. ] # Replace with a compatible vector -} - -result = ( - client.query - .get("Publication", "name") - .with_additional("distance") - .with_near_vector(nearVector) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional {certainty}') - .withNearVector({ - vector: [0.1, -0.15, 0.3, ... ] // Replace with a compatible vector - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.offset.mdx b/_includes/code/graphql.filters.offset.mdx index 880dea217..620953471 100644 --- a/_includes/code/graphql.filters.offset.mdx +++ b/_includes/code/graphql.filters.offset.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.additional.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -result = ( - client.query - .get("Article", "title") - .with_limit(5) - .with_offset(2) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withLimit(5) - .withOffset(2) - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.filters.where.beacon.count.mdx b/_includes/code/graphql.filters.where.beacon.count.mdx index 975c119ab..cc34360bd 100644 --- a/_includes/code/graphql.filters.where.beacon.count.mdx +++ b/_includes/code/graphql.filters.where.beacon.count.mdx @@ -5,61 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "valueInt": 2, - "operator": "GreaterThanEqual", - "path": ["writesFor"] -} - -response = ( - client.query - .get("Author", ["name", "writesFor {... on Publication { name }}"]) - .with_where(where_filter) - .do() -) - -print(response) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Author') - .withFields('name writesFor {... on Publication {name}}') - .withWhere({ - valueInt: 2, - operator: 'GreaterThanEqual', - path: ['writesFor'], - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.beacon.mdx b/_includes/code/graphql.filters.where.beacon.mdx index 7e61cb21e..b3974bb23 100644 --- a/_includes/code/graphql.filters.where.beacon.mdx +++ b/_includes/code/graphql.filters.where.beacon.mdx @@ -5,61 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["inPublication", "Publication", "name"], - "operator": "Equal", - "valueText": "New Yorker" -} - -query_result = ( - client.query - .get("Article", ["title", "inPublication{... on Publication{name}}"]) - .with_where(where_filter) - .do() -) - -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title inPublication{... on Publication{name}}') - .withWhere({ - path: ['inPublication', 'Publication', 'name'], - operator: 'Equal', - valueText: 'New Yorker', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.geocoordinates.mdx b/_includes/code/graphql.filters.where.geocoordinates.mdx index 350100512..5550427ea 100644 --- a/_includes/code/graphql.filters.where.geocoordinates.mdx +++ b/_includes/code/graphql.filters.where.geocoordinates.mdx @@ -5,83 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -get_articles_where = """ - { - Get { - Publication(where: { - operator: WithinGeoRange, - valueGeoRange: { - geoCoordinates: { - latitude: 51.51, # latitude - longitude: -0.09 # longitude - }, - distance: { - max: 2000 # distance in meters - } - }, - path: ["headquartersGeoLocation"] # property needs to be of geoLocation type. - }) { - name - headquartersGeoLocation { - latitude - longitude - } - } - } - } -""" - -query_result = client.query.raw(get_articles_where) -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name headquartersGeoLocation {latitude longitude}') - .withWhere({ - operator: 'WithinGeoRange', - path: ['headquartersGeoLocation'], - valueGeoRange: { - geoCoordinates: { - latitude: 51.51, - longitude: -0.09, - }, - distance: { - max: 2000, - }, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.id.mdx b/_includes/code/graphql.filters.where.id.mdx index eaf6dbc89..8d3c80277 100644 --- a/_includes/code/graphql.filters.where.id.mdx +++ b/_includes/code/graphql.filters.where.id.mdx @@ -5,62 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate -import json - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["id"], - "operator": "Equal", - "valueText": "00037775-1432-35e5-bc59-443baaef7d80" -} - -response = ( - client.query - .get("Article", "title") - .with_where(where_filter) - .do() -) - -print(json.dumps(response, indent=2)) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withWhere({ - operator: 'Equal', - path: ['id'], - valueText: '00037775-1432-35e5-bc59-443baaef7d80', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.like.mdx b/_includes/code/graphql.filters.where.like.mdx index ea5e77181..29e259ec3 100644 --- a/_includes/code/graphql.filters.where.like.mdx +++ b/_includes/code/graphql.filters.where.like.mdx @@ -5,61 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["name"], - "operator": "Like", - "valueText": "New *" -} - -query_result = ( - client.query - .get("Publication", "name") - .with_where(where_filter) - .do() -) - -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name') - .withWhere({ - path: ['name'], - operator: 'Like', - valueText: 'New *', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.operands.mdx b/_includes/code/graphql.filters.where.operands.mdx index 62e876550..eacc38364 100644 --- a/_includes/code/graphql.filters.where.operands.mdx +++ b/_includes/code/graphql.filters.where.operands.mdx @@ -5,75 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "operator": "And", - "operands": [{ - "path": ["wordCount"], - "operator": "GreaterThan", - "valueInt": 1000 - }, { - "path": ["title"], - "operator": "Like", - "valueText": "*economy*", - }] -} - -response = ( - client.query - .get("Article", "title") - .with_where(where_filter) - .do() -) - -print(response) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withWhere({ - operator: 'And', - operands: [{ - path: ['wordCount'], - operator: 'GreaterThan', - valueInt: 1000, - }, { - path: ['title'], - operator: 'Like', - valueText:'*economy*', - }], - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.simple.mdx b/_includes/code/graphql.filters.where.simple.mdx index a5e22b4fe..b0696ecee 100644 --- a/_includes/code/graphql.filters.where.simple.mdx +++ b/_includes/code/graphql.filters.where.simple.mdx @@ -5,61 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["wordCount"], - "operator": "GreaterThan", - "valueInt": 1000 -} - -query_result = ( - client.query - .get("Article", "title") - .with_where(where_filter) - .do() -) - -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withWhere({ - operator: 'GreaterThan', - path: ['wordCount'], - valueInt: 1000, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.filters.where.timestamps.mdx b/_includes/code/graphql.filters.where.timestamps.mdx index a89eaa389..7db3c048d 100644 --- a/_includes/code/graphql.filters.where.timestamps.mdx +++ b/_includes/code/graphql.filters.where.timestamps.mdx @@ -5,64 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.filters.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["_creationTimeUnix"], - "operator": "GreaterThan", - # "valueDate": "2022-03-18T20:26:34.586-05:00", # Can use either `valueDate` with a `RFC3339` datetime or `valueText` as Unix epoch milliseconds - "valueText": "1647653359063" -} - -response = ( - client.query - .get("Article", "title") - .with_where(where_filter) - .do() -) - -print(response) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title') - .withWhere({ - operator: 'GreaterThan', - path: ['_creationTimeUnix'], - // valueDate: '2022-03-18T20:26:34.586-05:00', - // Can use either `valueDate` with a `RFC3339` datetime or `valueText` as Unix epoch milliseconds - valueText: '1647653359063', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.get.beacon.mdx b/_includes/code/graphql.get.beacon.mdx index 467f50ea4..1af030eac 100644 --- a/_includes/code/graphql.get.beacon.mdx +++ b/_includes/code/graphql.get.beacon.mdx @@ -6,7 +6,7 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.get.simple.py'; import PyCodeV3 from '!!raw-loader!/_includes/code/graphql.get.beacon.v3.py'; - + - - - - - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title url wordCount inPublication {... on Publication {name}}') - .do(); -console.log(response); -``` - @@ -167,7 +138,7 @@ echo '{ text={PyCodeV3} startMarker="# ===== GRAPHQL EXAMPLE =====" endMarker="# ===== END GRAPHQL EXAMPLE =====" - language="pyv3" + language="graphql" /> diff --git a/_includes/code/graphql.get.consistency.mdx b/_includes/code/graphql.get.consistency.mdx index 3834b61f6..086c22864 100644 --- a/_includes/code/graphql.get.consistency.mdx +++ b/_includes/code/graphql.get.consistency.mdx @@ -3,56 +3,15 @@ import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/graphql.get.simple.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/graphql.get.simple.v3.py'; - + - - - -```python -import weaviate -from weaviate.data.replication import ConsistencyLevel - -client = weaviate.Client("http://localhost:8080") - -resp = ( - client.query.get("Article", ["name"]) - .with_additional("isConsistent") - .with_consistency_level(ConsistencyLevel.QUORUM) - .do() -) - -print(f"resp: {resp}") -``` - - - - -```ts -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('_additional { id isConsistent }') - .withConsistencyLevel('QUORUM') - .do(); - -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/graphql.get.groupby.mdx b/_includes/code/graphql.get.groupby.mdx index e1961da86..7a98689d7 100644 --- a/_includes/code/graphql.get.groupby.mdx +++ b/_includes/code/graphql.get.groupby.mdx @@ -6,7 +6,7 @@ import PyCode from '!!raw-loader!/_includes/code/graphql.get.simple.py'; import PyCodeV3 from '!!raw-loader!/_includes/code/graphql.get.simple.v3.py'; - + - + - - - - - - - - + - - - - - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate URL -}); - -const response = await client.graphql - .get() - .withClassName('JeopardyQuestion') - .withFields('question answer points') - .do(); -console.log(response); -``` - @@ -145,7 +116,7 @@ echo '{ text={PyCodeV3} startMarker="# ===== GRAPHQL EXAMPLE =====" endMarker="# ===== END GRAPHQL EXAMPLE =====" - language="pyv3" + language="graphql" /> diff --git a/_includes/code/graphql.get.sorting.mdx b/_includes/code/graphql.get.sorting.mdx index 3f4eaf6ae..41cf33c45 100644 --- a/_includes/code/graphql.get.sorting.mdx +++ b/_includes/code/graphql.get.sorting.mdx @@ -18,26 +18,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withSort([{ path: ['title'], order: 'asc' }]) - .withFields('title url wordCount') - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.certainty.mdx b/_includes/code/graphql.underscoreproperties.certainty.mdx index 2cbfff10a..c087d6745 100644 --- a/_includes/code/graphql.underscoreproperties.certainty.mdx +++ b/_includes/code/graphql.underscoreproperties.certainty.mdx @@ -45,26 +45,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withNearText({ concepts: ['fashion'] }) - .withFields('title _additional { id certainty }') - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.classification.mdx b/_includes/code/graphql.underscoreproperties.classification.mdx index dd0ab8ebb..e2e74aa71 100644 --- a/_includes/code/graphql.underscoreproperties.classification.mdx +++ b/_includes/code/graphql.underscoreproperties.classification.mdx @@ -28,25 +28,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional { classification { basedOn classifiedFields completed id scope } }') - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.distance.mdx b/_includes/code/graphql.underscoreproperties.distance.mdx index 2c6b0c062..e6f86a7b5 100644 --- a/_includes/code/graphql.underscoreproperties.distance.mdx +++ b/_includes/code/graphql.underscoreproperties.distance.mdx @@ -5,7 +5,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.metadata.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -near_text_filter = { - "concepts": ["fashion"] -} - -query_result = ( - client.query - .get("Article", "title") - .with_additional(["id", "distance"]) - .with_near_text(near_text_filter) - .do() -) - -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withNearText({ concepts: ['fashion'] }) - .withFields('title _additional { id distance }') - .do(); -console.log(response); -``` - - ```go diff --git a/_includes/code/graphql.underscoreproperties.featureprojection.mdx b/_includes/code/graphql.underscoreproperties.featureprojection.mdx index 0200f8552..3c3c15f73 100644 --- a/_includes/code/graphql.underscoreproperties.featureprojection.mdx +++ b/_includes/code/graphql.underscoreproperties.featureprojection.mdx @@ -38,33 +38,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional {featureProjection(dimensions: 2) { vector }}') - .withNearText({ - concepts:['music'], - moveTo: { - concepts: ['beatles'], - force: 0.5, - }, - }) - .withLimit(12) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.interpretation.mdx b/_includes/code/graphql.underscoreproperties.interpretation.mdx index 9be7e29de..cc808930b 100644 --- a/_includes/code/graphql.underscoreproperties.interpretation.mdx +++ b/_includes/code/graphql.underscoreproperties.interpretation.mdx @@ -53,25 +53,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('summary _additional { interpretation {source {concept occurrence weight}}}') - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.nearestneighbors.mdx b/_includes/code/graphql.underscoreproperties.nearestneighbors.mdx index 2f11f72d6..979ca5a99 100644 --- a/_includes/code/graphql.underscoreproperties.nearestneighbors.mdx +++ b/_includes/code/graphql.underscoreproperties.nearestneighbors.mdx @@ -61,32 +61,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional { nearestNeighbors { neighbors { concept distance } } }') - .withNearText({ - concepts:['music'], - moveTo: { - concepts: ['beatles'], - force: 0.5, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/graphql.underscoreproperties.semanticpath.mdx b/_includes/code/graphql.underscoreproperties.semanticpath.mdx index d729849fe..d525cf974 100644 --- a/_includes/code/graphql.underscoreproperties.semanticpath.mdx +++ b/_includes/code/graphql.underscoreproperties.semanticpath.mdx @@ -5,80 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -near_text_operator = { - "concepts": ["fashion"], - "distance": 0.6, #prior to v1.14 use certainty: 0.7 - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -additional_props = { - "semanticPath": "path {distanceToNext distanceToPrevious distanceToQuery distanceToResult}" -} - -query_result = ( - client.query - .get("Publication", "name") - .with_additional(additional_props) - .with_near_text(near_text_operator) - .do() -) - -print(query_result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name _additional { semanticPath { path { concept distanceToNext distanceToPrevious distanceToQuery distanceToResult } } }') - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty: 0.7 - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.add.data.things.add.reference.mdx b/_includes/code/howto.add.data.things.add.reference.mdx index e72f43966..7b4a6cfdb 100644 --- a/_includes/code/howto.add.data.things.add.reference.mdx +++ b/_includes/code/howto.add.data.things.add.reference.mdx @@ -29,41 +29,6 @@ client.data_object.reference.add( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -let response = await client.data - .creator() - .withClassName('Author') - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303') - .withProperties({ - name: 'Jodi Kantor', - }) - .do(); -console.log(response); - -response = await client.data - .referenceCreator() - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303') - .withReferenceProperty('writesFor') - .withReference( - client.data - .referencePayloadBuilder() - .withId('f81bfe5e-16ba-4615-a516-46c2ae2e5a80') - .payload(), - ) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.add.data.things.mdx b/_includes/code/howto.add.data.things.mdx index 5a804d261..5f5df0ebc 100644 --- a/_includes/code/howto.add.data.things.mdx +++ b/_includes/code/howto.add.data.things.mdx @@ -20,28 +20,6 @@ client.data_object.create( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.data - .creator() - .withClassName('Publication') - .withId('f81bfe5e-16ba-4615-a516-46c2ae2e5a80') - .withProperties({ - name: 'New York Times', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.add.data.things.reference.mdx b/_includes/code/howto.add.data.things.reference.mdx index 50e6673d3..f97ae8666 100644 --- a/_includes/code/howto.add.data.things.reference.mdx +++ b/_includes/code/howto.add.data.things.reference.mdx @@ -26,31 +26,6 @@ data_uuid = ( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.data - .creator() - .withClassName('Author') - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303') - .withProperties({ - name: 'Jodi Kantor', - writesFor: [{ - beacon: 'weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80', - }], - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.customvectors.adddata.mdx b/_includes/code/howto.customvectors.adddata.mdx index ca63e6d44..925afc0cf 100644 --- a/_includes/code/howto.customvectors.adddata.mdx +++ b/_includes/code/howto.customvectors.adddata.mdx @@ -21,29 +21,6 @@ client.data_object.create( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.data - .creator() - .withClassName('Post') - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a0934') - .withProperties({ - content: 'This is a news update of May 28 2021. Today .......', - }) - .withVector([0.3, 0.2, 0.1, 0.4, 0.6, 0.9]) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.customvectors.nearvector.mdx b/_includes/code/howto.customvectors.nearvector.mdx index 5a0a5c0e4..90cd9f613 100644 --- a/_includes/code/howto.customvectors.nearvector.mdx +++ b/_includes/code/howto.customvectors.nearvector.mdx @@ -35,26 +35,6 @@ nearVector = {vector: [-0.36840257,0.13973749,-0.28994447,-0.18607682,0.20019795 client.query.get("Post", ["content", "_additional {certainty}"]).with_near_vector(nearVector).do() # note that certainty is only supported if distance==cosine ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Post') - .withFields('content _additional { certainty distance }') // certainty is only supported if distance==cosine - .withNearVector({ vector: [-0.36840257,0.13973749,-0.28994447,-0.18607682,0.20019795,0.15541431,-0.42353877,0.30262852,0.2724561,0.07069917,0.4877447,0.038771532,0.64523,-0.15907241,-0.3413626,-0.026682584,-0.63310874,-0.33411884,0.082939014,0.30305764,0.045918174,-0.21439327,-0.5005205,0.6210859,-0.2729049,-0.51221114,0.09680918,0.094923325,-0.15688285,-0.07325482,0.6588305,0.0523736,-0.14173415,-0.27428055,0.25526586,0.057506185,-0.3103442,0.028601522,0.124522656,0.66984487,0.12160647,-0.5090515,-0.540393,-0.39546522,-0.2201204,0.34625968,-0.21068871,0.21132985,0.048714135,0.09043683,0.3176081,-0.056684002,-0.12117501,-0.6591976,-0.26731065,0.42615625,0.33333477,-0.3240578,-0.18771006,0.2328068,-0.17239179,-0.33583146,-0.6556605,-0.10608161,-0.5135395,-0.25123677,-0.23004892,0.7036331,0.04456794,0.41253626,0.27872285,-0.28226635,0.11927197,-0.4677766,0.4343466,-0.17538455,0.10621233,0.95815116,0.23587844,-0.006406698,-0.10512518,-1.1125883,-0.37921682,0.040789194,0.676718,0.3369762,0.040712647,0.580487,0.20063736,-0.021220192,-0.09071747,-0.0023735985,0.30007777,-0.039925132,0.4035474,-0.2518212,-0.17846306,0.12371392,-0.0703354,-0.3752431,-0.652917,0.5952828,1.3426708,-0.08167235,-0.38515738,0.058423538,-0.08100355,-0.192886,0.3745164,-0.23291737,0.33326542,-0.6019264,-0.42822492,-0.6524583,-0.15210791,-0.5073593,0.022548754,-0.058033653,-0.47369233,-0.30890635,0.6338296,0.0017854869,0.1954949,0.99348027,-0.26558784,-0.058124136,1.149388,0.02915948,0.013422121,0.25484946,-0.030017598,-0.23879935,0.053123385,-0.36463016,-0.0024245526,0.1202083,-0.45966506,-0.34140104,-0.08484162,-0.03537422,-0.2817959,0.25044164,-0.5060605,0.1252808,-0.032539487,0.110069446,-0.20679846,-0.46421885,-0.4141739,0.26994973,-0.070687145,0.16862138,-0.20162229,0.22199251,-0.2771402,0.23653336,0.16585203,-0.08286354,-0.15343396,0.23893964,-0.7453282,-0.16549355,-0.1947069,0.46136436,0.22064126,0.28654936,-0.038697664,0.037633028,-0.80988157,0.5094175,-0.0920082,0.25405347,-0.64169943,0.43366328,-0.2999211,-0.4090591,0.11957859,0.00803617,-0.0433745,0.12818244,0.28464508,-0.31760025,0.16558012,-0.33553946,-0.3943465,0.59569097,-0.6524206,0.3683173,-0.60456693,0.2046492,0.46010277,0.24695799,0.2946015,0.11376746,-0.027988048,0.03749422,-0.16577742,0.23407385,-0.0231737,-0.023245076,0.08752677,0.2299883,0.35467404,0.046193745,-0.39828986,0.21079691,0.38396686,-0.0018698421,0.16047359,-0.057517264,-0.203534,0.23438136,-0.84250915,0.22371331,0.0058325706,0.30733636,0.19518353,-0.108008966,0.6509316,0.070131645,-0.24023099,0.28779706,0.2326336,0.07004021,-0.45955566,0.20426086,-0.37472793,-0.049604423,0.4537271,0.6133582,-1.0527759,-0.5472505,0.15193434,0.5296606,-0.11560251,0.07279209,0.40557706,0.2505283,0.24490519,0.017602902,-0.004647707,0.16608049,0.12576887,0.118216865,0.4403996,0.39552462,-0.22196701,-0.061155193,0.03693534,-0.4022908,0.3842317,-0.0831345,0.01930883,0.3446575,-0.2167439,-0.23994556,-0.09370326,-0.3671856,0.044011243,0.017895095,-0.019855855,-0.16416992,0.17858285,0.31287143,0.38368022,-0.006513525,0.45780763,-0.23027879,0.108570844,-0.4449492,-0.035763215,0.03818417,0.040017277,-0.17022872,-0.2622464,0.65610534,0.16720143,0.2515769,-0.23535803,0.62484455,0.16771325,-0.62404263,0.19176348,-0.72786695,0.18485649,-0.30914405,-0.3230534,-0.24064465,0.28841522,0.39792386,0.15618932,0.03928854,0.18277727,-0.101632096,0.1868196,-0.33366352,0.086561844,0.48557812,-0.6198209,-0.07978742]}) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.customvectors.schemacreate.mdx b/_includes/code/howto.customvectors.schemacreate.mdx index 2a014b8d2..82eb5f32d 100644 --- a/_includes/code/howto.customvectors.schemacreate.mdx +++ b/_includes/code/howto.customvectors.schemacreate.mdx @@ -21,33 +21,6 @@ class_obj = { client.schema.create_class(class_obj) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const classObj = { - class: 'Post', - vectorizer: 'none', // explicitly tell Weaviate not to vectorize anything, we are providing the vectors ourselves through our BERT model - properties: [{ - name: 'content', - dataType: ['text'], - }], -}; - -const response = await client.schema - .classCreator() - .withClass(classObj) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.query.data.mdx b/_includes/code/howto.query.data.mdx index b83935e36..9d59acca3 100644 --- a/_includes/code/howto.query.data.mdx +++ b/_includes/code/howto.query.data.mdx @@ -48,30 +48,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title url wordCount HasAuthors { ... on Author { name } }') - .withWhere({ - operator: 'Equal', - path: ['inPublication', 'Publication', 'name'], - valueText:'Wired', - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.schema.create.mdx b/_includes/code/howto.schema.create.mdx index f11aa0489..9d78bdd40 100644 --- a/_includes/code/howto.schema.create.mdx +++ b/_includes/code/howto.schema.create.mdx @@ -33,45 +33,6 @@ class_obj = { client.schema.create_class(class_obj) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const classObj = { - class: 'Publication', - description: 'A publication with an online source', - properties: [ - { - dataType: [ - 'string', - ], - description: 'Name of the publication', - name: 'name', - }, - { - dataType: [ - 'geoCoordinates', - ], - description: 'Geo location of the HQ', - name: 'headquartersGeoLocation', - }, - ], -}; - -const response = await client.schema - .classCreator() - .withClass(classObj) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.schema.property.add.mdx b/_includes/code/howto.schema.property.add.mdx index 35348f1d1..0ea359b6a 100644 --- a/_includes/code/howto.schema.property.add.mdx +++ b/_includes/code/howto.schema.property.add.mdx @@ -20,35 +20,6 @@ reference_property = { client.schema.property.create("Publication", reference_property) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const className = 'Publication'; -const prop = { - dataType: [ - 'Article', - ], - description: 'The articles this publication has', - name: 'hasArticles', -}; - -const response = await client.schema - .propertyCreator() - .withClassName(className) - .withProperty(prop) - .do(); -console.log(response); - -``` - diff --git a/_includes/code/howto.semanticsearch.filter.mdx b/_includes/code/howto.semanticsearch.filter.mdx index c297f6695..c33fabe56 100644 --- a/_includes/code/howto.semanticsearch.filter.mdx +++ b/_includes/code/howto.semanticsearch.filter.mdx @@ -60,37 +60,6 @@ query_result = ( print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Publication') - .withFields('name') - .withNearText({ - concepts: ['fashion'], - distance: 0.6, // prior to v1.14 use certainty: 0.7, - moveAwayFrom: { - concepts: ['finance'], - force: 0.45, - }, - moveTo: { - concepts: ['haute couture'], - force: 0.85, - }, - }) - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto.semanticsearch.function.mdx b/_includes/code/howto.semanticsearch.function.mdx index ad70ee636..460baa303 100644 --- a/_includes/code/howto.semanticsearch.function.mdx +++ b/_includes/code/howto.semanticsearch.function.mdx @@ -62,30 +62,6 @@ query_result = client.query.raw(get_articles_query) print(query_result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .explore() - .withNearText({ - concepts: ['fashion'], - moveTo: { concepts: ['haute couture'], force: 0.85 }, - moveAwayFrom: { concepts: ['finance'], force: 0.45 }, - certainty: 0.7, - }) - .withFields('beacon certainty className') - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto/manage-data.create.with.geo.mdx b/_includes/code/howto/manage-data.create.with.geo.mdx index d938381c1..ed49e6953 100644 --- a/_includes/code/howto/manage-data.create.with.geo.mdx +++ b/_includes/code/howto/manage-data.create.with.geo.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.create.py'; - + - - -```python -data_obj = { - "name": "Elsevier", - "headquartersGeoLocation": { - "latitude": 52.3932696, - "longitude": 4.8374263 - } -} - -data_uuid = client.data_object.create( - data_obj, - "Publication", - uuid="df48b9f6-ba48-470c-bf6a-57657cb07390", # optional, if not provided, one is going to be generated -) -``` - - - + ```js const publication = client.collections.use('Publication') @@ -53,25 +34,6 @@ uuid = await publication.data.insert({ console.log('UUID: ', uuid) ``` - - - -```js -const response = await client.data - .creator() - .withClassName('Publication') - .withId('df48b9f6-ba48-470c-bf6a-57657cb07390') - .withProperties({ - 'name': 'Elsevier', - 'headquartersGeoLocation': { - 'latitude': 52.3932696, - 'longitude': 4.8374263, - }, - }) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/howto/manage-data.read.check.existence.mdx b/_includes/code/howto/manage-data.read.check.existence.mdx index 5e1345af0..b652bbd71 100644 --- a/_includes/code/howto/manage-data.read.check.existence.mdx +++ b/_includes/code/howto/manage-data.read.check.existence.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.create.py'; - + - -```python -exists = client.data_object.exists( - "36ddd591-2dee-4e7e-a3cc-eb86d30a4303", - class_name="Author", -) -print(exists) -``` - - - - + ```js import { generateUuid5 } from 'weaviate-client'; @@ -47,18 +36,6 @@ const authorExists = await authors.data.exists(object_uuid) console.log('Author exists: ' + authorExists) ``` - - - -```js -const response = await client.data - .checker() - .withClassName('Author') - .withId('df48b9f6-ba48-470c-bf6a-57657cb07390') - .do(); -console.log(response); -``` - diff --git a/_includes/code/howto/manage-data.shards.inspect.mdx b/_includes/code/howto/manage-data.shards.inspect.mdx index 390c86876..16d496d05 100644 --- a/_includes/code/howto/manage-data.shards.inspect.mdx +++ b/_includes/code/howto/manage-data.shards.inspect.mdx @@ -6,7 +6,7 @@ import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.p import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/manage-data.classes.java'; - + - - -```python -# highlight-start -article_shards = client.schema.get_class_shards("Article") -# highlight-end -print(article_shards) -``` - - - + ```js let articles = client.collections.use('Article') @@ -36,17 +26,6 @@ const shards = await articles.config.getShards() console.log(JSON.stringify(shards, null, 2)); ``` - - - -```js -const response = await client.schema - .shardsGetter() - .withClassName('Article') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/howto/manage-data.shards.update.mdx b/_includes/code/howto/manage-data.shards.update.mdx index 418a4b5ab..622109b5c 100644 --- a/_includes/code/howto/manage-data.shards.update.mdx +++ b/_includes/code/howto/manage-data.shards.update.mdx @@ -7,7 +7,7 @@ import GoCode from '!!raw-loader!/_includes/code/howto/go/docs/manage-data.shard import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/manage-data.classes.java'; - + - - -```python -# highlight-start -article_shards = client.schema.update_class_shard( - "Article", - status="READY", - shard_name="shard-1234" -) -# highlight-end -print(article_shards) -``` - - - + ```js let articles = client.collections.use('Article') @@ -41,19 +27,6 @@ const shards = await articles.config.updateShards('READY', 'shard-1234') console.log(JSON.stringify(shards, null, 2)); ``` - - - -```js -const shards = await client.schema.shardUpdater() - .withClassName('Article') - .withShardName('shard-1234') - .withStatus('READY') - .do() - -console.log(JSON.stringify(shards, null, 2)); -``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const object = await client.data - .creator() - .withClassName('FashionItem') - .withProperties({ - labelName: 'Mickey Mouse T-shirt' - image: 'iVBORw0KGgoAAAANS...' - }) -.do(); - -console.log(JSON.stringify(object, null, 2)); -``` - diff --git a/_includes/code/img2vec-neural.nearimage.encode.mdx b/_includes/code/img2vec-neural.nearimage.encode.mdx index f22203218..932b2fb7a 100644 --- a/_includes/code/img2vec-neural.nearimage.encode.mdx +++ b/_includes/code/img2vec-neural.nearimage.encode.mdx @@ -55,29 +55,6 @@ result = ( print(result) ``` - - - -```js -// The TypeScript client doesn't have a helper function for base64 image encoding - -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('FashionItem') - .withFields('image') - .withNearImage({ image: '/9j/4AAQSkZJRgABAgE...' }) - .do(); - -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/img2vec-neural.nearimage.mdx b/_includes/code/img2vec-neural.nearimage.mdx index 578267832..820d3c4dd 100644 --- a/_includes/code/img2vec-neural.nearimage.mdx +++ b/_includes/code/img2vec-neural.nearimage.mdx @@ -21,27 +21,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('FashionItem') - .withFields('image') - .withNearImage({ image: '/9j/4AAQSkZJRgABAgE...' }) - .do(); - -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/meta.mdx b/_includes/code/meta.mdx index 121609ed6..56d47e5f8 100644 --- a/_includes/code/meta.mdx +++ b/_includes/code/meta.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/rest.meta.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -meta_info = client.get_meta() -print(meta_info) -``` - - ```js diff --git a/_includes/code/ner-transformers-module.mdx b/_includes/code/ner-transformers-module.mdx index 4ec5d827d..e1fab4f62 100644 --- a/_includes/code/ner-transformers-module.mdx +++ b/_includes/code/ner-transformers-module.mdx @@ -47,25 +47,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional { tokens (properties: [\'title\'], limit: 1, certainty: 0.7) {entity property word certainty startPosition endPosition} }') - .do(); -console.log(response); -``` - diff --git a/_includes/code/nodes.mdx b/_includes/code/nodes.mdx index d5a8ba94b..9e55eb7a4 100644 --- a/_includes/code/nodes.mdx +++ b/_includes/code/nodes.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/rest.nodes.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -nodes_status = client.cluster.get_nodes_status() -print(nodes_status) -``` - - ```js diff --git a/_includes/code/qna-openai.ask.mdx b/_includes/code/qna-openai.ask.mdx index 516a7adb7..71c5947df 100644 --- a/_includes/code/qna-openai.ask.mdx +++ b/_includes/code/qna-openai.ask.mdx @@ -58,31 +58,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', - headers: { 'X-OpenAI-Api-Key': 'YOUR-OPENAI-API-KEY' }, -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withAsk({ - question: 'Who is Stanley Kubrick?', - properties: ['summary'], - }) - .withFields('title _additional { answer { hasAnswer property result startPosition endPosition } }') - .withLimit(1) - .do(); -console.log(response); -``` - diff --git a/_includes/code/qna-transformers.ask.mdx b/_includes/code/qna-transformers.ask.mdx index 2e72221eb..2e5e30c30 100644 --- a/_includes/code/qna-transformers.ask.mdx +++ b/_includes/code/qna-transformers.ask.mdx @@ -5,73 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.search-operators.py'; - + - - - -```python -import weaviate -import os - -client = weaviate.Client( - "https://edu-demo.weaviate.network", - auth_client_secret=weaviate.auth.AuthApiKey("learn-weaviate"), - additional_headers={ - "X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"] # Replace with your OPENAI API key - } -) - -ask = { - "question": "Who is the king of the Netherlands?", - "properties": ["summary"] -} - -result = ( - client.query - .get("Article", ["title", "_additional {answer {hasAnswer property result startPosition endPosition} }"]) - .with_ask(ask) - .with_limit(1) - .do() -) - -print(result) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new weaviate.ApiKey('learn-weaviate'), - headers: { - 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'], - }, -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withAsk({ - question: 'Who is the king of the Netherlands?', - properties: ['summary'], - }) - .withFields('title _additional { answer { hasAnswer property result startPosition endPosition } }') - .withLimit(1) - .do(); -console.log(response); - -``` - diff --git a/_includes/code/quickstart.autoschema.connect.docker.mdx b/_includes/code/quickstart.autoschema.connect.docker.mdx index 12e53dd47..83730b0fb 100644 --- a/_includes/code/quickstart.autoschema.connect.docker.mdx +++ b/_includes/code/quickstart.autoschema.connect.docker.mdx @@ -14,16 +14,6 @@ import EndToEndTSCode from '!!raw-loader!/_includes/code/quickstart/endtoend.ts' language="py" /> - - - - - diff --git a/_includes/code/quickstart.autoschema.connect.nokey.mdx b/_includes/code/quickstart.autoschema.connect.nokey.mdx index af6dc2548..81d604b92 100644 --- a/_includes/code/quickstart.autoschema.connect.nokey.mdx +++ b/_includes/code/quickstart.autoschema.connect.nokey.mdx @@ -12,18 +12,6 @@ client = weaviate.Client( ) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); -``` - diff --git a/_includes/code/quickstart.byov.all.mdx b/_includes/code/quickstart.byov.all.mdx index c446bb7a4..6a688ac2c 100644 --- a/_includes/code/quickstart.byov.all.mdx +++ b/_includes/code/quickstart.byov.all.mdx @@ -18,17 +18,6 @@ import ByovAllPyCode from '!!raw-loader!/_includes/code/quickstart.byov.all.py'; - - -import ByovAllTsCode from '!!raw-loader!/_includes/code/quickstart.byov.all.ts'; - - - - {/* ```go diff --git a/_includes/code/quickstart.byov.schema.mdx b/_includes/code/quickstart.byov.schema.mdx index 3d5582d80..a6a00c846 100644 --- a/_includes/code/quickstart.byov.schema.mdx +++ b/_includes/code/quickstart.byov.schema.mdx @@ -4,13 +4,11 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import ByovAllPyCode from '!!raw-loader!/_includes/code/quickstart.byov.all.py'; -import ByovAllPy3Code from '!!raw-loader!/_includes/code/quickstart.byov.all_v3.py'; import ByovAllTsCode from '!!raw-loader!/_includes/code/quickstart.byov.all.ts'; -import ByovAllTsCodeLegacy from '!!raw-loader!/_includes/code/quickstart.byov.all.legacy.ts'; import ByovAllShCode from '!!raw-loader!/_includes/code/quickstart.byov.all.sh'; - + - - - - + - - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -const response = await client - .data - .getter() - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart.import.questions-and-vectors.mdx b/_includes/code/quickstart.import.questions-and-vectors.mdx index 09b6eac99..97e82cc06 100644 --- a/_includes/code/quickstart.import.questions-and-vectors.mdx +++ b/_includes/code/quickstart.import.questions-and-vectors.mdx @@ -4,13 +4,11 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import ByovAllPyCode from '!!raw-loader!/_includes/code/quickstart.byov.all.py'; -import ByovAllPy3Code from '!!raw-loader!/_includes/code/quickstart.byov.all_v3.py'; import ByovAllTsCode from '!!raw-loader!/_includes/code/quickstart.byov.all.ts'; -import ByovAllTsCodeLegacy from '!!raw-loader!/_includes/code/quickstart.byov.all.legacy.ts'; - + - - - - + - -The import uses the `node-fetch` library.

- -```bash -npm install node-fetch -``` - - -
diff --git a/_includes/code/quickstart.import.questions.mdx b/_includes/code/quickstart.import.questions.mdx index b2270dd43..b06cc856c 100644 --- a/_includes/code/quickstart.import.questions.mdx +++ b/_includes/code/quickstart.import.questions.mdx @@ -39,64 +39,6 @@ with client.batch as batch: batch.add_data_object(properties, "Question") ``` -
- - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - headers: { 'X-OpenAI-Api-Key': 'YOUR-OPENAI-API-KEY' }, // Replace with your API key -}); - -async function getJsonData() { - const file = await fetch('https://raw.githubusercontent.com/weaviate-tutorials/quickstart/main/data/jeopardy_tiny.json'); - return file.json(); -} - -async function importQuestions() { - // Get the data from the data.json file - const data = await getJsonData(); - - // Prepare a batcher - let batcher = client.batch.objectsBatcher(); - let counter = 0; - const batchSize = 100; - - for (const question of data) { - // Construct an object with a class and properties 'answer' and 'question' - const obj = { - class: 'Question', - properties: { - answer: question.Answer, - question: question.Question, - category: question.Category, - }, - }; - - // add the object to the batch queue - batcher = batcher.withObject(obj); - - // When the batch counter reaches batchSize, push the objects to Weaviate - if (counter++ == batchSize) { - // flush the batch queue - await batcher.do(); - - // restart the batch queue - counter = 0; - batcher = client.batch.objectsBatcher(); - } - } - - // Flush the remaining objects - await batcher.do(); -} - -await importQuestions(); -``` - {/* diff --git a/_includes/code/quickstart.query.aggregate.1.mdx b/_includes/code/quickstart.query.aggregate.1.mdx index d1d8d5fdd..30e48950e 100644 --- a/_includes/code/quickstart.query.aggregate.1.mdx +++ b/_includes/code/quickstart.query.aggregate.1.mdx @@ -40,27 +40,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate API key - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .aggregate() - .withClassName('Question') - .withFields('meta { count }') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart.query.aggregate.2.mdx b/_includes/code/quickstart.query.aggregate.2.mdx index 2a38ca760..792ee028b 100644 --- a/_includes/code/quickstart.query.aggregate.2.mdx +++ b/_includes/code/quickstart.query.aggregate.2.mdx @@ -53,31 +53,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .aggregate() - .withClassName('Question') - .withFields('meta { count }') - .withWhere({ - path: ['category'], - operator: 'Equal', - valueText: 'ANIMALS', - }) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart.query.nearVector.mdx b/_includes/code/quickstart.query.nearVector.mdx index 31b1ab9ad..b7ad465ca 100644 --- a/_includes/code/quickstart.query.nearVector.mdx +++ b/_includes/code/quickstart.query.nearVector.mdx @@ -3,7 +3,7 @@ import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + import ByovAllPyCode from '!!raw-loader!/_includes/code/quickstart.byov.all.py'; @@ -15,19 +15,7 @@ import ByovAllPyCode from '!!raw-loader!/_includes/code/quickstart.byov.all.py'; /> - - -import ByovAllPy3Code from '!!raw-loader!/_includes/code/quickstart.byov.all_v3.py'; - - - - - + import ByovAllTsCode from '!!raw-loader!/_includes/code/quickstart.byov.all.ts'; @@ -40,18 +28,6 @@ import ByovAllTsCode from '!!raw-loader!/_includes/code/quickstart.byov.all.ts'; - - -import ByovAllTsCodeLegacy from '!!raw-loader!/_includes/code/quickstart.byov.all.legacy.ts'; - - - - diff --git a/_includes/code/quickstart.query.neartext.additional.mdx b/_includes/code/quickstart.query.neartext.additional.mdx index 14aae221a..00f15c0cf 100644 --- a/_includes/code/quickstart.query.neartext.additional.mdx +++ b/_includes/code/quickstart.query.neartext.additional.mdx @@ -47,28 +47,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .get() - .withClassName('Question') - .withFields('question answer category _additional {certainty}') - .withNearText({ concepts: ['biology'] }) - .withLimit(2) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart.query.where.1.mdx b/_includes/code/quickstart.query.where.1.mdx index 8c556f8d3..41f98aabc 100644 --- a/_includes/code/quickstart.query.where.1.mdx +++ b/_includes/code/quickstart.query.where.1.mdx @@ -39,32 +39,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .get() - .withClassName('Question') - .withFields('question answer category') - .withNearText({ concepts: ['biology'] }) - .withWhere({ - path: ['category'], - operator: 'Equal', - valueText: 'ANIMALS', - }) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart.query.where.2.mdx b/_includes/code/quickstart.query.where.2.mdx index 9080bea29..c05a47cae 100644 --- a/_includes/code/quickstart.query.where.2.mdx +++ b/_includes/code/quickstart.query.where.2.mdx @@ -42,33 +42,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - headers: { 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'] }, // Replace with your API key -}); - -const response = await client.graphql - .get() - .withClassName('Question') - .withFields('question answer category _additional { id certainty }') - .withNearText({ concepts: ['biology'] }) - .withWhere({ - path: ['category'], - operator: 'Equal', - valueText: 'ANIMALS', - }) - .withLimit(2) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - {/* diff --git a/_includes/code/quickstart/collection.definition.mdx b/_includes/code/quickstart/collection.definition.mdx index ccf63a9ea..59b2b828e 100644 --- a/_includes/code/quickstart/collection.definition.mdx +++ b/_includes/code/quickstart/collection.definition.mdx @@ -4,11 +4,10 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import EndToEndPyCode from '!!raw-loader!/_includes/code/quickstart/endtoend.py'; import EndToEndPy3Code from '!!raw-loader!/_includes/code/quickstart/endtoend.py3.py'; import EndToEndTSCode from '!!raw-loader!/_includes/code/quickstart/endtoend.ts'; -import EndToEndTSCodeLegacy from '!!raw-loader!/_includes/code/quickstart/endtoend-v2.ts'; import GoCollectionDefine from '!!raw-loader!/_includes/code/quickstart/go-collection-define.go'; - + - - - - - - + - - - - + ```python import weaviate, os @@ -27,20 +27,7 @@ client.is_ready() ``` - - -```python -import weaviate -import json - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=weaviate.auth.AuthApiKey(api_key="YOUR-WEAVIATE-API-KEY"), # Replace with your Weaviate instance API key -) -``` - - - + ```ts import weaviate, { WeaviateClient } from 'weaviate-client' @@ -59,20 +46,6 @@ const client: WeaviateClient = await weaviate.connectToWeaviateCloud( - - -```ts -import weaviate, { WeaviateClient, ObjectsBatcher, ApiKey } from 'weaviate-ts-client'; -import fetch from 'node-fetch'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate instance API key -}); -``` - - ```go diff --git a/_includes/code/quickstart/connect.partial.mdx b/_includes/code/quickstart/connect.partial.mdx index 84e5e07f5..b708d7062 100644 --- a/_includes/code/quickstart/connect.partial.mdx +++ b/_includes/code/quickstart/connect.partial.mdx @@ -3,7 +3,7 @@ import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + ```python import weaviate, os @@ -24,20 +24,7 @@ client.is_ready() ``` - - -```python -import weaviate -import json - -client = weaviate.Client( - url = "https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=weaviate.auth.AuthApiKey(api_key="YOUR-WEAVIATE-API-KEY"), # Replace with your Weaviate instance API key -) -``` - - - + ```ts import weaviate, { WeaviateClient } from 'weaviate-client' @@ -54,20 +41,6 @@ const client: WeaviateClient = await weaviate.connectToWeaviateCloud(weaviateURL - - -```ts -import weaviate, { WeaviateClient, ObjectsBatcher, ApiKey } from 'weaviate-ts-client'; -import fetch from 'node-fetch'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate instance API key -}); -``` - - For `curl`, add the API key to the header as shown below: diff --git a/_includes/code/quickstart/connect.withkey.mdx b/_includes/code/quickstart/connect.withkey.mdx index 32a17a907..8aeee23e4 100644 --- a/_includes/code/quickstart/connect.withkey.mdx +++ b/_includes/code/quickstart/connect.withkey.mdx @@ -4,12 +4,11 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import EndToEndPyCode from '!!raw-loader!/_includes/code/quickstart/endtoend.py'; import EndToEndPy3Code from '!!raw-loader!/_includes/code/quickstart/endtoend.py3.py'; import EndToEndTSCode from '!!raw-loader!/_includes/code/quickstart/endtoend.ts'; -import EndToEndTSCodeLegacy from '!!raw-loader!/_includes/code/quickstart/endtoend-v2.ts'; import GoConnectCode from '!!raw-loader!/_includes/code/quickstart/go-connect.go'; - + - - - - - - + - - - - - - + - - - - + - - - @@ -27,7 +26,7 @@ import GoGenGrouped from '!!raw-loader!/_includes/code/quickstart/go-query-gener ``` */} - + - - - - + - - - @@ -27,7 +26,7 @@ import GoGenerative from '!!raw-loader!/_includes/code/quickstart/go-query-gener ``` */} - + - - - - + - - - - + - - - - - - - - - - diff --git a/_includes/code/quickstart/import.mdx b/_includes/code/quickstart/import.mdx index c11925062..47f139c77 100644 --- a/_includes/code/quickstart/import.mdx +++ b/_includes/code/quickstart/import.mdx @@ -2,13 +2,11 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import EndToEndPyCode from '!!raw-loader!/_includes/code/quickstart/endtoend.py'; -import EndToEndPy3Code from '!!raw-loader!/_includes/code/quickstart/endtoend.py3.py'; import EndToEndTSCode from '!!raw-loader!/_includes/code/quickstart/endtoend.ts'; -import EndToEndTSCodeLegacy from '!!raw-loader!/_includes/code/quickstart/endtoend-v2.ts'; import GoImportObjects from '!!raw-loader!/_includes/code/quickstart/go-add-objects.go'; - + - - - - + - - - @@ -27,7 +25,7 @@ import GoNearText from '!!raw-loader!/_includes/code/quickstart/go-query-neartex ``` */} - + - - - - - - + - - - GoNearText diff --git a/_includes/code/quickstart/neartext.where.mdx b/_includes/code/quickstart/neartext.where.mdx index 3e40e37b1..b38ba1494 100644 --- a/_includes/code/quickstart/neartext.where.mdx +++ b/_includes/code/quickstart/neartext.where.mdx @@ -4,7 +4,6 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import EndToEndPyCode from '!!raw-loader!/_includes/code/quickstart/endtoend.py'; import EndToEndPy3Code from '!!raw-loader!/_includes/code/quickstart/endtoend.py3.py'; import EndToEndTSCode from '!!raw-loader!/_includes/code/quickstart/endtoend.ts'; -import EndToEndTSCodeLegacy from '!!raw-loader!/_includes/code/quickstart/endtoend-v2.ts'; import GoWhereFilter from '!!raw-loader!/_includes/code/quickstart/go-query-filter.go'; @@ -27,7 +26,7 @@ import GoWhereFilter from '!!raw-loader!/_includes/code/quickstart/go-query-filt ``` */} - + - - - - + - - - - + - - -```python -import weaviate -from weaviate.data.replication import ConsistencyLevel - -client = weaviate.Client("http://localhost:8080") - -data_object = ( - client.data_object.get_by_id( - uuid="36ddd591-2dee-4e7e-a3cc-eb86d30a4303", - class_name="MyClass", - consistency_level=ConsistencyLevel.ONE, - ) -) - -# The parameter "consistency_level" can be one of ConsistencyLevel.ALL, -# ConsistencyLevel.QUORUM (default), or ConsistencyLevel.ONE. Determines how many -# replicas must acknowledge a request before it is considered successful. - -print(data_object) -``` - - - + - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.data - .getterById() - .withClassName('MyClass') - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303') - .withConsistencyLevel('ONE') // default QUORUM - .do(); -console.log(JSON.stringify(response, null, 2)); - -// The parameter passed to `withConsistencyLevel` can be one of: -// * 'ALL', -// * 'QUORUM' (default), or -// * 'ONE'. -// -// It determines how many replicas must acknowledge a request -// before it is considered successful. -``` - diff --git a/_includes/code/schema.things.create.replication.mdx b/_includes/code/schema.things.create.replication.mdx index 9cc8f0b51..94ba68c32 100644 --- a/_includes/code/schema.things.create.replication.mdx +++ b/_includes/code/schema.things.create.replication.mdx @@ -1,14 +1,12 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.collections-v3.py'; import TSCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.ts'; -import TSCodeLegacy from '!!raw-loader!/_includes/code/howto/manage-data.collections-v2.ts'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - - - - + - - - diff --git a/_includes/code/schema.things.properties.add.mdx b/_includes/code/schema.things.properties.add.mdx index 31a18ce9f..348b8e1d0 100644 --- a/_includes/code/schema.things.properties.add.mdx +++ b/_includes/code/schema.things.properties.add.mdx @@ -6,7 +6,7 @@ import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.collections.p import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/manage-data.classes.java'; - + - - -```python -add_prop = { - "dataType": [ - "boolean" - ], - "name": "onHomepage" -} - -client.schema.property.create("Article", add_prop) -``` - - - + ```js let articles = client.collections.use('Article') @@ -42,24 +28,6 @@ articles.config.addProperty({ // highlight-end ``` - - - -```js -const className = 'Article'; -const prop = { - dataType: ['boolean'], - name: 'onHomepage', -}; - -const response = await client.schema - .propertyCreator() - .withClassName(className) - .withProperty(prop) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/spellcheck-module.mdx b/_includes/code/spellcheck-module.mdx index 304bd65ec..f38bfc3a8 100644 --- a/_includes/code/spellcheck-module.mdx +++ b/_includes/code/spellcheck-module.mdx @@ -49,28 +49,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional { spellCheck { change {corrected original} didYouMean location originalText } }') - .withNearText({ - concepts: ['houssing prices'], - }) - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/sum-transformers-module.mdx b/_includes/code/sum-transformers-module.mdx index 11c8d2149..05acec925 100644 --- a/_includes/code/sum-transformers-module.mdx +++ b/_includes/code/sum-transformers-module.mdx @@ -41,25 +41,6 @@ result = ( print(result) ``` - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'http', - host: 'localhost:8080', -}); - -const response = await client.graphql - .get() - .withClassName('Article') - .withFields('title _additional { summary ( properties: ["summary"]) { property result } }') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/code/tutorial.schema.create.mdx b/_includes/code/tutorial.schema.create.mdx index 59fcdc768..e0a0ec7c3 100644 --- a/_includes/code/tutorial.schema.create.mdx +++ b/_includes/code/tutorial.schema.create.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/starter-guides/schema.py'; - + - - - -```python -import weaviate -import json - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL/") # Replace with your Weaviate endpoint - -# we will create the class "Question" -class_obj = { - "class": "Question", - "description": "Information from a Jeopardy! question", # description of the class - "properties": [ - { - "name": "question", - "dataType": ["text"], - "description": "The question", - }, - { - "name": "answer", - "dataType": ["text"], - "description": "The answer", - }, - { - "name": "category", - "dataType": ["text"], - "description": "The question category", - }, - ], - "vectorizer": "text2vec-openai", - "moduleConfig": { - "generative-openai": {} # Set `generative-openai` as the generative module - } -} - -# add the schema -client.schema.create_class(class_obj) - -# get the schema -schema = client.schema.get() - -# print the schema -print(json.dumps(schema, indent=4)) -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -// Define the 'Question' class -const classObj = { - class: 'Question', - description: 'Information from a Jeopardy! question', // description of the class - properties: [ - { - name: 'question', - dataType: ['text'], - description: 'The question', - }, - { - name: 'answer', - dataType: ['text'], - description: 'The answer', - }, - { - name: 'category', - dataType: ['text'], - description: 'The question category', - }, - ], - vectorizer: 'text2vec-openai', - moduleConfig: { - generative-openai: {} // Set `generative-openai` as the generative module - } -}; - -// Add the class to the schema -await client - .schema - .classCreator() - .withClass(classObj) - .do(); -``` - {/* diff --git a/_includes/code/tutorial.schema.index-settings.mdx b/_includes/code/tutorial.schema.index-settings.mdx index e61746e9f..bbf2a4353 100644 --- a/_includes/code/tutorial.schema.index-settings.mdx +++ b/_includes/code/tutorial.schema.index-settings.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/starter-guides/schema.py'; - + - -```python -import weaviate -import json - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL/") # Replace with your Weaviate endpoint - -# we will create the class "Question" -class_obj = { - "class": "Question", - "description": "Information from a Jeopardy! question", # description of the class - "vectorizer": "text2vec-openai", - "moduleConfig": { - "generative-openai": {} # Set `generative-openai` as the generative module - }, - "properties": [ - { - "name": "question", - "dataType": ["text"], - "description": "The question", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": True, - "tokenization": "lowercase" - } - } - }, - { - "name": "answer", - "dataType": ["text"], - "description": "The answer", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": False, - "tokenization": "whitespace" - } - } - }, - ], - # highlight-start - # Configure the vector index - "vectorIndexType": "hnsw", # Or "flat" or "dynamic" - "vectorIndexConfig": { - "distance": "cosine", - "bq": { - "enabled": True, - }, - }, - # Configure the inverted index - "indexTimestamps": True, - "indexNullState": True, - "indexPropertyLength": True, - # highlight-end -} - -# add the schema -client.schema.create_class(class_obj) -``` - - - - + ```js import weaviate from 'weaviate-client'; @@ -128,73 +67,6 @@ const newCollection = await client.collections.create(collectionObj) - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -// Define the 'Question' class -const classObj = { - class: 'Question', - description: 'Information from a Jeopardy! question', // description of the class - vectorizer: 'text2vec-openai', - moduleConfig: { - generative-openai: {} // Set `generative-openai` as the generative module - }, - properties: [ - { - name: 'question', - dataType: ['text'], - description: 'The question', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: true, - tokenization: 'lowercase' // Use "lowercase" tokenization - }, - } - }, - { - name: 'answer', - dataType: ['text'], - description: 'The answer', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: false, - tokenization: 'whitespace' // Use "whitespace" tokenization - }, - } - }, - ], - // highlight-start - // Configure the vector index - vectorIndexType: 'hnsw', // Or `flat` or `dynamic` - vectorIndexConfig: { - distance: 'cosine', - bq: { - enabled: True, - }, - }, - // Configure the inverted index - indexTimestamps: true, - indexNullState: true, - indexPropertyLength: true, - // highlight-end -}; - -// Add the class to the schema -await client - .schema - .classCreator() - .withClass(classObj) - .do(); -``` - - {/* ```go diff --git a/_includes/code/tutorial.schema.multi-tenancy.mdx b/_includes/code/tutorial.schema.multi-tenancy.mdx index a3cc2d2be..916b46d2b 100644 --- a/_includes/code/tutorial.schema.multi-tenancy.mdx +++ b/_includes/code/tutorial.schema.multi-tenancy.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/starter-guides/schema.py'; - + - -```python -import weaviate -import json - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL/") # Replace with your Weaviate endpoint - -# we will create the class "Question" -class_obj = { - "class": "Question", - "description": "Information from a Jeopardy! question", # description of the class - "vectorizer": "text2vec-openai", - "moduleConfig": { - "generative-openai": {} # Set `generative-openai` as the generative module - }, - "properties": [ - { - "name": "question", - "dataType": ["text"], - "description": "The question", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": True, - "tokenization": "lowercase" - } - } - }, - { - "name": "answer", - "dataType": ["text"], - "description": "The answer", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": False, - "tokenization": "whitespace" - } - } - }, - ], - # highlight-start - "multiTenancyConfig": {"enabled": True}, # Enable multi-tenancy - # highlight-end -} - -# add the schema -client.schema.create_class(class_obj) -``` - - - - + ```js import weaviate from 'weaviate-client'; @@ -108,62 +58,6 @@ const newCollection = await client.collections.create(collectionObj) - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -// Define the 'Question' class -const classObj = { - class: 'Question', - description: 'Information from a Jeopardy! question', // description of the class - vectorizer: 'text2vec-openai', - moduleConfig: { - generative-openai: {} // Set `generative-openai` as the generative module - }, - properties: [ - { - name: 'question', - dataType: ['text'], - description: 'The question', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: true, - tokenization: 'lowercase' // Use "lowercase" tokenization - }, - } - }, - { - name: 'answer', - dataType: ['text'], - description: 'The answer', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: false, - tokenization: 'whitespace' // Use "whitespace" tokenization - }, - } - }, - ], - // highlight-start - multiTenancyConfig: { enabled: true } // Enable multi-tenancy - // highlight-end -}; - -// Add the class to the schema -await client - .schema - .classCreator() - .withClass(classObj) - .do(); -``` - - {/* ```go diff --git a/_includes/code/tutorial.schema.properties.options.mdx b/_includes/code/tutorial.schema.properties.options.mdx index 534dfc4c2..ca68fab39 100644 --- a/_includes/code/tutorial.schema.properties.options.mdx +++ b/_includes/code/tutorial.schema.properties.options.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/starter-guides/schema.py'; - + - -```python -import weaviate -import json - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL/") # Replace with your Weaviate endpoint - -# we will create the class "Question" -class_obj = { - "class": "Question", - "description": "Information from a Jeopardy! question", # description of the class - "vectorizer": "text2vec-openai", - "moduleConfig": { - "generative-openai": {} # Set `generative-openai` as the generative module - }, - "properties": [ - { - "name": "question", - "dataType": ["text"], - "description": "The question", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": True, - "tokenization": "lowercase" - } - } - }, - { - "name": "answer", - "dataType": ["text"], - "description": "The answer", - "moduleConfig": { - "text2vec-openai": { # this must match the vectorizer used - "vectorizePropertyName": False, - "tokenization": "whitespace" - } - } - }, - ], -} - -# add the schema -client.schema.create_class(class_obj) -``` - - - - + ```js import weaviate from 'weaviate-client'; @@ -103,59 +56,6 @@ const newCollection = await client.collections.create(collectionObj) - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -// Define the 'Question' class -const classObj = { - class: 'Question', - description: 'Information from a Jeopardy! question', // description of the class - vectorizer: 'text2vec-openai', - moduleConfig: { - generative-openai: {} // Set `generative-openai` as the generative module - }, - properties: [ - { - name: 'question', - dataType: ['text'], - description: 'The question', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: true, - tokenization: 'lowercase' // Use "lowercase" tokenization - }, - } - }, - { - name: 'answer', - dataType: ['text'], - description: 'The answer', - moduleConfig: { - 'text2vec-openai': { // this must match the vectorizer used - vectorizePropertyName: false, - tokenization: 'whitespace' // Use "whitespace" tokenization - }, - } - }, - ] -}; - -// Add the class to the schema -await client - .schema - .classCreator() - .withClass(classObj) - .do(); -``` - - {/* ```go diff --git a/_includes/code/tutorials.wikipedia.hybrid.mdx b/_includes/code/tutorials.wikipedia.hybrid.mdx index 533e45d3c..8e57e932f 100644 --- a/_includes/code/tutorials.wikipedia.hybrid.mdx +++ b/_includes/code/tutorials.wikipedia.hybrid.mdx @@ -38,24 +38,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -const hybridResult = await client.graphql - .get() - .withClassName('Article') - .withFields('title content _additional{score}') - .withHybrid({ - query: 'jackfruit', - alpha: 0.5, // optional, defaults to 0.75 - }) - .withLimit(3) - .do(); - -console.log('hybrid: jackfruit = ', JSON.stringify(hybridResult.data['Get']['Article'], null, 2)); -``` - {/* diff --git a/_includes/code/tutorials.wikipedia.import.mdx b/_includes/code/tutorials.wikipedia.import.mdx index 3bf4dfc3b..adef9bc78 100644 --- a/_includes/code/tutorials.wikipedia.import.mdx +++ b/_includes/code/tutorials.wikipedia.import.mdx @@ -46,56 +46,5 @@ with client.batch as batch: print(f"Finished importing {counter} articles.") ``` - - - -```js -// ===== Import data ===== -import fs from 'fs'; -import csv from 'csv-parser'; - -async function importCSV(filePath) { - let batcher = client.batch.objectsBatcher(); - let counter = 0; - const batchSize = 100; - - return new Promise((resolve, reject) => { - fs.createReadStream(filePath) - .pipe(csv()) - .on('data', async (row) => { - // Import each record - const obj = { - class: 'Article', - properties: { - title: row.title, - content: row.text, - url: row.url, - }, - vector: JSON.parse(row['content_vector']), - } - // Add the object to the batch queue - batcher = batcher.withObject(obj); - counter++; - - // When the batch counter reaches batchSize, push the objects to Weaviate - if (counter % batchSize === 0) { - console.log(`Imported ${counter} articles...`); - // Flush the batch queue and restart it - await batcher.do(); - batcher = client.batch.objectsBatcher(); - } - }) - .on('end', async () => { - // Flush the remaining objects - await batcher.do(); - console.log(`Finished importing ${counter} articles.`); - resolve(); - }); - }); -} - -await importCSV('vector_database_wikipedia_articles_embedded.csv'); -``` - diff --git a/_includes/code/tutorials.wikipedia.nearText.mdx b/_includes/code/tutorials.wikipedia.nearText.mdx index c978db5b1..d52cf4610 100644 --- a/_includes/code/tutorials.wikipedia.nearText.mdx +++ b/_includes/code/tutorials.wikipedia.nearText.mdx @@ -45,21 +45,6 @@ result = ( print(json.dumps(result, indent=4)) ``` - - - -```js -const nearTextResult = await client.graphql - .get() - .withClassName('Article') - .withFields('title content') - .withNearText({ concepts: ['modern art in Europe'] }) - .withLimit(1) - .do(); - -console.log('nearText: modern art in Europe = ', JSON.stringify(nearTextResult.data['Get']['Article'], null, 2)); -``` - {/* diff --git a/_includes/code/tutorials.wikipedia.schema.mdx b/_includes/code/tutorials.wikipedia.schema.mdx index 6af54c7f9..7ddb4b172 100644 --- a/_includes/code/tutorials.wikipedia.schema.mdx +++ b/_includes/code/tutorials.wikipedia.schema.mdx @@ -44,52 +44,5 @@ print('Created schema'); - - -```js -try { - await client.schema.classDeleter().withClassName('Article').do(); - console.log('Deleted existing Articles'); -} catch (e) { - if (!e.match(/could not find class/)) - throw e; -} - -// ===== Create Article class for the schema ===== -const articleClass = { - class: 'Article', - description: 'An article from the Simple English Wikipedia data set', - vectorizer: 'text2vec-openai', - moduleConfig: { - // Match how OpenAI created the embeddings for the `content` (`text`) field - 'text2vec-openai': { - model: 'ada', - modelVersion: '002', - type: 'text', - vectorizeClassName: false, - }, - }, - properties: [ - { - name: 'title', - description: 'The title of the article', - dataType: ['string'], - // Don't vectorize the title - moduleConfig: { 'text2vec-openai': { skip: true } }, - }, - { - name: 'content', - description: 'The content of the article', - dataType: ['text'], - }, - ], -}; - -// Add the Article class to the schema -await client.schema.classCreator().withClass(articleClass).do(); -console.log('Created schema'); -``` - - diff --git a/_includes/code/wcs.authentication.api.key.edu-demo.mdx b/_includes/code/wcs.authentication.api.key.edu-demo.mdx index 77b5ff6c3..1401a813f 100644 --- a/_includes/code/wcs.authentication.api.key.edu-demo.mdx +++ b/_includes/code/wcs.authentication.api.key.edu-demo.mdx @@ -19,24 +19,6 @@ client = weaviate.Client( ) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -// Instantiate the client with the auth config -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new ApiKey('learn-weaviate'), - headers: { - // Only needed if using an inference service (e.g. `nearText`, `hybrid` or `generative` queries) - 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'], // Replace with your API key - }, -}); -``` - diff --git a/_includes/code/wcs.authentication.api.key.mdx b/_includes/code/wcs.authentication.api.key.mdx index 9129eb6c7..bd3dd6b2f 100644 --- a/_includes/code/wcs.authentication.api.key.mdx +++ b/_includes/code/wcs.authentication.api.key.mdx @@ -5,7 +5,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - + Use an API key to connect to Weaviate Cloud. - - -```python -import weaviate -import os - -# Instantiate the client with the auth config -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=weaviate.auth.AuthApiKey(api_key=weaviate_key), # Replace with your Weaviate instance API key -) -``` - - - + ```ts import weaviate from 'weaviate-client'; @@ -51,20 +37,6 @@ const client = await weaviate.connectToWeaviateCloud( ) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -// Instantiate the client with the auth config -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL - apiKey: new ApiKey(weaviateKey), -}); -``` - diff --git a/_includes/code/wcs.authentication.api.key.with.inference.key.mdx b/_includes/code/wcs.authentication.api.key.with.inference.key.mdx index c14c0849b..0aa3da1dc 100644 --- a/_includes/code/wcs.authentication.api.key.with.inference.key.mdx +++ b/_includes/code/wcs.authentication.api.key.with.inference.key.mdx @@ -5,7 +5,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - + - - -```python -import weaviate -import os - -cohere_key = os.getenv("COHERE_API_KEY") # Recommended: save to an environment variable - -# Instantiate the client with the auth config -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=weaviate.auth.AuthApiKey(api_key=weaviate_key), # Replace with your Weaviate instance API key - additional_headers={ - "X-Cohere-Api-Key": cohere_key, - }, -) -``` - - - + ```js import weaviate, { ApiKey } from 'weaviate-client'; @@ -50,25 +31,6 @@ const client = await weaviate.connectToWeaviateCloud( ) ``` - - - -```js -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -var cohereKey = process.env.COHERE_API_KEY; // Recommended: save to an environment variable - -// Instantiate the client with the auth config -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL - apiKey: new ApiKey(weaviateKey), // Replace with your Weaviate instance API key - headers: { - 'X-Cohere-Api-Key': cohereKey, // Replace with your Cohere API key - }, -}); -``` - diff --git a/_includes/code/wcs.authentication.api.key.with.openai.key.mdx b/_includes/code/wcs.authentication.api.key.with.openai.key.mdx index 0da91a255..43d137824 100644 --- a/_includes/code/wcs.authentication.api.key.with.openai.key.mdx +++ b/_includes/code/wcs.authentication.api.key.with.openai.key.mdx @@ -18,23 +18,6 @@ client = weaviate.Client( ) ``` - - - -```ts -import weaviate, { ApiKey } from 'weaviate-ts-client'; - -// Instantiate the client with the auth config -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate instance API key - headers: { - 'X-OpenAI-Api-Key': process.env['OPENAI_API_KEY'], // Replace with your API key - }, -}); -``` - diff --git a/_includes/code/wcs.authentication.user.pass.mdx b/_includes/code/wcs.authentication.user.pass.mdx index 6af9c03be..d4a480e82 100644 --- a/_includes/code/wcs.authentication.user.pass.mdx +++ b/_includes/code/wcs.authentication.user.pass.mdx @@ -5,7 +5,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - + - - -```python -import weaviate - -# Instantiate the client with the auth config -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=weaviate.AuthClientPassword( - username = wcd_username, # Replace with your Weaviate Cloud username - password = wcd_password, # Replace with your Weaviate Cloud password - ), -) -``` - - - + ```ts import weaviate from 'weaviate-client'; @@ -46,22 +30,6 @@ const client = await weaviate.connectToWeaviateCloud( - - -```ts -import weaviate, { AuthUserPasswordCredentials } from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: "https", - host: "WEAVIATE_INSTANCE_URL", // Replace with your Weaviate endpoint - authClientSecret: new AuthUserPasswordCredentials({ - username: wcdUsername, // Replace with your Weaviate Cloud username - password: wcdPassword, // Replace with your Weaviate Cloud password - }) -}); -``` - - ```go diff --git a/_includes/code/wcs.client.is_ready.mdx b/_includes/code/wcs.client.is_ready.mdx index 6c74f6477..5095b3653 100644 --- a/_includes/code/wcs.client.is_ready.mdx +++ b/_includes/code/wcs.client.is_ready.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyClientCode from '!!raw-loader!/_includes/code/wcs.client.is_ready.py'; - + - - -```python -import weaviate -import os - -client = weaviate.Client( - url=os.getenv("WEAVIATE_INSTANCE_URL"), # Replace with your Weaviate endpoint - auth_client_secret=weaviate.auth.AuthApiKey(api_key=os.getenv("YOUR-WEAVIATE-API-KEY")), # Replace with your Weaviate instance API key - additional_headers={ - 'X-OpenAI-Api-key': os.getenv("OPENAI_APIKEY") # Replace with your third party API key and identifying header - } -) - -print(client.is_ready()) -``` - - - + ```js import weaviate, { WeaviateClient } from 'weaviate-client'; @@ -44,24 +26,6 @@ const response = await client.isReady(); console.log(response); ``` - - - -```js -import weaviate, { WeaviateClient, ObjectsBatcher, ApiKey } from 'weaviate-ts-client'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint - apiKey: new ApiKey('YOUR-WEAVIATE-API-KEY'), // Replace with your Weaviate instance API key -}); - -const response = await client.misc - .readyChecker() - .do(); -console.log(response); -``` - diff --git a/_includes/code/wcs.without.authentication.mdx b/_includes/code/wcs.without.authentication.mdx index a4913a28d..803a64a49 100644 --- a/_includes/code/wcs.without.authentication.mdx +++ b/_includes/code/wcs.without.authentication.mdx @@ -4,7 +4,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/tutorials/connect.py'; - + - -```python -import weaviate - -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint -) -``` - - - - + ```ts import weaviate from 'weaviate-client'; @@ -36,18 +25,6 @@ const client: WeaviateClient = await weaviate.connectToWeaviateCloud( - - -```ts -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); -``` - - ```go diff --git a/_includes/code/wellknown.live.mdx b/_includes/code/wellknown.live.mdx index 5a31a98a3..ac3f14c41 100644 --- a/_includes/code/wellknown.live.mdx +++ b/_includes/code/wellknown.live.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/rest.well-known.py'; - + - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -is_live = client.is_live() -print(is_live) -``` - - ```js diff --git a/_includes/code/wellknown.openid-configuration.mdx b/_includes/code/wellknown.openid-configuration.mdx index 1e1fa112e..07cd9ba2a 100644 --- a/_includes/code/wellknown.openid-configuration.mdx +++ b/_includes/code/wellknown.openid-configuration.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/rest.well-known.py'; - + - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -open_id_configuration = client.get_open_id_configuration() -print(open_id_configuration) -``` - - ```js diff --git a/_includes/code/wellknown.ready.mdx b/_includes/code/wellknown.ready.mdx index 009913a55..fd877b751 100644 --- a/_includes/code/wellknown.ready.mdx +++ b/_includes/code/wellknown.ready.mdx @@ -6,7 +6,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/rest.well-known.py'; - + - - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -is_ready = client.is_ready() -print(is_ready) # returns True if Weaviate is ready -``` - - ```js diff --git a/_includes/configuration/bq-compression-parameters.mdx b/_includes/configuration/bq-compression-parameters.mdx index 8a82b11f4..346b1ab7d 100644 --- a/_includes/configuration/bq-compression-parameters.mdx +++ b/_includes/configuration/bq-compression-parameters.mdx @@ -1,6 +1,6 @@ | Parameter | Type | Default | Details | | :---------------------- | :------ | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `bq` : `enabled` | boolean | `false` | Enable BQ. Weaviate uses binary quantization (BQ) compression when `true`.

The Python client v4 does not use the `enabled` parameter. To enable BQ with the v4 client, set a `quantizer` in the collection definition. | +| `bq` : `enabled` | boolean | `false` | Enable BQ. Weaviate uses binary quantization (BQ) compression when `true`.

The Python client does not use the `enabled` parameter. To enable BQ with the v4 client, set a `quantizer` in the collection definition. | | `bq` : `rescoreLimit` | integer | -1 | The minimum number of candidates to fetch before rescoring. | | `bq` : `cache` | boolean | `false` | Whether to use the vector cache. | | `vectorCacheMaxObjects` | integer | `1e12` | Maximum number of objects in the memory cache. By default, this limit is set to one trillion (`1e12`) objects when a new collection is created. For sizing recommendations, see [Vector cache considerations](/weaviate/concepts/vector-index#vector-cache-considerations). | diff --git a/_includes/configuration/sq-compression-parameters.mdx b/_includes/configuration/sq-compression-parameters.mdx index 625348cf8..2049e0832 100644 --- a/_includes/configuration/sq-compression-parameters.mdx +++ b/_includes/configuration/sq-compression-parameters.mdx @@ -1,6 +1,6 @@ | Parameter | Type | Default | Details | | :---------------------- | :------ | :------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `sq`: `enabled` | boolean | `false` | Uses SQ when `true`.

The Python client v4 does not use the `enabled` parameter. To enable SQ with the v4 client, set a `quantizer` in the collection definition. | +| `sq`: `enabled` | boolean | `false` | Uses SQ when `true`.

The Python client does not use the `enabled` parameter. To enable SQ with the v4 client, set a `quantizer` in the collection definition. | | `sq`: `rescoreLimit` | integer | -1 | The minimum number of candidates to fetch before rescoring. | | `sq`: `trainingLimit` | integer | 100000 | The size of the training set to determine scalar bucket boundaries. | | `sq`: `cache` | boolean | `false` | Use the vector cache when true. | diff --git a/_includes/how.to.get.object.count.mdx b/_includes/how.to.get.object.count.mdx index 7669e4376..cb125c02a 100644 --- a/_includes/how.to.get.object.count.mdx +++ b/_includes/how.to.get.object.count.mdx @@ -5,43 +5,13 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/graphql.aggregate.simple.py'; - + - - - -```python -import weaviate - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL") # Replace WEAVIATE_INSTANCE_URL with your instance URL - -client.query.aggregate().with_meta_count().do() -``` - - - - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL -}); - -const response = await client.graphql - .aggregate() - .withClassName() - .withFields('meta { count }') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - diff --git a/_includes/schema-delete-class.mdx b/_includes/schema-delete-class.mdx index 1bc679940..db4dd3153 100644 --- a/_includes/schema-delete-class.mdx +++ b/_includes/schema-delete-class.mdx @@ -22,7 +22,7 @@ This code deletes a collection and its objects. ``` */} - + - - -```python -# delete class "Article" - THIS WILL DELETE ALL DATA IN THIS CLASS -client.schema.delete_class("Article") # Replace with your class name -``` - - - - + ```ts // delete collection "Article" - THIS WILL DELETE THE COLLECTION AND ALL ITS DATA @@ -53,17 +44,6 @@ await client.collections.delete('Article') - - -```ts -// delete collection "Article" - THIS WILL DELETE THE COLLECTION AND ALL ITS DATA -await client.schema - .classDeleter() - .withClassName('Article') - .do(); -``` - - diff --git a/_includes/weaviate-embeddings-vectorizer-parameters.mdx b/_includes/weaviate-embeddings-vectorizer-parameters.mdx index 6e79b2027..5b4e5fae2 100644 --- a/_includes/weaviate-embeddings-vectorizer-parameters.mdx +++ b/_includes/weaviate-embeddings-vectorizer-parameters.mdx @@ -16,7 +16,7 @@ import JavaImportQueries from '!!raw-loader!/_includes/code/howto/java/src/test/ The following examples show how to configure Weaviate Embeddings-specific options. - + - + - - -```js -Coming soon -``` - diff --git a/docs/academy/js/standalone/which-search/05_review.mdx b/docs/academy/js/standalone/which-search/05_review.mdx index 30d6672c2..d79753aae 100644 --- a/docs/academy/js/standalone/which-search/05_review.mdx +++ b/docs/academy/js/standalone/which-search/05_review.mdx @@ -17,7 +17,7 @@ These code examples are runnable, with the [`v3` Weaviate Typescript client](../ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -{/* - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL -}); - -const response = await client.graphql - .get() - .withClassName('WikiArticle') - .withFields('title wiki_summary') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - @@ -111,5 +92,5 @@ public class App { } ``` - */} + diff --git a/docs/academy/py/zero_to_mvp/101_hello_weaviate/_snippets/academy.clients.rest.object.get.mdx b/docs/academy/py/zero_to_mvp/101_hello_weaviate/_snippets/academy.clients.rest.object.get.mdx index caf18b19c..db47ee32d 100644 --- a/docs/academy/py/zero_to_mvp/101_hello_weaviate/_snippets/academy.clients.rest.object.get.mdx +++ b/docs/academy/py/zero_to_mvp/101_hello_weaviate/_snippets/academy.clients.rest.object.get.mdx @@ -19,25 +19,6 @@ client = weaviate.Client("http://localhost:8080") print(client.get_meta()) ``` - -{/* - -```js -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace WEAVIATE_INSTANCE_URL with your instance URL -}); - -const response = await client.data - .getterById() - .withClassName('WikiArticle') - .withId('36ddd591-2dee-4e7e-a3cc-eb86d30a4303') - .do(); -console.log(JSON.stringify(response, null, 2)); -``` - @@ -102,5 +83,5 @@ public class App { } ``` - */} + diff --git a/docs/agents/personalization/tutorial-recipe-recommender.mdx b/docs/agents/personalization/tutorial-recipe-recommender.mdx index 976c05f32..c9027b26d 100644 --- a/docs/agents/personalization/tutorial-recipe-recommender.mdx +++ b/docs/agents/personalization/tutorial-recipe-recommender.mdx @@ -113,7 +113,7 @@ import ForcePipInstall from '../_includes/_force_pip_install.mdx'; Now, you can finally connect to your Weaviate Cloud instance with the parameters from the first step: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + - - - - + - - - - - + - - - - + - - - - - + - - - - + - + - + - - - - - + - - - - + - - - - + - - - - + - + - - - @@ -309,7 +299,7 @@ import RaftRFChangeWarning from '/_includes/1-25-replication-factor.mdx'; Configure replication settings, such as [async replication](/deploy/configuration/replication.md#async-replication-settings) and [deletion resolution strategy](/weaviate/concepts/replication-architecture/consistency.md#deletion-resolution-strategies). - + - + - - - ```bash diff --git a/docs/deploy/configuration/replica-movement.mdx b/docs/deploy/configuration/replica-movement.mdx index ea73f3fab..8103d539e 100644 --- a/docs/deploy/configuration/replica-movement.mdx +++ b/docs/deploy/configuration/replica-movement.mdx @@ -20,7 +20,7 @@ import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBl import PyCode from '!!raw-loader!/_includes/code/python/howto.configure.replica.movement.py'; - + - + ```typescript // JS/TS support coming soon @@ -68,7 +68,7 @@ Nodes for shard 'w5OcBGbNvRt4': ['node2', 'node3'] Copy or move a shard replica by specifying the the source node, destination node, collection name, shard ID and operation type (`MOVE` or `COPY`). - + - + ```typescript // JS/TS support coming soon @@ -113,7 +113,7 @@ Replication initiated, ID: 32536c0e-09e1-4ea1-a2c5-e85af10a9d58 Shard replication operations are asynchronous. An operation status can be queried, with an option to view the full operation history. - + - + ```typescript // JS/TS support coming soon @@ -173,7 +173,7 @@ To learn more about the replication states, check out [Concepts: Replication arc List all ongoing and completed operations. This can be filtered by node, collection and shard. - + - + ```typescript // JS/TS support coming soon @@ -219,7 +219,7 @@ Filtered operations for collection 'MyReplicatedDocCollection' on 'node3': 1 The operation will be stopped if possible. If successfully cancelled, its state will change to `CANCELLED`. - + - + ```typescript // JS/TS support coming soon @@ -255,7 +255,7 @@ language="py" Remove a replication operation from the logs. If the operation is active, it will be cancelled first. - + - + ```typescript // JS/TS support coming soon @@ -291,7 +291,7 @@ language="py" Remove all replication operations from the logs. If any operations are active, they will be cancelled first. - + - + ```typescript // JS/TS support coming soon diff --git a/docs/deploy/tutorials/rbac.mdx b/docs/deploy/tutorials/rbac.mdx index 8161d6435..e316cf81b 100644 --- a/docs/deploy/tutorials/rbac.mdx +++ b/docs/deploy/tutorials/rbac.mdx @@ -123,7 +123,7 @@ We will connect to Weaviate with `root-user`, and once we create a new role, we Ensure you are connected to Weaviate with a user possessing sufficient permissions to manage roles. You can achieve this by either using the predefined `root` role during [Weaviate configuration](/deploy/configuration/configuring-rbac.md) or by granting a user the [`manage_roles` permission](/weaviate/configuration/rbac/manage-roles.mdx#role-management-permissions). - + - + - + - + - + - + ```ts // TS support coming soon @@ -231,7 +231,7 @@ First, let's create the new user `custom-user`: Now, you can assign the role `rw_role` to `custom-user`: - + - + - + - + - + - + - + - + ```ts // TS support coming soon @@ -380,7 +380,7 @@ First, let's create the new user `custom-user`: Now, you can assign the role `viewer_role` to `custom-user`: - + - + - + - + - + - + - + - + ```ts // TS support coming soon @@ -531,7 +531,7 @@ First, let's create the new user `custom-user`: Now, you can assign the role `tenant_manager` to `custom-user`: - + - + - + - - - - - - - + - - - - - - - + - - - - - - - + - - - - - - Starting with the Weaviate Python client `v4.16.0`, there are multiple changes to the vectorizer configuration API when creating collections: + - `.vectorizer_config` has been replaced with `.vector_config` - `Configure.NamedVectors` has been replaced with `Configure.Vectors` and `Configure.MultiVectors` -- `Configure.NamedVectors.none` and `Configure.Vectorizer.none` have been replaced with `Configure.Vectors.self_provided` and `Configure.MultiVectors.self_provided` +- `Configure.NamedVectors.none` and `Configure.Vectorizer.none` have been replaced with `Configure.Vectors.self_provided` and `Configure.MultiVectors.self_provided` + +#### Python client `v3` deprecation -#### Migrating from `v3` to `v4` + -If you are migrating from the Python `v3` client to the `v4` client, see this [dedicated guide](./v3_v4_migration.md). +The Weaviate Python client `v3` has been deprecated and should no longer be used. If you need documentation for the `v3` client, see the [documentation archive](https://archive.docs.weaviate.io/weaviate/client-libraries/python/python_v3). If you are migrating from the Python `v3` client to the `v4` client, see this [migration guide](https://archive.docs.weaviate.io/weaviate/client-libraries/python/v3_v4_migration). #### Beta releases diff --git a/docs/weaviate/client-libraries/python/python_v3.md b/docs/weaviate/client-libraries/python/python_v3.md deleted file mode 100644 index ed1d84d5d..000000000 --- a/docs/weaviate/client-libraries/python/python_v3.md +++ /dev/null @@ -1,920 +0,0 @@ ---- -title: "Legacy (v3) API (DEPRECATED)" -sidebar_position: 80 -description: "Deprecated Python v3 client documentation maintained for legacy application compatibility only." -image: og/docs/client-libraries.jpg -# tags: ['python', 'client library'] ---- - -:::caution `v3` client is deprecated -This document relates to the legacy `v3` client and API. -
- -From `v4.10.0`, the [Weaviate Python client installations](https://pypi.org/project/weaviate-client/) no longer include the `v3` API (i.e. the `weaviate.Client` class). This separation helps us to provide the best developer experience for you and provide support for the latest Weaviate features. -
- -The `v3` client will continue to get critical security updates and bugfixes for the foreseeable future, but it will not support any new features. -
- -**What does this mean for me?** -
- -To take advantage of the latest developments on the Weaviate Database, we recommend migrating your codebase to use the [`v4` client API](./index.mdx). -
- -Our documentation includes [a migration guide here](./v3_v4_migration.md), and many code examples include both `v3` and `v4` syntax. We will be adding more dedicated resources for you to ease the migration experience. -
- -If you have an existing codebase and Weaviate Database that you expect to remain static, we recommend pinning the version in your requirements file (e.g. `requirements.txt`), like so: - -```bash - weaviate-client>=3.26.7,<4.0.0 -``` - -We appreciate that code migration can be cumbersome, but we feel strongly that the end experience and feature set will make your time worthwhile. -
- -If you have specific requests for migration documentation or resources, please reach out through [our GitHub repository](https://github.com/weaviate/docs/issues). -::: - -## Installation and setup - -### Requirements - -The `v3` client is not to be used with with the gRPC API that was introduced in Weaviate `1.22`. You can still use Weaviate `1.22` and newer with the `v3` client, however it will not take advantage of improvements made with the gRPC API. For the gRPC API, use the `v4` client. - -### Installation - -The `v3` Python library is available on [PyPI.org](https://pypi.org/project/weaviate-client/). The package can be installed using [pip](https://pypi.org/project/pip/). The client is developed and tested for Python 3.7 and higher. - -```bash -pip install "weaviate-client==3.*" -``` - -### Set-up - -Now you can use the client in your Python scripts as follows: - -```python -import weaviate - -client = weaviate.Client("https://WEAVIATE_INSTANCE_URL") # Replace WEAVIATE_INSTANCE_URL with your instance URL. - -assert client.is_ready() # Will return True if the client is connected & the server is ready to accept requests -``` - -Or, with additional arguments such as those below: - -```python -import weaviate - -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # URL of your Weaviate instance - auth_client_secret=auth_config, # (Optional) If the Weaviate instance requires authentication - timeout_config=(5, 15), # (Optional) Set connection timeout & read timeout time in seconds - additional_headers={ # (Optional) Any additional headers; e.g. keys for API inference services - "X-Cohere-Api-Key": "YOUR-COHERE-API-KEY", # Replace with your Cohere key - "X-HuggingFace-Api-Key": "YOUR-HUGGINGFACE-API-KEY", # Replace with your Hugging Face key - "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY", # Replace with your OpenAI key - } -) - -assert client.is_ready() # Will return True if the client is connected & the server is ready to accept requests -``` - -## Authentication - -import ClientAuthIntro from '/docs/weaviate/client-libraries/_components/client.auth.introduction.mdx' - - - -### WCD authentication - -import ClientAuthWCD from '/docs/weaviate/client-libraries/_components/client.auth.wcs.mdx' - - - -### API key authentication - -:::info Added in Weaviate Python client version `3.14.0`. -::: - -import ClientAuthApiKey from '/docs/weaviate/client-libraries/_components/client.auth.api.key.mdx' - - - -```python -import weaviate - -auth_config = weaviate.auth.AuthApiKey(api_key="YOUR-WEAVIATE-API-KEY") # Replace with your Weaviate instance API key - -# Instantiate the client with the auth config -client = weaviate.Client( - url="https://WEAVIATE_INSTANCE_URL", # Replace with your Weaviate endpoint - auth_client_secret=auth_config -) -``` - -### OIDC authentication - -import ClientAuthOIDCIntro from '/docs/weaviate/client-libraries/_components/client.auth.oidc.introduction.mdx' - - - -#### Resource Owner Password Flow - -import ClientAuthFlowResourceOwnerPassword from '/docs/weaviate/client-libraries/_components/client.auth.flow.resource.owner.password.mdx' - - - -```python -import weaviate - -resource_owner_config = weaviate.AuthClientPassword( - username = "user", - password = "pass", - scope = "offline_access" # optional, depends on the configuration of your identity provider (not required with WCD) - ) - -# Initiate the client with the auth config -client = weaviate.Client("http://localhost:8080", auth_client_secret=resource_owner_config) -``` - -#### Client Credentials flow - -import ClientAuthFlowClientCredentials from '/docs/weaviate/client-libraries/_components/client.auth.flow.client.credentials.mdx' - - - -```python -import weaviate - -client_credentials_config = weaviate.AuthClientCredentials( - client_secret = "client_secret", - scope = "scope1 scope2" # optional, depends on the configuration of your identity provider (not required with WCD) - ) - -# Initiate the client with the auth config -client = weaviate.Client("https://localhost:8080", auth_client_secret=client_credentials_config) -``` - -#### Refresh Token flow - -import ClientAuthBearerToken from '/docs/weaviate/client-libraries/_components/client.auth.bearer.token.mdx' - - - -```python -import weaviate - -bearer_config = weaviate.AuthBearerToken( - access_token="some token" - expires_in=300 # in seconds, by default 60s - refresh_token="other token" # Optional -) - -# Initiate the client with the auth config -client = weaviate.Client("https://localhost:8080", auth_client_secret=bearer_config) -``` - -## Custom headers - -You can pass custom headers to the client, which are added at initialization: - -```python -client = weaviate.Client( - url="https://localhost:8080", - additional_headers={"HeaderKey": "HeaderValue"}, -) -``` - -## Neural Search Frameworks - -There is a variety of neural search frameworks that use Weaviate under the hood to store, search through, and retrieve vectors. - -- deepset's [haystack](https://www.deepset.ai/weaviate-vector-search-engine-integration) -- Jina's [DocArray](https://github.com/docarray/docarray) - -# References documentation - -On this Weaviate documentation website, you will find how to use the Python client for all [RESTful endpoints](/weaviate/api/rest) and [GraphQL functions](/weaviate/api). For each reference, a code block is included with an example of how to use the function with the Python (and other) clients. The Python client, however, has additional functionalities, which are covered in the full client documentation on [weaviate-python-client.readthedocs.io](https://weaviate-python-client.readthedocs.io/en/stable/). Some of these additional functions are highlighted here below. - -### Example: client.schema.create(schema) -Instead of adding classes one by one using the RESTful `v1/schema` endpoint, you can upload a full schema in JSON format at once using the Python client. Use the function `client.schema.create(schema)` as follows: - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -schema = { - "classes": [{ - "class": "Publication", - "description": "A publication with an online source", - "properties": [ - { - "dataType": [ - "text" - ], - "description": "Name of the publication", - "name": "name" - }, - { - "dataType": [ - "Article" - ], - "description": "The articles this publication has", - "name": "hasArticles" - }, - { - "dataType": [ - "geoCoordinates" - ], - "description": "Geo location of the HQ", - "name": "headquartersGeoLocation" - } - ] - }, { - "class": "Article", - "description": "A written text, for example a news article or blog post", - "properties": [ - { - "dataType": [ - "text" - ], - "description": "Title of the article", - "name": "title" - }, - { - "dataType": [ - "text" - ], - "description": "The content of the article", - "name": "content" - } - ] - }, { - "class": "Author", - "description": "The writer of an article", - "properties": [ - { - "dataType": [ - "text" - ], - "description": "Name of the author", - "name": "name" - }, - { - "dataType": [ - "Article" - ], - "description": "Articles this author wrote", - "name": "wroteArticles" - }, - { - "dataType": [ - "Publication" - ], - "description": "The publication this author writes for", - "name": "writesFor" - } - ] - }] -} - -client.schema.create(schema) -``` - -#### Example: Blog Post on How to get started with Weaviate and the Python client - -A full example of how to use the Python client for Weaviate can be found in [this article on Towards Data Science](https://towardsdatascience.com/quickstart-with-weaviate-python-client-e85d14f19e4f). - -## Batching - -Batching is a way of importing/creating `objects` and `references` in bulk using a single API request to the Weaviate server. With Python this can be done using 3 different methods: - -1. ***Auto-batching*** -2. ***Dynamic-batching*** -3. ***Manual-batching*** - -Generally, we recommend use of `client.batch` in a context manager, which will automatically flush the batch when exiting. This is the easiest way to use the batching functionality. - -The following parameters have the greatest impact on the batch import speed: - -| Parameter | Type | Recommended
value | Purpose | -| :- | :- | :- |:- | -| `batch_size` | integer | 50 - 200 | Initial batch size -| `num_workers` | integer | 1 - 2 | Maximum number of parallel workers -| `dynamic` | boolean | True | If true, dynamically adjust the `batch_size`
based on the number of items in the batch - -### Multi-threading batch import - -:::info Added in Weaviate Python client version `3.9.0`. -::: - -Multi-threading Batch import works with both `Auto-batching` and `Dynamic-batching`. - -To use it, set the number of workers (threads) using the `.configure(...)` (same as `.__call__(...)`) by setting the argument `num_workers` in the batch configuration. See also [Batch configuration](#batch-configuration) below. - -:::warning -Multithreading is disabled by default (num_workers=1). Use with care to not overload your Weaviate instance. -::: - -**Example** - -```python -client.batch( # or client.batch.configure( - batch_size=100, - dynamic=True, - num_workers=4, -) -``` - -### Auto-batching - -This method allows the Python client to handle all the `object` and `reference` import/creation. This means that you do NOT have to explicitly import/create objects and cross-references. All you need to do is add everything you want imported/created to the `Batch`, and the `Batch` is going to take care of creating the objects and cross-references among them. To enable auto-batching we need to configure `batch_size` to be a positive integer (by default `None`) (see [Batch configuration](#batch-configuration) below for more information). The `Batch` is going to import/create objects, then create cross-references, if the number of objects + number of references == `batch_size`. See example below: - -```python -import weaviate -from weaviate.util import generate_uuid5 -client = weaviate.Client("http://localhost:8080") - -# create schema -schema = { - "classes": [ - { - "class": "Author", - "properties": [ - { - "name": "name", - "dataType": ["text"] - }, - { - "name": "wroteBooks", - "dataType": ["Book"] - } - ] - }, - { - "class": "Book", - "properties": [ - { - "name": "title", - "dataType": ["text"] - }, - { - "name": "ofAuthor", - "dataType": ["Author"] - } - ] - } - ] -} - -client.schema.create(schema) - -author = { - "name": "Jane Doe", -} -book_1 = { - "title": "Jane's Book 1" -} -book_2 = { - "title": "Jane's Book 2" -} - -client.batch.configure( - batch_size=5, # int value for batch_size enables auto-batching, see Batch configuration section below -) - -with client.batch as batch: - # add author - uuid_author = generate_uuid5(author, "Author") - batch.add_data_object( - data_object=author, - class_name="Author", - uuid=uuid_author, - ) - # add book_1 - uuid_book_1 = generate_uuid5(book_1, "Book") - batch.add_data_object( - data_object=book_1, - class_name="Book", - uuid=uuid_book_1, - ) - # add references author ---> book_1 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_1, - to_object_class_name="Book", - ) - # add references author <--- book_1 - batch.add_reference( - from_object_uuid=uuid_book_1, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) - # add book_2 - uuid_book_2 = generate_uuid5(book_2, "Book") - batch.add_data_object( - data_object=book_2, - class_name="Book", - uuid=uuid_book_2, - ) - # add references author ---> book_2 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_2, - to_object_class_name="Book", - ) - # add references author <--- book_2 - batch.add_reference( - from_object_uuid=uuid_book_2, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) - -# NOTE: When exiting context manager the method `batch.flush()` is called -# done, everything is imported/created -``` - -### Dynamic-batching - -This method allows the Python client to handle all object and cross-reference import/creations in a dynamic manner. This means that the user does NOT have to explicitly import/create objects and cross-reference (same as with [Auto-batching](#auto-batching). To enable dynamic-batching we need to configure `batch_size` to be a positive integer (by default `None`) AND set `dynamic` to `True` (by default `False`) (see [Batch-configuration](#batch-configuration) below for more information). For this method the `Batch` is going to compute the `recommended_num_objects` and `recommended_num_references` after the first `Batch` creation, where the `batch_size` is used for `recommended_num_objects` and `recommended_num_references` as the initial value. The `Batch` is going to import/create objects then references, if current number of objects reached `recommended_num_objects` OR current number of reference reached `recommended_num_references`. See example below: - - -```python -import weaviate -from weaviate.util import generate_uuid5 -client = weaviate.Client("http://localhost:8080") - -# create schema -schema = { - "classes": [ - { - "class": "Author", - "properties": [ - { - "name": "name", - "dataType": ["text"] - }, - { - "name": "wroteBooks", - "dataType": ["Book"] - } - ] - }, - { - "class": "Book", - "properties": [ - { - "name": "title", - "dataType": ["text"] - }, - { - "name": "ofAuthor", - "dataType": ["Author"] - } - ] - } - ] -} - -client.schema.create(schema) - -author = { - "name": "Jane Doe", -} -book_1 = { - "title": "Jane's Book 1" -} -book_2 = { - "title": "Jane's Book 2" -} - -client.batch.configure( - batch_size=5, # int value for batch_size enables auto-batching, see Batch configuration section below - dynamic=True, # makes it dynamic -) - -with client.batch as batch: - # add author - uuid_author = generate_uuid5(author, "Author") - batch.add_data_object( - data_object=author, - class_name="Author", - uuid=uuid_author, - ) - # add book_1 - uuid_book_1 = generate_uuid5(book_1, "Book") - batch.add_data_object( - data_object=book_1, - class_name="Book", - uuid=uuid_book_1, - ) - # add references author ---> book_1 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_1, - to_object_class_name="Book", - ) - # add references author <--- book_1 - batch.add_reference( - from_object_uuid=uuid_book_1, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) - # add book_2 - uuid_book_2 = generate_uuid5(book_2, "Book") - batch.add_data_object( - data_object=book_2, - class_name="Book", - uuid=uuid_book_2, - ) - # add references author ---> book_2 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_2, - to_object_class_name="Book", - ) - # add references author <--- book_2 - batch.add_reference( - from_object_uuid=uuid_book_2, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) -# NOTE: When exiting context manager the method `batch.flush()` is called -# done, everything is imported/created -``` - -### Manual-batching - -This method gives the user total control over the `Batch`, meaning the `Batch` is NOT going to perform any import/creation implicitly but will leave it to the user's discretion. See example below: - - -```python -import weaviate -from weaviate.util import generate_uuid5 -client = weaviate.Client("http://localhost:8080") - -# create schema -schema = { - "classes": [ - { - "class": "Author", - "properties": [ - { - "name": "name", - "dataType": ["text"] - }, - { - "name": "wroteBooks", - "dataType": ["Book"] - } - ] - }, - { - "class": "Book", - "properties": [ - { - "name": "title", - "dataType": ["text"] - }, - { - "name": "ofAuthor", - "dataType": ["Author"] - } - ] - } - ] -} - -client.schema.create(schema) - -author = { - "name": "Jane Doe", -} -book_1 = { - "title": "Jane's Book 1" -} -book_2 = { - "title": "Jane's Book 2" -} - -client.batch.configure( - batch_size=None, # None disable any automatic functionality -) - -with client.batch as batch: - # add author - uuid_author = generate_uuid5(author, "Author") - batch.add_data_object( - data_object=author, - class_name="Author", - uuid=uuid_author, - ) - # add book_1 - uuid_book_1 = generate_uuid5(book_1, "Book") - batch.add_data_object( - data_object=book_1, - class_name="Book", - uuid=uuid_book_1, - ) - result = batch.create_objects() # <----- implicit object creation - - # add references author ---> book_1 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_1, - to_object_class_name="Book", - ) - # add references author <--- book_1 - batch.add_reference( - from_object_uuid=uuid_book_1, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) - result = batch.create_references() # <----- implicit reference creation - - - # add book_2 - uuid_book_2 = generate_uuid5(book_2, "Book") - batch.add_data_object( - data_object=book_2, - class_name="Book", - uuid=uuid_book_2, - ) - result = batch.create_objects() # <----- implicit object creation - - # add references author ---> book_2 - batch.add_reference( - from_object_uuid=uuid_author, - from_object_class_name="Author", - from_property_name="wroteBooks", - to_object_uuid=uuid_book_2, - to_object_class_name="Book", - ) - # add references author <--- book_2 - batch.add_reference( - from_object_uuid=uuid_book_2, - from_object_class_name="Book", - from_property_name="ofAuthor", - to_object_uuid=uuid_author, - to_object_class_name="Author", - ) - result = batch.create_references() # <----- implicit reference creation - -# NOTE: When exiting context manager the method `batch.flush()` is called -# done, everything is imported/created -``` - -### Batch configuration -The `Batch` object can be configured using the `batch.configure()` method or the `batch()` (i.e. call batch object, `__call__`) method. They are the same function. In the examples above we saw that we can configure the `batch_size` and `dynamic` parameters. Here are more available parameters: - -- `batch_size` - (`int` or `None`: default `None`): If it is `int` then auto-/dynamic-batching is enabled. For Auto-batching, if number of objects + number of references == `batch_size` then the `Batch` is going to import/create current objects then references (see [Auto-batching](#auto-batching) for more info). For Dynamic-batching it is used as the initial value for `recommended_num_objects` and `recommended_num_references` (see [Dynamic batching](#dynamic-batching) for more info). A value of `None` means it is Manual-batching—no automatic object/reference import/creation. -- `dynamic` - (`bool`, default: `False`): Enables/disables Dynamic-batching. Does not have any effect if `batch_size` is `None`. -- `creation_time` - (`int` or `float`, default: `10`): It is the interval of time in which the batch import/create should be done. It used to compute `recommended_num_objects` and `recommended_num_references`, consequently has an impact for Dynamic-batching. -- `callback` (Optional[Callable[[dict], None]], default `weaviate.util.check_batch_result`): It is a callback function on the results of the `batch.create_objects()` and `batch.create_references()`. It is used for error handling for Auto-/Dynamic-batching. Has no effect if `batch_size` is `None`. -- `timeout_retries` - (`int`, default `3`): Number of attempts to import/create a batch before resulting in `TimeoutError`. -- `connection_error_retries` - (`int`, default `3`): Number of attempts to import/create a batch before resulting in `ConnectionError`. **NOTE:** Added in `weaviate-client 3.9.0`. -- `num_workers` - (`int`, default `1`): The maximal number of concurrent threads to run batch import. Only used for non-MANUAL batching. i.e. is used only with AUTO or DYNAMIC batching. ***Use with care to not overload your Weaviate instance.*** **NOTE:** Added in `weaviate-client 3.9.0`. - -NOTE: You have to specify all the configurations that you want at each call of this method, otherwise some setting are going to be replaced by default values. -```python -client.batch( - batch_size=100, - dynamic=False, - creation_time=5, - timeout_retries=3, - connection_error_retries=5, - callback=None, - num_workers=1, -) -``` - -### Tips & Tricks - -* There is no limit to how many objects/references one could add to a batch before committing/creating it. However a too large batch can lead to a TimeOut error, which means that Weaviate could not process and create all the objects from the batch in the specified time (the timeout configuration can be set like [this](https://weaviate-python-client.readthedocs.io/en/latest/weaviate.html#weaviate.Client) or [this](https://weaviate-python-client.readthedocs.io/en/latest/weaviate.html#weaviate.Client.timeout_config)). Note that setting a timeout configuration higher that 60s would require some changes to the docker-compose.yml/helm chart file. -* The `batch` class in the Python Client can be used in three ways: - * Case 1: Everything should be done by the user, i.e. the user should add the objects/object-references and create them whenever the user wants. To create one of the data type use these methods of this class: `create_objects`, `create_references` and `flush`. This case has the Batch instance's batch_size set to None (see docs for the `configure` or `__call__` method). Can be used in a context manager, see below. - * Case 2: Batch auto-creates when full. This can be achieved by setting the Batch instance's batch_size set to a positive integer (see docs for the `configure` or `__call__` method). The batch_size in this case corresponds to the sum of added objects and references. This case does not require the user to create the batch/s, but it can be done. Also to create non-full batches (last batches) that do not meet the requirement to be auto-created use the `flush` method. Can be used in a context manager, see below. - * Case 3: Similar to Case II but uses dynamic batching, i.e. auto-creates either objects or references when one of them reached the `recommended_num_objects` or `recommended_num_references` respectively. See docs for the `configure` or `__call__` method for how to enable it. - * **Context-manager support**: Can be use with the with statement. When it exists the context-manager it calls the flush method for you. Can be combined with `configure` or `__call__` method, in order to set it to the desired Case. - -### Error Handling - -Creating objects in `Batch` is faster then creating each object/reference individually but it comes at the cost of skipping some validation steps. Skipping some validation steps at object/reference level can result in some objects that failed to create or some references that could not be added. In this case the `Batch` does not fail but individual objects/references might and we can make sure that everything was imported/created without errors by checking the returned value of the `batch.create_objects()` and `batch.create_references()`. Here are examples how to catch and handle errors on individual `Batch` objects/references. - -Lets define a function that checks for such errors and prints them: -```python -def check_batch_result(results: dict): - """ - Check batch results for errors. - - Parameters - ---------- - results : dict - The Weaviate batch creation return value. - """ - - if results is not None: - for result in results: - if "result" in result and "errors" in result["result"]: - if "error" in result["result"]["errors"]: - print(result["result"]) -``` - -Now we can use this function to print the error messages at item (object/reference) level. Lets look how we can do it using Auto-/Dynamic-batching where we never implicitly call the `create` methods: - -```python -client.batch( - batch_size=100, - dynamic=True, - creation_time=5, - timeout_retries=3, - connection_error_retries=3, - callback=check_batch_result, -) - -# done, easy as that -``` - -For Manual-batching we can call the function on the returned value: -```python -# on objects -result = client.batch.create_object() -check_batch_result(result) - -# on references -result = client.batch.create_references() -check_batch_result(result) -``` - - -
- Example code - -The following Python code can be used to handle errors on individual data objects in the batch. - -```python -import weaviate - -client = weaviate.Client("http://localhost:8080") - -def check_batch_result(results: dict): - """ - Check batch results for errors. - - Parameters - ---------- - results : dict - The Weaviate batch creation return value, i.e. returned value of the client.batch.create_objects(). - """ - if results is not None: - for result in results: - if 'result' in result and 'errors' in result['result']: - if 'error' in result['result']['errors']: - print("We got an error!", result) - -object_to_add = { - "name": "Jane Doe", - "writesFor": [{ - "beacon": "weaviate://localhost/f81bfe5e-16ba-4615-a516-46c2ae2e5a80" - }] -} - -client.batch.configure( - # `batch_size` takes an `int` value to enable auto-batching - # (`None` is used for manual batching) - batch_size=100, - # dynamically update the `batch_size` based on import speed - dynamic=False, - # `timeout_retries` takes an `int` value to retry on time outs - timeout_retries=3, - # checks for batch-item creation errors - # this is the default in weaviate-client >= 3.6.0 - callback=check_batch_result, - consistency_level=weaviate.data.replication.ConsistencyLevel.ALL, # default QUORUM -) - -with client.batch as batch: - batch.add_data_object(object_to_add, "Author", "36ddd591-2dee-4e7e-a3cc-eb86d30a4303", vector=[1,2]) - # lets force an error, adding a second object with unmatching vector dimensions - batch.add_data_object(object_to_add, "Author", "cb7d0da4-ceaa-42d0-a483-282f545deed7", vector=[1,2,3]) -``` - -This can also be applied to adding references in batch. Note that sending batches, especially references, skips some validations at the object and reference level. Adding this validation on single data objects like above makes it less likely for errors to go undiscovered. - -
- - -## Design - -### GraphQL query builder pattern - -For complex GraphQL queries (e.g. with filters), the client uses a builder pattern to form the queries. An example is the following query with multiple filters: - -```python -import weaviate -client = weaviate.Client("http://localhost:8080") - -where_filter = { - "path": ["wordCount"], - "operator": "GreaterThan", - "valueInt": 1000 -} - -near_text_filter = { - "concepts": ["fashion"], - "certainty": 0.7, - "moveAwayFrom": { - "concepts": ["finance"], - "force": 0.45 - }, - "moveTo": { - "concepts": ["haute couture"], - "force": 0.85 - } -} - -query_result = client.query\ - .get("Article", ["title"])\ - .with_where(where_filter)\ - .with_near_text(near_text_filter)\ - .with_limit(50)\ - .do() - -print(query_result) -``` - -Note that you need to use the `.do()` method to execute the query. - -:::tip -You can use `.build()` to inspect the resulting GraphQL query -::: - -```python -query_result = client.query\ - .get("Article", ["title"])\ - .with_where(where_filter)\ - .with_near_text(near_text_filter)\ - .with_limit(50) - -query_result.build() - ->>> '{Get{Article(where: {path: ["wordCount"] operator: GreaterThan valueInt: 1000} limit: 50 nearText: {concepts: ["fashion"] certainty: 0.7 moveTo: {force: 0.85 concepts: ["haute couture"]} moveAwayFrom: {force: 0.45 concepts: ["finance"]}} ){title}}}' - -``` - -## Best practices and notes - -### Thread-safety - -While the Python client is fundamentally designed to be thread-safe, it's important to note that due to its dependency on the `requests` library, complete thread safety isn't guaranteed. - -This is an area that we are looking to improve in the future. - -:::warning Thread safety -The batching algorithm in our client is not thread-safe. Keep this in mind to help ensure smoother, more predictable operations when using our Python client in multi-threaded environments. -::: - -If you are performing batching in a multi-threaded scenario, ensure that only one of the threads is performing the batching workflow at any given time. No two threads can use the same `client.batch` object at one time. - -## Releases - -Go to the [GitHub releases page](https://github.com/weaviate/weaviate-python-client/releases) to see the history of the Python client library releases. - -
- Click here for a table of Weaviate and corresponding client versions - -import ReleaseHistory from '/_includes/release-history.md'; - - - -
- -## Questions and feedback - -import DocsFeedback from '/_includes/docs-feedback.mdx'; - - diff --git a/docs/weaviate/client-libraries/python/v3_v4_migration.md b/docs/weaviate/client-libraries/python/v3_v4_migration.md deleted file mode 100644 index 661296c3e..000000000 --- a/docs/weaviate/client-libraries/python/v3_v4_migration.md +++ /dev/null @@ -1,276 +0,0 @@ ---- -title: Migrate from v3 to v4 -sidebar_position: 50 -description: "Migration guide for upgrading Python applications from deprecated v3 to current v4 client library." -image: og/docs/client-libraries.jpg -# tags: ['python', 'client library'] ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; -import PythonCode from '!!raw-loader!/_includes/code/client-libraries/python_v4.py'; - -:::note Python client version -The current Python client version is `v||site.python_client_version||` -::: - -The `v4` Weaviate Python client API is a complete rewrite, aimed at an improved overall user experience. It is therefore also very different to the `v3` API, and will require re-learning of changed patterns in the way you interact with Weaviate. - -While this may introduce some overhead, we believe the `v4` API is a significant improvement to your developer experience. For instance, using the `v4` client will allow you to take full advantage faster speeds through the gRPC API, and additional static analysis for IDE assistance through strong typing. - -Due to the extensive API surface changes, this guide does not cover every change. Instead, this guide is designed to help you understand the major changes and how to migrate your code at a high level. - -For code examples, refer to the documentation throughout the site, [starting with these suggested sections](#how-to-migrate-your-code). - -## Installation - -To go from `v3` to `v4`, you must - -1. Upgrade the client library: - - ```bash - pip install -U weaviate-client - ``` - -2. Upgrade Weaviate to a compatible version. Each minor Python client version is closely tied to a minor Weaviate version. - - For example, Weaviate `v1.27.x` were developed together with `v4.9.x` of the Python client. - - Generally, we recommend you use the latest versions of Weaviate and the client. You can find the version compatibility matrix in the [release notes](../../release-notes/index.md#weaviate-database-and-client-releases) - -3. Make sure a port for gRPC is open to Weaviate. - - The default port is 50051. - -
- docker-compose.yml example - - If you are running Weaviate with Docker, you can map the default port (`50051`) by adding the following to your `docker-compose.yml` file: - - ```yaml - ports: - - 8080:8080 - - 50051:50051 - ``` - -
- -## Instantiate a client - -The `v4` client is instantiated by the `WeaviateClient` object. The `WeaviateClient` object is the main entry point for all API operations. - -You can instantiate the `WeaviateClient` object directly. However, in most cases it is easier to use a connection helper function such as `connect_to_local` or `connect_to_weaviate_cloud`. - - - - - - - - - - - - - - - - - - - - - - - - - - - -## Major changes - -The `v4` client API is very different from the `v3` API. Major user-facing changes in the `v4` client include: - -- Extensive use of helper classes -- Interaction with collections -- Removal of builder patterns - -### Helper classes - -The `v4` client makes extensive use of helper classes. These classes provide strong typing and thus static type checking. It also makes coding easier through your IDE's auto-completion feature. - -When you are coding, check the auto-complete frequently. It provides useful guidance for API changes and client options. - -import QuickStartCode from '!!raw-loader!/_includes/code/graphql.filters.nearText.generic.py'; - - - - - - - - - - - - - - -The `wvc` namespace exposes commonly used classes in the `v4` API. The namespace is divided further into submodules based on their primary purpose. - - - -### Interact with collections - -When you connect to a Weaviate Database, the v4 API returns a `WeaviateClient` object, while the v3 API returns a `Client` object. - -The `v3` API's interactions were built around the `client` object (an instance of `Client`). This includes server interactions for CRUD and search operations. - -In the `v4` API, the main starting points for your interaction with Weaviate follow a different paradigm. - -Server-level interactions such as checking readiness (`client.is_ready()`) or getting node statuses (`client.cluster.nodes()`) still remain with `client` (now an instance of `WeaviateClient`). - -CRUD and search operations are now performed against a `Collection` object to reflect that these operations target a particular collection. - -This example below shows a function with a `Collection` typing hint). - - - -The collection object includes its name as an attribute. Accordingly, operations such as a `near_text` query can be performed without specifying the collection name. The `v4` collection object has a more focussed namespace in comparison to the breadth of operations available with the `v3` client object. This simplifies your code and reduces the potential for errors. - -import ManageDataCode from '!!raw-loader!/_includes/code/howto/manage-data.read.py'; -import ManageDataCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.read-v3.py'; - - - - - - - - - - - -### Terminology changes (e.g. class -> collection) - -Some of the terms within the Weaviate ecosystem are changing, and the client has changed accordingly: - -- A Weaviate "Class" is now called a "Collection". A collection stores a set of data objects together with their vector embeddings. -- A "Schema" is now called a "Collection Configuration", a set of settings that define collection name, vectorizers, index configurations, property definitions, and so on. - -Due to the architectural changes as well as changes to the terminology, most of the API has been changed. Expect to find differences in the way you interact with Weaviate. - -For example, `client.collections.list_all()` is the replacement for `client.schema.get()`. - -[Manage collections](../../manage-collections/index.mdx) has more details and additional sample code for working with collections. See [searches](../../search/index.mdx) for further details on various queries and filters. - -### Collection creation from JSON - -You can still create a collection from a JSON definition. This may be a useful way to migrate your existing data, for example. You could [fetch an existing definition](../../manage-collections/collection-operations.mdx#read-a-single-collection-definition) and then use it to create a new collection. - - - -### Removal of builder patterns - -The builder patterns for constructing queries have been removed. Builder patterns could be confusing, and led to runtime errors that could not be picked up with static analysis. - -Instead, construct queries in the `v4` API using specific methods and its parameters. - -import SearchSimilarityCode from '!!raw-loader!/_includes/code/howto/search.similarity.py'; -import SearchSimilarityCodeV3 from '!!raw-loader!/_includes/code/howto/search.similarity-v3.py'; - - - - - - - - - - - -Additionally, many arguments are now constructed using helper classes (e.g. `MetadataQuery` or `Filter`) which makes it easier to use and reduces errors through IDE assistance and static analysis. - -## How to migrate your code - -The migration will likely involve significant changes to your codebase. Review the [Python client library documentation](./index.mdx) to get started, including instantiation details and various submodules. - -Then, take a look at the how-to guides for [Managing collections](../../manage-collections/index.mdx) and [Queries](../../search/index.mdx). - -In particular, check out the pages for: - -- [Manage collections](../../manage-collections/index.mdx), -- [Batch import](../../manage-objects/import.mdx) -- [Cross-reference](../../manage-collections/cross-references.mdx) -- [Basic search](../../search/basics.md) -- [Similarity search](../../search/similarity.md) -- [Filters](../../search/filters.md) - -## Questions and feedback - -import DocsFeedback from '/_includes/docs-feedback.mdx'; - - diff --git a/docs/weaviate/client-libraries/typescript/index.mdx b/docs/weaviate/client-libraries/typescript/index.mdx index 94b4815e1..d2c793200 100644 --- a/docs/weaviate/client-libraries/typescript/index.mdx +++ b/docs/weaviate/client-libraries/typescript/index.mdx @@ -125,7 +125,6 @@ All client v3 methods, with the exception of `collection.use()`, use ES6 Promise When there is an asynchronous code error, a promise returns the specific error message. If you use `async` and `await`, a rejected promises acts like a thrown exception - ## Releases Go to the [GitHub releases page](https://github.com/weaviate/typescript-client/releases) to see the history of the TypeScript client library releases and change logs. @@ -139,16 +138,19 @@ import ReleaseHistory from "/_includes/release-history.md"; -#### Vectorizer API changes `v3.8.0` +#### Vectorizer API changes `v3.8.0` Starting with the Weaviate JS/TS client `v3.8.0`, there are multiple changes to the vectorizer configuration API when creating collections: + - `configure.vectorizer` has been replaced with `configure.vectors` -- `configure.multiVectors` has been added to enable users work with [Multi-vectors](../../manage-collections/vector-config.mdx#define-multi-vector-embeddings-eg-colbert-colpali) -- `configure.vectorizer.none` have been replaced with `configure.vectors.selfProvided` +- `configure.multiVectors` has been added to enable users work with [Multi-vectors](../../manage-collections/vector-config.mdx#define-multi-vector-embeddings-eg-colbert-colpali) +- `configure.vectorizer.none` have been replaced with `configure.vectors.selfProvided` + +#### JavaScript/TypeScript client `v2` deprecation -#### Migrating from `v2` to `v3` + -If you are migrating a project from the Weaviate TypeScript client v2 to the v3 client, see the [migration page](/weaviate/client-libraries/typescript/v2_v3_migration) for additional details. +The Weaviate JavaScript/TypeScript client `v2` has been deprecated and should no longer be used. If you need documentation for the `v2` client, see the [documentation archive](https://archive.docs.weaviate.io/weaviate/client-libraries/typescript/typescript-v2). If you are migrating from the JavaScript/TypeScript `v2` client to the `v3` client, see this [migration guide](https://archive.docs.weaviate.io/weaviate/client-libraries/typescript/v2_v3_migration). ## Code examples & further resources diff --git a/docs/weaviate/client-libraries/typescript/typescript-v2.mdx b/docs/weaviate/client-libraries/typescript/typescript-v2.mdx deleted file mode 100644 index a40be08df..000000000 --- a/docs/weaviate/client-libraries/typescript/typescript-v2.mdx +++ /dev/null @@ -1,440 +0,0 @@ ---- -title: JS/TS client v2 -sidebar_position: 20 -description: "Legacy TypeScript client v2 documentation for maintaining existing applications and compatibility." -image: og/docs/client-libraries.jpg -# tags: ['TypeScript', 'client library'] ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -:::note TypeScript client version -The TypeScript client is version `v||site.typescript_client_version||`. Use the [TypeScript v3 client](./index.mdx) for new projects. -::: - -The TypeScript client can be used for both JavaScript and TypeScript scripts. - -## Installation and setup - -To install the TypeScript client library package, use [npm](https://www.npmjs.com/). - -```bash -npm install weaviate-ts-client -``` - -## Usage and type definitions - -Once installed, you can use the client in your TypeScript and JavaScript scripts, as shown in the following examples. - -### Usage - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -client - .schema - .getter() - .do() - .then(res => { - console.log(res); - }) - .catch(err => { - console.error(err) - }); -``` - - - - -```ts -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your Weaviate endpoint -}); - -const response = await client - .schema - .getter() - .do(); -console.log(response); -``` - - - - -:::tip Troubleshooting imports with TypeScript -If you are having any issues with the import statement in TypeScript (e.g. if `weaviate` is `undefined`), try adding `"esModuleInterop": true` to your `"compilerOptions"` in `tsconfig.json`. -::: - -### Type definitions - -The type definitions can be found under the `types` subdirectory of the package in the `*.d.ts` files, for example as shown on the [npm package page](https://www.npmjs.com/package/weaviate-ts-client?activeTab=code). - -## Authentication - -import ClientAuthIntro from '/docs/weaviate/client-libraries/_components/client.auth.introduction.mdx' - - - - -### API key authentication - -import ClientAuthApiKey from '/docs/weaviate/client-libraries/_components/client.auth.api.key.mdx' - - - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -// Instantiate the client with the auth config -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', // Replace with your Weaviate endpoint - apiKey: new weaviate.ApiKey('learn-weaviate'), // Replace with your Weaviate instance API key -}); -``` - - - - -```ts -import weaviate, { WeaviateClient, ApiKey } from 'weaviate-ts-client'; - -// Instantiate the client with the auth config -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', // Replace with your Weaviate endpoint - apiKey: new ApiKey('learn-weaviate'), // Replace with your Weaviate instance API key -}); -``` - - - - -### OIDC authentication - -import ClientAuthOIDCIntro from '/docs/weaviate/client-libraries/_components/client.auth.oidc.introduction.mdx' - - - -:::info Background refresh processes with TS -When using OIDC with the TypeScript client, its background token refresh process can block a script from exiting. If this behavior is not desired, you can: -1. Set the `silentRefresh` parameter as `false` in the OIDC configuration. Or, -1. Stop the process via `client.oidcAuth?.stopTokenRefresh()`, e.g. when a script is expected to exit, or token refresh is no longer needed. -::: - -#### Resource Owner Password Flow - -import ClientAuthFlowResourceOwnerPassword from '/docs/weaviate/client-libraries/_components/client.auth.flow.resource.owner.password.mdx' - - - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new weaviate.AuthUserPasswordCredentials({ - username: 'user123', - password: 'password', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - scopes: ['offline_access'] // optional, depends on the configuration of your identity provider (not required with WCD) - }) -}); -``` - - - - -```ts -import weaviate, { WeaviateClient, AuthUserPasswordCredentials } from 'weaviate-ts-client'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new AuthUserPasswordCredentials({ - username: 'user123', - password: 'password', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - scopes: ['offline_access'] // optional, depends on the configuration of your identity provider (not required with WCD) - }) -}); -``` - - - - -#### Client Credentials flow - -import ClientAuthFlowClientCredentials from '/docs/weaviate/client-libraries/_components/client.auth.flow.client.credentials.mdx' - - - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new weaviate.AuthClientCredentials({ - clientSecret: 'supersecuresecret', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - scopes: ['scope1', 'scope2'] // optional, depends on the configuration of your identity provider - }) -}); -``` - - - - -```ts -import weaviate, { WeaviateClient, AuthClientCredentials } from 'weaviate-ts-client'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new AuthClientCredentials({ - clientSecret: 'supersecuresecret', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - scopes: ['scope1', 'scope2'] // optional, depends on the configuration of your identity provider - }) -}); -``` - - - - -#### Refresh Token flow - -import ClientAuthBearerToken from '/docs/weaviate/client-libraries/_components/client.auth.bearer.token.mdx' - - - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new weaviate.AuthAccessTokenCredentials({ - accessToken: 'abcd1234', - expiresIn: 900, - refreshToken: 'efgh5678', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - }) -}); -``` - - - - -```ts -import weaviate, { WeaviateClient, AuthAccessTokenCredentials } from 'weaviate-ts-client'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - authClientSecret: new AuthAccessTokenCredentials({ - accessToken: 'abcd1234', - expiresIn: 900, - refreshToken: 'efgh5678', - silentRefresh: true, // Default: true - if false, you must refresh the token manually; if true, this background process will prevent a script from exiting. - }) -}); -``` - - - - -## Custom headers - -You can pass custom headers to the client, which are added at initialization: - - - - -```js -const { default: weaviate } = require('weaviate-ts-client'); - -const client = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - headers: { headerName: 'HeaderValue' } -}); -``` - - - - -```ts -import weaviate, { WeaviateClient } from 'weaviate-ts-client'; - -const client: WeaviateClient = weaviate.client({ - scheme: 'https', - host: 'WEAVIATE_INSTANCE_URL', // Replace with your instance URL - headers: { headerName: 'HeaderValue' } -}); -``` - - - - -These headers will then be included in every request that the client makes. - -## References - -:::note JS to TS migration -Some older code examples are written in JavaScript and have not been updated yet. Newer code examples use TypeScript. -::: - -Our [RESTful endpoints](/weaviate/api/rest) and [GraphQL functions](/weaviate/api) covered by the TypeScript client currently have JavaScript examples in the code blocks. - -## Design - -### Builder pattern - -The TypeScript client is designed following the [Builder pattern](https://en.wikipedia.org/wiki/Builder_pattern). The pattern is used to build complex query objects. This means that calls (for example to retrieve data with a RESTful GET request, or using a more complex GraphQL query) are built with chained objects to reduce complexity. Some builder objects are optional, others are required to perform specific functions. Builder examples can be found in the [RESTful API reference pages](/weaviate/api/rest) and the [GraphQL reference pages](/weaviate/api). - -The code snippet at the top of this page shows a simple query corresponding to the RESTful request `GET /v1/schema`. The client is initialized by requiring the package and connecting to a local instance. Then, a query is constructed by getting the `.schema` with `.getter()`. The query will be sent with the `.do()` call. `do()` is required for every function you want to build and execute. - -### General notes -- All methods use ES6 Promises to deal with asynchronous code, so you need to use `.then()` after function calls, or have `async`/`await` support. -- In the case of an error, the Promise rejects with the specific error message. (If using `async`/`await`, a rejected promises acts like a thrown exception). -- Internally the client uses `isomorphic-fetch` to make the REST calls, so it should work from both the browser and NodeJS applications without any required changes. - -## TypeScript for JavaScript users - -TypeScript is a superset of JavaScript. There are, however, some differences that you should be aware of. This section offers some suggestions for JavaScript users who are new to TypeScript. - -### Run a TypeScript file - -To run a TypeScript file, first convert it to JavaScript. The `typescript` package from `npm` includes the `tsc` utility. Use `tsc` to convert (transpile) the TypeScript file. - -Install the `typescript` package. Add the `-g` flag if you want the package to be available globally. - -```bash -npm install typescript -``` - -Some packages, like the Weaviate TypeScript client, require extra configuration. The root directory of a TypeScript project has a `tsconfig.json` file. Add the following to your `tsconfig.json`. - -- Compiler options - - - `"target": "esnext"` - - `"module": "esnext"` - - `"moduleResolution": "node"` - -- `"include": ["*.ts"]` (Or specific files) -- `"lib": [ "es2018" ]` - -Don't specify filenames on the command line when you use `tsconfig.json`. Specify the TypeScript files in `tsconfig.json` instead. `tsc` only reads `tsconfig.json` when you run it by itself. - -```bash -tsc -``` - -`node` only allows the `import` statement in modules. To allow the `import` statement, add the following to your `package.json` file. - -```json -{ - "type": "module" -} -``` - -### Example - -To run this example, complete these steps. - -- Install the `typescript` package. -- Update the `tsconfig.json` and `package.json` files as described above. -- Copy the sample code. -- Save the code as `sample.ts` in the same directory as `tsconfig.json` and `package.json`. -- Convert and run the code. - -Use this code to create `sample.ts`. - -
- Sample TypeScript code - -```ts -import weaviate from 'weaviate-ts-client'; - -const client = weaviate.client({ - scheme: 'https', - host: 'edu-demo.weaviate.network', - apiKey: new weaviate.ApiKey('learn-weaviate'), -}); - -console.log(client.misc) -``` -
- -Convert `sample.ts`. - -```bash -tsc -``` - -Run the converted file. - -```bash -node sample.js -``` - -The output looks like this. - -
- Sample output - -```json -{ - "clientId": "wcs", - "href": "https://auth.wcs.api.weaviate.io/auth/realms/SeMI/.well-known/openid-configuration" -} -``` -
- -## Client releases - -
- Click here for a table of Weaviate and corresponding client versions - -import ReleaseHistory from '/_includes/release-history.md'; - - - -
- -## Client change logs - -The client [change logs](https://github.com/weaviate/typescript-client/releases) for each release are available on GitHub. - -## Questions and feedback - -import DocsFeedback from '/_includes/docs-feedback.mdx'; - - diff --git a/docs/weaviate/client-libraries/typescript/v2_v3_migration.mdx b/docs/weaviate/client-libraries/typescript/v2_v3_migration.mdx deleted file mode 100644 index 93a01d5ce..000000000 --- a/docs/weaviate/client-libraries/typescript/v2_v3_migration.mdx +++ /dev/null @@ -1,457 +0,0 @@ ---- -title: Migrate from v2 to v3 -sidebar_position: 70 -description: "Upgrade guide for migrating TypeScript applications from v2 to current v3 client library version." -image: og/docs/client-libraries.jpg -# tags: ['typescript', 'client library'] ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; -import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; -import TSv2Code from '!!raw-loader!/_includes/code/client-libraries/migrate-ts2.ts'; -import TSv3Code from '!!raw-loader!/_includes/code/client-libraries/migrate-ts3.ts'; -import TSv3Additional from '!!raw-loader!/_includes/code/client-libraries/migrate-additional-ts3.ts'; -import TSv2Additional from '!!raw-loader!/_includes/code/client-libraries/migrate-additional-ts2.ts'; - -import TSClientIntro from '/_includes/clients/ts-client-intro.mdx'; - - - -## Install - -To install the TypeScript client v3, follow these steps: - -1. **Update Node.js** - - The v3 client requires `Node v18` or higher. - -1. **Install the new client package** - - ```bash - npm install weaviate-client - ``` - -1. **Upgrade Weaviate** - - The v3 client requires Weaviate Database `1.23.7` or higher. Whenever possible, use the latest versions of Weaviate Database and the Weaviate client. - -1. **Open a gRPC port** - - The default gRPC port is 50051. - -
- docker-compose.yml - - To map the Weaviate gRPC port in your Docker container to a local port, add this code to your `docker-compose.yml` file: - - ```yaml - ports: - - 8080:8080 - - 50051:50051 - ``` -
- -## Instantiate a client - -The weaviate object is the main entry point for all API operations. The v3 client instantiates the weaviate object and [creates a connection](/weaviate/connections) to your Weaviate instance. - -In most cases, you should use one of the connection helper functions to connect to your Weaviate instance: - -- `connectToWCD` -- `connectToLocal` -- `connectToCustom` - -You can also use a custom configuration to instantiate the client directly: - - - - - - - - - - - - - -## Changes in v3 - -This section highlights some features of the v3 TypeScript client. - -### Design philosophy - -The v3 client interacts with collections as the primary way to work with objects in your Weaviate database. - -Your application code creates an object that represents a collection. This object enables search and CRUD operations to be performed against it. - -This example returns objects from the `JeopardyQuestion` collection. - -```js -const myCollection = client.collections.use('JeopardyQuestion'); - -const result = await myCollection.query.fetchObjects() - -console.log(JSON.stringify(result, null, 2)); -``` - -### Node support only - -The gRPC protocol is fast and provides other internal benefits. Unfortunately, gRPC does not support browser-based client development. - -The v3 client uses gRPC to connect to your Weaviate instance. The client supports Node.js, server-based development. It does not support browser-based web client development. - -To develop a browser-based application, use the [v2 client](/weaviate/client-libraries/typescript/typescript-v2). - -### Work with collections - -The v2 client uses the `client` object for CRUD and search operations. In the v3 client, the `collection` object replaces the `client` object. - -After you create a connection, you do not have to specify the collection for each operation. This helps to reduce errors. - - - - - - - - - - -The collection object can be re-used throughout the codebase. - -### Builder Pattern is removed - -The v2 client uses builder patterns to construct queries. Builder patterns can be confusing and can lead to invalid queries. - -The v3 client doesn't use the builder pattern. The v3 client uses specific methods and method parameters instead. - - - - - - - - - - -### Batch Inserts - -The `insertMany()` method replaces `objectBatcher()` to make batch insertions easier. - -For inserts of over 5000 objects, use `insertMany()` as part of a batch process. - -For more information on batch processing, see [Batch Inserts](../../manage-objects/import.mdx). - - - - - - - - - - -### Client Close Method - -import TSClientClose from '/_includes/clients/ts-client-close.mdx'; - - - -### Filter data - -The `Filter` helper class makes it easier to use filters with conditions. The v3 client streamlines how you use `Filter` so your code is cleaner and more concise. - - - - - - - - - - -### Generate Namespace - -The v3 client adds a new namespace, `generate` for generative queries. This makes it easier to distinguish between generative queries and vector searches. - - - - - - - - - - -### Return object - -The new client has a cleaner return object. It is easier to access important information like object UUIDs, object metadata, and generative query results. - - - - - - - - - - -## Code comparison - -These samples compare v2 client code and v3 client code. - -The comparison samples omit sections of the code that are the same for both clients. The complete v2 and v3 client scripts are [here](#sample-scripts). - -### Imports - - - - - - - - - - -### Connect to Weaviate Cloud - - - - - - - - - - -### Create a collection - - - - - - - - - - -### Batch insert - - - - - - - - - - -### Query your data - - - - - - - - - - -### Delete a collection - - - - - - - - - - - -### Sample scripts - -These scripts are complete versions of the client comparison code from this section. - - - - - - - - - - -For more code examples, see the following: - -- [Search](/weaviate/search) -- [Collection management](/weaviate/manage-collections) -- [Connect to Weaviate](/weaviate/connections) - -## How to migrate your code - -To update v2 client code to v3, follow these steps: - -1. Install the [v3 client package](https://www.npmjs.com/package/weaviate-client). -1. Edit your v2 code to [import](/weaviate/client-libraries/typescript#import-the-client) the v3 client package. -1. Edit your v2 [client instantiation](/weaviate/client-libraries/typescript) code. -1. Edit your code to reflect the [collection first](#design-philosophy) client orientation. - -Continue to update the v2 code until all of the old code is replace with the v3 equivalent. - -## Client change logs - -The client [change logs](https://github.com/weaviate/typescript-client/releases) for each release are available on GitHub. - -## Questions and feedback - -import DocsFeedback from '/_includes/docs-feedback.mdx'; - - diff --git a/docs/weaviate/config-refs/collections.mdx b/docs/weaviate/config-refs/collections.mdx index 4f31457fd..c681e793a 100644 --- a/docs/weaviate/config-refs/collections.mdx +++ b/docs/weaviate/config-refs/collections.mdx @@ -112,7 +112,7 @@ An example of a complete collection object including properties: This code example shows how to configure the collection parameters through a client library: - + - - + - + - + - - - - + - - - @@ -129,7 +111,7 @@ Follow these steps to manually enable PQ. [Create a collection](../../manage-collections/collection-operations.mdx#create-a-collection) without specifying a quantizer. - + - - - - + - - - - + - - - - + - - - To review the current `pq` configuration, you can retrieve it as shown below. - + - - - - + - - - - + - + - + - + - + - + - - - - + - + - - - - + - + - + - + - + - + ```typescript // TS/JS support coming soon @@ -174,7 +174,7 @@ This example creates a role called `testRole` with permissions to: - Create, read, update and delete all collections starting with `TargetCollection`. - + - + - + - + - + - + - + - + - + - + - + - + - + - + ```typescript // TS/JS support coming soon @@ -449,7 +449,7 @@ This example creates a role called `testRole` with permissions to: - Create, read, update and delete replica movement operations for collections starting with `TargetCollection` and shards starting with `TargetShard`. - + - + ```typescript // TS/JS support coming soon @@ -489,7 +489,7 @@ This example grants additional permissions to the role `testRole` to: - **Create new data** in collections that start with `TargetCollection` - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - - - - - - ## Questions and feedback diff --git a/docs/weaviate/connections/connect-local.mdx b/docs/weaviate/connections/connect-local.mdx index e4314451c..b845077ae 100644 --- a/docs/weaviate/connections/connect-local.mdx +++ b/docs/weaviate/connections/connect-local.mdx @@ -13,10 +13,8 @@ import WCSWithoutAuthentication from '/_includes/code/wcs.without.authentication import WCSAuthenticationApiKey from '/_includes/code/wcs.authentication.api.key.mdx'; import WCDAuthAndInferenceKeys from '/_includes/code/wcs.authentication.api.key.with.inference.key.mdx'; -import PyCodeV3 from '!!raw-loader!/_includes/code/connections/connect-python-v3.py'; import PyCodeV4 from '!!raw-loader!/_includes/code/connections/connect-python-v4.py'; import TsCodeV3 from '!!raw-loader!/_includes/code/connections/connect-ts-v3.ts'; -import TsCodeV2 from '!!raw-loader!/_includes/code/connections/connect-ts-v2.ts'; import JavaCode from '!!raw-loader!/_includes/code/connections/connect.java'; import ShellCode from '!!raw-loader!/_includes/code/connections/connect.sh'; import GoCode from '!!raw-loader!/_includes/code/connections/connect.go'; @@ -34,7 +32,7 @@ If your instance runs on Kubernetes, see the `host` and `port` values in your He To connect to a local instance without authentication, follow these examples. - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - @@ -112,7 +86,7 @@ It is also possible to add a cross-reference property to an existing collection Specify a cross-reference when creating an object. - + - - - - + - - - @@ -155,7 +113,7 @@ Specify a cross-reference when creating an object. Specify the required id and properties for the source and the target. - + - - - - + - - - - + - - - - + - - - Create the `JeopardyQuestion` collection including the reference property to `JeopardyCategory`: - + - - - - + - - - Modify `JeopardyCategory` to add the reference to `JeopardyQuestion`: - + - - - - + - - - And add the cross-references: - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - -

- The migrate_data_from_weaviate_to_weaviate function is called to migrate the data. -

-

- -
- + - + - - - - + - + - - - - + - + - -

- The migrate_data_from_weaviate_to_weaviate function is called to migrate the data. -

-

- -
- + - + - - - - + - + - -

- The migrate_data_from_weaviate_to_weaviate function is called to migrate the data. -

-

- -
- + - + - - - - + - + - - - - + - + - -

- The migrate_data_from_weaviate_to_weaviate function is called to migrate the data. -

-

- -
- + - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - - - - - + - - - - + - - - - - + - - - - + - + - + - + - + - - - - - + - - - - + - + - + - - - - - + - - - - + - - - - - + - - - - + - - - - - + - - - - + - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - ## Create an object with a specified ID @@ -211,7 +161,7 @@ If no ID is provided, Weaviate will generate a random [UUID](https://en.wikipedi ::: - + - - - - + - - - - + - - - - + - - - @@ -347,14 +265,12 @@ import CrossReferencePerformanceNote from '/_includes/cross-reference-performanc import XrefPyCode from '!!raw-loader!/_includes/code/howto/manage-data.cross-refs.py'; -import XrefPyCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.cross-refs-v3.py'; import XrefTSCode from '!!raw-loader!/_includes/code/howto/manage-data.cross-refs'; -import XrefTSCodeLegacy from '!!raw-loader!/_includes/code/howto/manage-data.cross-refs-v2'; You can create an object with cross-references to other objects. - + - - - - + - - - :::tip Additional information @@ -412,7 +312,7 @@ import CreateWithGeo from '/_includes/code/howto/manage-data.create.with.geo.mdx Before you create an object, you can validate it against the collection definition. - + - - - + - - - + - - - - + - - - - - - --> @@ -127,7 +102,7 @@ You can handle errors as follows: To delete objects that match a set of criteria, specify the collection and a [`where` filter](../search/similarity.md). - + - - - - + - - - - + - - - - + - - -```js -await client.batch - .objectsBatchDeleter() - .withClassName('EphemeralObject') - .withWhere({ - path: ['name'], - // highlight-start - operator: 'ContainsAny', - valueTextArray: ['asia', 'europe'], // Note the array syntax - // highlight-end - }) - // highlight-end - .do(); -``` - - @@ -301,7 +234,7 @@ The default `QUERY_MAXIMUM_RESULTS` value is 10,000. This may be configurable, e - + - - - - + - - -```js -await client.batch - .objectsBatchDeleter() - .withClassName('EphemeralObject') - .withWhere({ - path: ['id'], - // highlight-start - operator: 'ContainsAny', - valueTextArray: ['12c88739-7a4e-49fd-bf53-d6a829ba0261', '3022b8be-a6dd-4ef4-b213-821f65cee53b', '30de68c1-dd53-4bed-86ea-915f34faea63'], // Note the array syntax - // highlight-end - }) - // highlight-end - .do(); -``` - - @@ -391,7 +298,7 @@ Objects must belong to a collection in Weaviate. Accordingly [deleting collectio - Set `output` to `'verbose'` to see more details (ID and deletion status) for each deletion. - + - - - - + - - - - + - - - - + - - - - + @@ -117,7 +99,7 @@ The Python client uses gRPC by default.
The legacy Python client does not support gRPC.
- + The TypeScript client v3 uses gRPC by default. @@ -185,7 +167,7 @@ Weaviate generates an UUID for each object. Object IDs must be unique. If you se - `generateUuid5` (TypeScript) - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - @@ -351,7 +285,7 @@ When you create an object, you can specify named vectors (if [configured in your You can batch create links from an object to another other object through cross-references. - + - - - - - - ## Python-specific considerations @@ -382,7 +300,7 @@ You can batch create links from an object to another other object through cross- The Python clients have built-in batching methods to help you optimize import speed. For details, see the client documentation: -- [Python client `v4`](../client-libraries/python/index.mdx) +- [Python client](../client-libraries/python/notes-best-practices.mdx) ### Async Python client and batching @@ -422,7 +340,7 @@ To try the example code, download the sample data and create the sample input fi Stream JSON files example code - + - - - Stream CSV files example code - + - - - - + - + - - - - + - - - - + - - - - + - - - ## Read all objects - Multi-tenant collections @@ -138,7 +104,7 @@ For classes where [multi-tenancy](../concepts/data.md#multi-tenancy) is enabled, - + - - - - + - - - ## Related pages diff --git a/docs/weaviate/manage-objects/read.mdx b/docs/weaviate/manage-objects/read.mdx index 96d893a97..5f8eaf95a 100644 --- a/docs/weaviate/manage-objects/read.mdx +++ b/docs/weaviate/manage-objects/read.mdx @@ -8,9 +8,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.read.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.read-v3.py'; import TSCode from '!!raw-loader!/_includes/code/howto/manage-data.read.ts'; -import TSCodeLegacy from '!!raw-loader!/_includes/code/howto/manage-data.read-v2.ts'; import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/manage-data.read.java'; import GoCode from '!!raw-loader!/_includes/code/howto/go/docs/manage-data.read_test.go'; import SkipLink from '/src/components/SkipValidationLink' @@ -30,7 +28,7 @@ import RestObjectsCRUDClassnameNote from '/_includes/rest-objects-crud-classname Use an ID to retrieve an object. If the id doesn't exist, Weaviate returns a 404 error. - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - diff --git a/docs/weaviate/manage-objects/update.mdx b/docs/weaviate/manage-objects/update.mdx index 40e941630..a86476fd4 100644 --- a/docs/weaviate/manage-objects/update.mdx +++ b/docs/weaviate/manage-objects/update.mdx @@ -10,9 +10,7 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; import PyCode from '!!raw-loader!/_includes/code/howto/manage-data.update.py'; -import PyCodeV3 from '!!raw-loader!/_includes/code/howto/manage-data.update-v3.py'; import TSCode from '!!raw-loader!/_includes/code/howto/manage-data.update.ts'; -import TSCodeLegacy from '!!raw-loader!/_includes/code/howto/manage-data.update-v2.ts'; import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/manage-data.update.java'; import GoCode from '!!raw-loader!/_includes/code/howto/go/docs/manage-data.update_test.go'; import RestObjectsCRUDClassnameNote from '/_includes/rest-objects-crud-classname-note.md'; @@ -43,7 +41,7 @@ If you update the value of a *previously vectorized* property, Weaviate re-vecto However, if you add a *new* property to your collection definition, Weaviate only vectorizes the new objects. Weaviate doesn't re-vectorize and re-index existing objects when a new property is defined, only when an existing property is updated. - + - - - - + - - - - + - - - - + - - - > Coming soon (vote for the [feature request](https://github.com/weaviate/typescript-client/issues/64)) - - @@ -149,7 +118,7 @@ The object vector can also be updated similarly to properties. For [named vector The entire object can be replaced by providing the collection name, id and the new object. - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - + - - - - - - + - - - - - + - - - - - - + - - - - - - + - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - - + - + - + - - - - + - - - - + The `v4` Python client API provides filtering by `any_of`, or `all_of`, as well as using `&` or `|` operators.
@@ -138,16 +122,8 @@ To filter with two or more conditions, use `And` or `Or` to define the relations
- - - - + Use `Filters.and` and `Filters.or` methods to combine filters in the JS/TS `v3` API.
@@ -163,14 +139,6 @@ To filter with two or more conditions, use `And` or `Or` to define the relations />
- - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - - - - + - - - - + - - - - + - + - - - - + - - - - + - - - - + - + - + - + - - - - + - - - - + - - - - + - - - - + - + - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - If your query image is stored in a file, you can use the client library to search by its filename. - + - - - - + - - - > Not available yet. Vote for the [feature request](https://github.com/weaviate/typescript-client/issues/65). DIY code below. - - - @@ -121,7 +100,7 @@ If your query image is stored in a file, you can use the client library to searc You can search by a base64 representation of an image: - + - - - - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - This example uses a base64 representation of an image. - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + The v4 client requires Weaviate 1.23.7 or higher.

```bash pip install -U weaviate-client ```
- - -```bash -pip install "weaviate-client==3.*" -``` - - + ```bash npm install weaviate-client ``` - - -```bash -npm install weaviate-ts-client -``` -
## Connect to Weaviate @@ -162,7 +148,7 @@ When you create a query vector, use the same vectorizer that you use to create t This [`nearVector`](/weaviate/search/similarity#search-with-a-vector) query supplies a query vector. The query vector is an embedding of the query string, "biology". - + - - - - + - - - - + - - - - + - - - @@ -112,7 +95,7 @@ Let's take an illustrative example with passages from a book. Here, the Weaviate Before we can generate text, we need to retrieve relevant data. Let's retrieve the three most similar passages to the meaning of `history of git` with a semantic search. - + - - - - + - - - This should return a set of results like the following (truncated for brevity): @@ -182,7 +149,7 @@ We can transform this result set into new text using RAG with just a minor modif Run the following code snippet, and inspect the results: - + - - - - + - - - Here is our generated text: @@ -251,7 +202,7 @@ Here we prompt the model to translate individual wine reviews into French, using Note that in this query, we apply a `single prompt` parameter. This means that the LLM is prompted with each object individually, rather than with the entire result set. - + - - - - + - - - As the query was run with a limit of 5, you should see 5 objects returned, including generated texts. @@ -338,7 +273,7 @@ If you are using WCD, you will not need to do anything to enable modules. You can check which modules are enabled by viewing the `meta` information for your Weaviate instance, as shown below: - + - - - - + - - - The response will include a list of modules. Check that your desired module is enabled. @@ -442,7 +361,7 @@ You can read further discussions in the [Best practices & tips](#best-practices- In the following snippet, we download a chapter of the `Pro Git` book, clean it and chunk it. - + - - - - + - - - This will download the text from the chapter, and return a list/array of strings of 150 word chunks, with a 25-word overlap added in front. @@ -485,7 +388,7 @@ We can now create a collection definition for the chunks. To use RAG, your desir The below collection definition for the `GitBookChunk` collection specifies `text2vec-openai` as the vectorizer and `generative-openai` as the generative module. Note that the `generative-openai` parameter can have an empty dictionary/object as its value, which will use the default parameters. - + - - - - + - - - #### Import data @@ -524,7 +411,7 @@ The below collection definition for the `GitBookChunk` collection specifies `tex Now, we can import the data into Weaviate. - + - - - - + - - - Once this is done, you should have imported a collection of chunks from the chapter into Weaviate. You can check this by running a simple aggregation query: - + - - - - + - - - Which should indicate that there are `10` chunks in the database. @@ -606,7 +461,7 @@ Now that we have configured Weaviate and populated it with data, we can perform Single prompts tell Weaviate to generate text based on each retrieved object and the user-provided prompt. In this example, we retrieve two objects and prompt the language model to write a haiku based on the text of each chunk. - + - - - - + - - - It should return haiku-like text, such as: @@ -661,7 +500,7 @@ A grouped task is a prompt that is applied to a group of objects. This allows yo In this example, we prompt the language model to write a trivia tweet based on the result. - + - - - - + - - - It should return a factoid written for social media, such as: @@ -710,7 +533,7 @@ RAG in Weaviate is a two-step process under the hood, involving retrieval of obj In this example, we search the chapter for passages that relate to the states of git before generating a tweet as before. - + - - - - + - - - This should return text like: @@ -755,7 +562,7 @@ This should return text like: Now, simply by changing the search query, we can generate similar content about different topics. - + - - - - + - - - In this case, the result should be something like: diff --git a/docs/weaviate/starter-guides/managing-collections/index.mdx b/docs/weaviate/starter-guides/managing-collections/index.mdx index 51be32a8e..28862ce16 100644 --- a/docs/weaviate/starter-guides/managing-collections/index.mdx +++ b/docs/weaviate/starter-guides/managing-collections/index.mdx @@ -259,7 +259,7 @@ Now with aliases, simply create a new collection with your updated collection de Here's a complete example showing how to use aliases for a collection migration: - + - + - - - - - @@ -167,16 +157,6 @@ Take a look at the snippet below in which we retrieve objects from the `Jeopardy language="py" /> - - - - - @@ -207,14 +187,6 @@ Take a look at the snippet below, This query looks through the `JeopardyQuestion language="python" /> - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + ' + ) + + # We'll build the new content line by line + result_lines = [] + skip_mode = False + nesting_level = 0 + + # Process the file line by line + lines = file_content.split("\n") + for line in lines: + # Check if we're starting a Python Client v3 TabItem + if not skip_mode and start_pattern.search(line): + skip_mode = True + nesting_level = 1 + # Check if there's a closing tag on the same line + if "" in line: + nesting_level -= 1 + if nesting_level == 0: + skip_mode = False + continue + + # If we're in skip mode, check for nested tags + if skip_mode: + # Count opening tags (handle nested TabItems) + nesting_level += line.count("") + + # If nesting level is back to 0, we're done skipping + if nesting_level <= 0: + skip_mode = False + continue + + # If we're not skipping, add the line to the result + result_lines.append(line) + + return "\n".join(result_lines) + + +def process_directory(directory_path, file_extensions, dry_run=True): + """ + Process all files with given extensions in a directory and its subdirectories. + """ + directory = Path(directory_path) + files_processed = 0 + files_modified = 0 + + for ext in file_extensions: + for file_path in directory.glob(f"**/*{ext}"): + files_processed += 1 + + # Read the file content + with open(file_path, "r", encoding="utf-8") as file: + try: + content = file.read() + except UnicodeDecodeError: + print(f"Error reading {file_path}: UnicodeDecodeError") + continue + + # Process the content + new_content = remove_py3_tab_items(content) + + # If content was modified + if new_content != content: + files_modified += 1 + print(f"Modified: {file_path}") + + # Write the changes if not in dry-run mode + if not dry_run: + with open(file_path, "w", encoding="utf-8") as file: + file.write(new_content) + + return files_processed, files_modified + + +def main(): + parser = argparse.ArgumentParser( + description="Remove Python Client v3 TabItem blocks from files." + ) + parser.add_argument("directory", help="Directory to process") + parser.add_argument( + "--ext", + nargs="+", + default=[".md", ".mdx"], + help="File extensions to process (default: .md .mdx)", + ) + parser.add_argument( + "--apply", + action="store_true", + help="Apply changes (without this flag, runs in dry-run mode)", + ) + + args = parser.parse_args() + + print(f"Processing files in {args.directory}") + print(f"File extensions: {', '.join(args.ext)}") + print( + f"Mode: {'Apply Changes' if args.apply else 'Dry Run (no changes will be made)'}" + ) + + files_processed, files_modified = process_directory( + args.directory, args.ext, dry_run=not args.apply + ) + + print(f"\nSummary:") + print(f"Files processed: {files_processed}") + print(f"Files that would be modified: {files_modified}") + + if not args.apply and files_modified > 0: + print("\nRun with --apply to make the changes.") + + +if __name__ == "__main__": + main() diff --git a/tools/remove_ts2.py b/tools/remove_ts2.py new file mode 100644 index 000000000..5b97b10d5 --- /dev/null +++ b/tools/remove_ts2.py @@ -0,0 +1,128 @@ +import os +import re +import argparse +from pathlib import Path + + +def remove_ts2_tab_items(file_content): + """ + Remove TabItem blocks for TypeScript Client v2 from the content. + This uses a combination of regex and state tracking to properly handle nested tags. + """ + # Pattern to detect the start of TypeScript Client v2 TabItem + start_pattern = re.compile( + r'' + ) + + # We'll build the new content line by line + result_lines = [] + skip_mode = False + nesting_level = 0 + + # Process the file line by line + lines = file_content.split("\n") + for line in lines: + # Check if we're starting a TypeScript Client v2 TabItem + if not skip_mode and start_pattern.search(line): + skip_mode = True + nesting_level = 1 + # Check if there's a closing tag on the same line + if "" in line: + nesting_level -= 1 + if nesting_level == 0: + skip_mode = False + continue + + # If we're in skip mode, check for nested tags + if skip_mode: + # Count opening tags (handle nested TabItems) + nesting_level += line.count("") + + # If nesting level is back to 0, we're done skipping + if nesting_level <= 0: + skip_mode = False + continue + + # If we're not skipping, add the line to the result + result_lines.append(line) + + return "\n".join(result_lines) + + +def process_directory(directory_path, file_extensions, dry_run=True): + """ + Process all files with given extensions in a directory and its subdirectories. + """ + directory = Path(directory_path) + files_processed = 0 + files_modified = 0 + + for ext in file_extensions: + for file_path in directory.glob(f"**/*{ext}"): + files_processed += 1 + + # Read the file content + with open(file_path, "r", encoding="utf-8") as file: + try: + content = file.read() + except UnicodeDecodeError: + print(f"Error reading {file_path}: UnicodeDecodeError") + continue + + # Process the content + new_content = remove_ts2_tab_items(content) + + # If content was modified + if new_content != content: + files_modified += 1 + print(f"Modified: {file_path}") + + # Write the changes if not in dry-run mode + if not dry_run: + with open(file_path, "w", encoding="utf-8") as file: + file.write(new_content) + + return files_processed, files_modified + + +def main(): + parser = argparse.ArgumentParser( + description="Remove TypeScript Client v2 TabItem blocks from files." + ) + parser.add_argument("directory", help="Directory to process") + parser.add_argument( + "--ext", + nargs="+", + default=[".md", ".mdx"], + help="File extensions to process (default: .md .mdx)", + ) + parser.add_argument( + "--apply", + action="store_true", + help="Apply changes (without this flag, runs in dry-run mode)", + ) + + args = parser.parse_args() + + print(f"Processing files in {args.directory}") + print(f"File extensions: {', '.join(args.ext)}") + print( + f"Mode: {'Apply Changes' if args.apply else 'Dry Run (no changes will be made)'}" + ) + + files_processed, files_modified = process_directory( + args.directory, args.ext, dry_run=not args.apply + ) + + print(f"\nSummary:") + print(f"Files processed: {files_processed}") + print(f"Files that would be modified: {files_modified}") + + if not args.apply and files_modified > 0: + print("\nRun with --apply to make the changes.") + + +if __name__ == "__main__": + main() diff --git a/tools/validate_code_blocks.py b/tools/validate_code_blocks.py new file mode 100644 index 000000000..9485c7998 --- /dev/null +++ b/tools/validate_code_blocks.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +import os +import re +import argparse +from pathlib import Path + + +def validate_tab_items(file_content, file_path): + """ + Validates all blocks in a file's content. + + A TabItem is considered valid if it contains either: + 1. A markdown code block (```). + 2. A component. + + Args: + file_content (str): The content of the file to check. + file_path (Path): The path to the file, used for error reporting. + + Returns: + list: A list of error message strings. An empty list means no errors were found. + """ + errors = [] + # This regex finds ... blocks, handling multi-line content + # It's non-greedy (.*?) to correctly handle multiple tabs in a file. + # re.DOTALL makes '.' match newlines. + tab_item_pattern = re.compile(r"(.*?)", re.DOTALL) + + for match in tab_item_pattern.finditer(file_content): + # The content is in the first capturing group + tab_content = match.group(1) + + # The start position of the match is used to calculate the line number + start_index = match.start() + line_number = file_content.count("\n", 0, start_index) + 1 + + # Check for the required elements + has_markdown_code = "```" in tab_content + has_filtered_text_block = ".\n" + f" Content: {tab_content.strip()[:100]}..." # Show a snippet of the content + ) + errors.append(error_message) + + return errors + + +def process_directory(directory_path, file_extensions): + """ + Process all files with given extensions in a directory and its subdirectories. + """ + directory = Path(directory_path) + files_scanned = 0 + files_with_issues = 0 + total_issues = 0 + + print("--- Starting Validation ---") + + for ext in file_extensions: + for file_path in directory.glob(f"**/*{ext}"): + files_scanned += 1 + + try: + with open(file_path, "r", encoding="utf-8") as file: + content = file.read() + except UnicodeDecodeError: + print(f"āš ļø Could not read file (UnicodeDecodeError): {file_path}") + continue + except Exception as e: + print(f"āŒ Error opening file {file_path}: {e}") + continue + + # Validate the file's content + issues = validate_tab_items(content, file_path) + + if issues: + files_with_issues += 1 + total_issues += len(issues) + print(f"\nāŒ Found issues in: {file_path}") + for issue in issues: + print(issue) + + print("\n--- Validation Summary ---") + print(f"šŸ” Files scanned: {files_scanned}") + print(f"šŸ“„ Files with issues: {files_with_issues}") + print(f"ā—ļø Total issues found: {total_issues}") + + if files_with_issues == 0: + print("\nāœ… All scanned files are valid!") + + +def main(): + parser = argparse.ArgumentParser( + description="Validate documentation files to ensure all TabItem blocks contain code snippets." + ) + parser.add_argument("directory", help="Directory to process") + parser.add_argument( + "--ext", + nargs="+", + default=[".md", ".mdx"], + help="File extensions to process (default: .md .mdx)", + ) + + args = parser.parse_args() + + print(f"Processing files in: {args.directory}") + print(f"File extensions: {', '.join(args.ext)}") + + process_directory(args.directory, args.ext) + + +if __name__ == "__main__": + main()