diff --git a/_includes/code/configuration/replication-consistency.mdx b/_includes/code/configuration/replication-consistency.mdx index 8209c476..1f442987 100644 --- a/_includes/code/configuration/replication-consistency.mdx +++ b/_includes/code/configuration/replication-consistency.mdx @@ -1,14 +1,13 @@ 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'; - + - - - - + - - - - + - + - + - + - - - - + - - - - + - - - - + - - - -```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) -``` - diff --git a/_includes/code/graphql.aggregate.nearObject.mdx b/_includes/code/graphql.aggregate.nearObject.mdx index 5de5f0aa..c8e06602 100644 --- a/_includes/code/graphql.aggregate.nearObject.mdx +++ b/_includes/code/graphql.aggregate.nearObject.mdx @@ -5,35 +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) -``` - diff --git a/_includes/code/graphql.aggregate.nearText.mdx b/_includes/code/graphql.aggregate.nearText.mdx index 46bddb69..e6509bf6 100644 --- a/_includes/code/graphql.aggregate.nearText.mdx +++ b/_includes/code/graphql.aggregate.nearText.mdx @@ -5,34 +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) -``` - diff --git a/_includes/code/graphql.aggregate.nearVector.mdx b/_includes/code/graphql.aggregate.nearVector.mdx index 2ddb2d91..439f06ac 100644 --- a/_includes/code/graphql.aggregate.nearVector.mdx +++ b/_includes/code/graphql.aggregate.nearVector.mdx @@ -5,34 +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) -``` - diff --git a/_includes/code/graphql.aggregate.simple.mdx b/_includes/code/graphql.aggregate.simple.mdx index e5eb8c2d..f18543fa 100644 --- a/_includes/code/graphql.aggregate.simple.mdx +++ b/_includes/code/graphql.aggregate.simple.mdx @@ -5,32 +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) -``` - diff --git a/_includes/code/graphql.explore.vector.mdx b/_includes/code/graphql.explore.vector.mdx index 760bc6ab..a1ac1246 100644 --- a/_includes/code/graphql.explore.vector.mdx +++ b/_includes/code/graphql.explore.vector.mdx @@ -2,33 +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 diff --git a/_includes/code/graphql.filters.after.mdx b/_includes/code/graphql.filters.after.mdx index 3e56e565..8b96b540 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 diff --git a/_includes/code/graphql.filters.bm25.filter.example.mdx b/_includes/code/graphql.filters.bm25.filter.example.mdx index 56b862eb..306c0c23 100644 --- a/_includes/code/graphql.filters.bm25.filter.example.mdx +++ b/_includes/code/graphql.filters.bm25.filter.example.mdx @@ -5,34 +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() -) -``` - diff --git a/_includes/code/graphql.filters.bm25.mdx b/_includes/code/graphql.filters.bm25.mdx index 4849d5fd..1e9496ec 100644 --- a/_includes/code/graphql.filters.bm25.mdx +++ b/_includes/code/graphql.filters.bm25.mdx @@ -5,36 +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) -``` - diff --git a/_includes/code/graphql.filters.group.mdx b/_includes/code/graphql.filters.group.mdx index 552b7852..cfc701d2 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 diff --git a/_includes/code/graphql.filters.hybrid.filter.example.mdx b/_includes/code/graphql.filters.hybrid.filter.example.mdx index f69b5424..b6f54067 100644 --- a/_includes/code/graphql.filters.hybrid.filter.example.mdx +++ b/_includes/code/graphql.filters.hybrid.filter.example.mdx @@ -5,33 +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() -) -``` - diff --git a/_includes/code/graphql.filters.hybrid.mdx b/_includes/code/graphql.filters.hybrid.mdx index 0b577837..9a9bbd14 100644 --- a/_includes/code/graphql.filters.hybrid.mdx +++ b/_includes/code/graphql.filters.hybrid.mdx @@ -5,28 +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() - ) - -``` - diff --git a/_includes/code/graphql.filters.hybrid.properties.mdx b/_includes/code/graphql.filters.hybrid.properties.mdx index 670c3456..48e398c1 100644 --- a/_includes/code/graphql.filters.hybrid.properties.mdx +++ b/_includes/code/graphql.filters.hybrid.properties.mdx @@ -7,34 +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)) -``` - diff --git a/_includes/code/graphql.filters.hybrid.vector.mdx b/_includes/code/graphql.filters.hybrid.vector.mdx index 088d6c23..0ee014b8 100644 --- a/_includes/code/graphql.filters.hybrid.vector.mdx +++ b/_includes/code/graphql.filters.hybrid.vector.mdx @@ -5,26 +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() - ) -``` - diff --git a/_includes/code/graphql.filters.limit.mdx b/_includes/code/graphql.filters.limit.mdx index 0da03403..5974957a 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 diff --git a/_includes/code/graphql.filters.nearObject.mdx b/_includes/code/graphql.filters.nearObject.mdx index 132f897a..bd4ced78 100644 --- a/_includes/code/graphql.filters.nearObject.mdx +++ b/_includes/code/graphql.filters.nearObject.mdx @@ -5,38 +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) -``` - diff --git a/_includes/code/graphql.filters.nearText.2obj.mdx b/_includes/code/graphql.filters.nearText.2obj.mdx index f2c8206b..7a8d9cd7 100644 --- a/_includes/code/graphql.filters.nearText.2obj.mdx +++ b/_includes/code/graphql.filters.nearText.2obj.mdx @@ -5,40 +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) -``` - diff --git a/_includes/code/graphql.filters.nearText.mdx b/_includes/code/graphql.filters.nearText.mdx index 739df562..150020aa 100644 --- a/_includes/code/graphql.filters.nearText.mdx +++ b/_includes/code/graphql.filters.nearText.mdx @@ -4,43 +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) -``` - diff --git a/_includes/code/graphql.filters.nearVector.mdx b/_includes/code/graphql.filters.nearVector.mdx index 50fee454..9ffa76df 100644 --- a/_includes/code/graphql.filters.nearVector.mdx +++ b/_includes/code/graphql.filters.nearVector.mdx @@ -5,36 +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) -``` - diff --git a/_includes/code/graphql.filters.offset.mdx b/_includes/code/graphql.filters.offset.mdx index 293e2f46..f0383743 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 diff --git a/_includes/code/graphql.filters.where.beacon.count.mdx b/_includes/code/graphql.filters.where.beacon.count.mdx index 397cd084..15a9e242 100644 --- a/_includes/code/graphql.filters.where.beacon.count.mdx +++ b/_includes/code/graphql.filters.where.beacon.count.mdx @@ -5,37 +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) -``` - diff --git a/_includes/code/graphql.filters.where.beacon.mdx b/_includes/code/graphql.filters.where.beacon.mdx index 1b32cf42..d7c57654 100644 --- a/_includes/code/graphql.filters.where.beacon.mdx +++ b/_includes/code/graphql.filters.where.beacon.mdx @@ -5,37 +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) -``` - diff --git a/_includes/code/graphql.filters.where.geocoordinates.mdx b/_includes/code/graphql.filters.where.geocoordinates.mdx index b4340d40..5c217dc1 100644 --- a/_includes/code/graphql.filters.where.geocoordinates.mdx +++ b/_includes/code/graphql.filters.where.geocoordinates.mdx @@ -5,51 +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) -``` - diff --git a/_includes/code/graphql.filters.where.id.mdx b/_includes/code/graphql.filters.where.id.mdx index 45e82db9..dfc72351 100644 --- a/_includes/code/graphql.filters.where.id.mdx +++ b/_includes/code/graphql.filters.where.id.mdx @@ -5,38 +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)) -``` - diff --git a/_includes/code/graphql.filters.where.like.mdx b/_includes/code/graphql.filters.where.like.mdx index 6e0b13e3..b930217d 100644 --- a/_includes/code/graphql.filters.where.like.mdx +++ b/_includes/code/graphql.filters.where.like.mdx @@ -5,37 +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) -``` - diff --git a/_includes/code/graphql.filters.where.operands.mdx b/_includes/code/graphql.filters.where.operands.mdx index b884a92e..e1627704 100644 --- a/_includes/code/graphql.filters.where.operands.mdx +++ b/_includes/code/graphql.filters.where.operands.mdx @@ -5,44 +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) -``` - diff --git a/_includes/code/graphql.filters.where.simple.mdx b/_includes/code/graphql.filters.where.simple.mdx index 6bd424e1..cd7a7d8e 100644 --- a/_includes/code/graphql.filters.where.simple.mdx +++ b/_includes/code/graphql.filters.where.simple.mdx @@ -5,37 +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) -``` - diff --git a/_includes/code/graphql.filters.where.timestamps.mdx b/_includes/code/graphql.filters.where.timestamps.mdx index a1f2409f..3ff82dee 100644 --- a/_includes/code/graphql.filters.where.timestamps.mdx +++ b/_includes/code/graphql.filters.where.timestamps.mdx @@ -5,38 +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) -``` - diff --git a/_includes/code/graphql.get.beacon.mdx b/_includes/code/graphql.get.beacon.mdx index 565fa454..d060f1d5 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'; - + - - - - - diff --git a/_includes/code/graphql.get.consistency.mdx b/_includes/code/graphql.get.consistency.mdx index 3834b61f..1c97a9af 100644 --- a/_includes/code/graphql.get.consistency.mdx +++ b/_includes/code/graphql.get.consistency.mdx @@ -3,35 +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}") -``` - diff --git a/_includes/code/graphql.get.groupby.mdx b/_includes/code/graphql.get.groupby.mdx index e1961da8..7a98689d 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'; - + - + - - - - - + - - - - - diff --git a/_includes/code/graphql.underscoreproperties.distance.mdx b/_includes/code/graphql.underscoreproperties.distance.mdx index 93251b0f..d78fb701 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 diff --git a/_includes/code/graphql.underscoreproperties.semanticpath.mdx b/_includes/code/graphql.underscoreproperties.semanticpath.mdx index 73a740cf..2c01ec6e 100644 --- a/_includes/code/graphql.underscoreproperties.semanticpath.mdx +++ b/_includes/code/graphql.underscoreproperties.semanticpath.mdx @@ -5,49 +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) -``` - diff --git a/_includes/code/howto/manage-data.create.with.geo.mdx b/_includes/code/howto/manage-data.create.with.geo.mdx index 7e3da49d..9d49fa17 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 diff --git a/_includes/code/howto/manage-data.read.check.existence.mdx b/_includes/code/howto/manage-data.read.check.existence.mdx index 8cfbd50a..dccb37a0 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) -``` - - diff --git a/_includes/code/howto/manage-data.shards.inspect.mdx b/_includes/code/howto/manage-data.shards.inspect.mdx index e47cdb08..1b243710 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 diff --git a/_includes/code/howto/manage-data.shards.update.mdx b/_includes/code/howto/manage-data.shards.update.mdx index 96ebc818..1ce3e6a9 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 diff --git a/_includes/code/meta.mdx b/_includes/code/meta.mdx index 486ca7d9..f69530c3 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/nodes.mdx b/_includes/code/nodes.mdx index ca26afc0..625de52b 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-transformers.ask.mdx b/_includes/code/qna-transformers.ask.mdx index b2aa2e94..3f845118 100644 --- a/_includes/code/qna-transformers.ask.mdx +++ b/_includes/code/qna-transformers.ask.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 -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) -``` - diff --git a/_includes/code/quickstart.byov.schema.mdx b/_includes/code/quickstart.byov.schema.mdx index 3d5582d8..5e6c259a 100644 --- a/_includes/code/quickstart.byov.schema.mdx +++ b/_includes/code/quickstart.byov.schema.mdx @@ -4,13 +4,12 @@ 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'; - + - - - - + - - - - + ```python import weaviate, os @@ -23,19 +23,6 @@ client = weaviate.connect_to_weaviate_cloud( 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 -) -``` - diff --git a/_includes/code/quickstart/import.mdx b/_includes/code/quickstart/import.mdx index c1192506..b0183957 100644 --- a/_includes/code/quickstart/import.mdx +++ b/_includes/code/quickstart/import.mdx @@ -2,13 +2,12 @@ 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'; - + - - - */} - + - - - - - diff --git a/_includes/code/replication.get.object.by.id.mdx b/_includes/code/replication.get.object.by.id.mdx index 624b7a46..72419c88 100644 --- a/_includes/code/replication.get.object.by.id.mdx +++ b/_includes/code/replication.get.object.by.id.mdx @@ -5,7 +5,7 @@ import TSCode from '!!raw-loader!/_includes/code/howto/search.consistency.ts'; import FilteredTextBlock from '@site/src/components/Documentation/FilteredTextBlock'; - + - + - - - - + - - -```python -add_prop = { - "dataType": [ - "boolean" - ], - "name": "onHomepage" -} - -client.schema.property.create("Article", add_prop) -``` - - ```js diff --git a/_includes/code/tutorial.schema.create.mdx b/_includes/code/tutorial.schema.create.mdx index 8ae43c59..b9375bc5 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)) -``` - diff --git a/_includes/code/tutorial.schema.index-settings.mdx b/_includes/code/tutorial.schema.index-settings.mdx index bf746735..4968a632 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) -``` - diff --git a/_includes/code/tutorial.schema.multi-tenancy.mdx b/_includes/code/tutorial.schema.multi-tenancy.mdx index 730d9cd1..8756e2e3 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) -``` - diff --git a/_includes/code/tutorial.schema.properties.options.mdx b/_includes/code/tutorial.schema.properties.options.mdx index 06053c80..a1c56af3 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) -``` - diff --git a/_includes/code/wcs.authentication.api.key.mdx b/_includes/code/wcs.authentication.api.key.mdx index 799246f6..319575d7 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 -) -``` - 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 0c25d1d5..57670115 100644 --- a/_includes/code/wcs.authentication.api.key.with.inference.key.mdx +++ b/_includes/code/wcs.authentication.api.key.with.inference.key.mdx @@ -5,32 +5,13 @@ 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, - }, -) -``` - diff --git a/_includes/code/wcs.without.authentication.mdx b/_includes/code/wcs.without.authentication.mdx index 66a71285..50100246 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 -) -``` - - diff --git a/_includes/code/wellknown.live.mdx b/_includes/code/wellknown.live.mdx index 0e5327da..3ccb3204 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 188619ea..052f4d2a 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 96d7851c..65c60793 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/how.to.get.object.count.mdx b/_includes/how.to.get.object.count.mdx index 26075e1b..37a78f6f 100644 --- a/_includes/how.to.get.object.count.mdx +++ b/_includes/how.to.get.object.count.mdx @@ -5,24 +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() -``` - diff --git a/_includes/schema-delete-class.mdx b/_includes/schema-delete-class.mdx index 1bc67994..b9d9f49f 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 diff --git a/blog/2024-02-27-weaviate-1-24-release/_core-1-24-include.mdx b/blog/2024-02-27-weaviate-1-24-release/_core-1-24-include.mdx index 3f7bcbb7..f4bcb157 100644 --- a/blog/2024-02-27-weaviate-1-24-release/_core-1-24-include.mdx +++ b/blog/2024-02-27-weaviate-1-24-release/_core-1-24-include.mdx @@ -79,7 +79,6 @@ Weaviate is a robust platform that handles many kinds of workloads. This release The new Weaviate [Python client v4](/docs/weaviate/client-libraries/python) is available. The latest release adds support for named vectors and brings numerous other updates. If you have feedback on the new client, please let us know. - To learn more about the new client, read the [client release blog post](https://weaviate.io/blog/py-client-v4-release). -- To learn how to upgrade your code, see the [v3 to v4 migration guide](/docs/weaviate/client-libraries/python/v3_v4_migration). ## Summary diff --git a/docs/agents/query/tutorial-ecommerce.mdx b/docs/agents/query/tutorial-ecommerce.mdx index 36eb9bb0..a06febf5 100644 --- a/docs/agents/query/tutorial-ecommerce.mdx +++ b/docs/agents/query/tutorial-ecommerce.mdx @@ -109,7 +109,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: - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + -## Migration guides - -:::tip Migrating from `v3` to `v4` -If you are migrating from the `v3` client to the `v4`, see this [dedicated guide](./v3_v4_migration.md). -::: - ### 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 4131bc4d..00000000 --- a/docs/weaviate/client-libraries/python/python_v3.md +++ /dev/null @@ -1,915 +0,0 @@ ---- -title: "Legacy (v3) API (DEPRECATED)" -sidebar_position: 80 -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.md). -
- -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](/docs/weaviate/api/rest) and [GraphQL functions](../../api/graphql/index.md). 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) -``` - -## 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 004a302a..00000000 --- a/docs/weaviate/client-libraries/python/v3_v4_migration.md +++ /dev/null @@ -1,277 +0,0 @@ ---- -title: Migrate from v3 to v4 -sidebar_position: 50 -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-core-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`. - - - - - - -To configure connection timeout values, see [Timeout values](/docs/weaviate/client-libraries/python#timeout-values). - - - - - - - - - - - - - - - - - - - -The `v3` API style `Client` object is [still available](./index.md#legacy-v3-api), and will be deprecated in the future. - -## 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](./index.md#helper-classes). - - - -### 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 data](../../manage-data/index.md) has more details and additional sample code for working with data, such as [working with collections](../../manage-data/collections.mdx). See [searches](../../search/index.md) 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-data/collections.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.md) to get started, including instantiation details and various submodules. - -Then, take a look at the how-to guides for [Managing data](../../manage-data/index.md) and [Queries](../../search/index.md). - -In particular, check out the pages for: - -- [Client instantiation](./index.md#instantiate-a-client), -- [Manage collections](../../manage-data/collections.mdx), -- [Batch import](../../manage-data/import.mdx) -- [Cross-reference](../../manage-data/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/config-refs/datatypes.md b/docs/weaviate/config-refs/datatypes.md index 72429f6e..90bb1d2e 100644 --- a/docs/weaviate/config-refs/datatypes.md +++ b/docs/weaviate/config-refs/datatypes.md @@ -49,7 +49,7 @@ import TextTypeTs from '!!raw-loader!/_includes/code/typescript/config-refs.data #### Property definition - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - + - - - - - + - - - - - + - + - - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - To review the current `pq` configuration, you can retrieve it as shown below. - + - - - - + - - - @@ -64,7 +55,7 @@ To tune SQ, set these `vectorIndexConfig` parameters. - + - - - ## Multiple vector embeddings (named vectors) diff --git a/docs/weaviate/configuration/rbac/manage-roles-users.mdx b/docs/weaviate/configuration/rbac/manage-roles-users.mdx index cbe043c6..48b52816 100644 --- a/docs/weaviate/configuration/rbac/manage-roles-users.mdx +++ b/docs/weaviate/configuration/rbac/manage-roles-users.mdx @@ -32,7 +32,7 @@ Role management requires appropriate `role` resource permissions that can be obt - A role with [`Role Management`](#role-management-permissions) permissions granted. - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - 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. - + - - - validate it against the collection definition. - + - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + The Python client uses gRPC by default. See the client page for additional batch import [configuration options](/docs/weaviate/client-libraries/python#batch-imports). @@ -182,7 +173,7 @@ Weaviate generates an UUID for each object. Object IDs must be unique. If you se - `generateUuid5` (TypeScript) - + - - - - + - - - - + - - - - + - - - Stream JSON files example code - + - - - Stream CSV files example code - + - - - - + - + - - - - + - -

- 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. -

-

- -
- + - - - - + - + - + - - - - + - - - - + - + - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - - + The `v4` Python client API provides filtering by `any_of`, or `all_of`, as well as using `&` or `|` operators.
@@ -138,14 +130,6 @@ To filter with two or more conditions, use `And` or `Or` to define the relations
- - - @@ -210,7 +194,7 @@ The output is like this: You can group and nest filters. - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - - + - + - + - - - - + - - - - + - - - If your query image is stored in a file, you can use the client library to search by its filename. - + - - - @@ -121,7 +113,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: - + - - - - + - + - + - + - + - + - + - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + The v4 client requires Weaviate 1.23.7 or higher.

```bash pip install -U weaviate-client ```
- - -```bash -pip install "weaviate-client==3.*" -``` - ```bash @@ -161,7 +154,7 @@ When you create a query vector, use the same vectorizer that you use to create t This [`nearVector`](/docs/weaviate/search/similarity#search-with-a-vector) query supplies a query vector. The query vector is an embedding of the query string, "biology". - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + ' + ) + + # 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()