Skip to content

Commit

Permalink
280 py4 add client.close (#1563)
Browse files Browse the repository at this point in the history
* 280 client.close

* .py files .mdx next

* add mdx instances

* Clean up
  • Loading branch information
daveatweaviate authored Jan 22, 2024
1 parent e555e70 commit 366cb21
Show file tree
Hide file tree
Showing 45 changed files with 238 additions and 38 deletions.
2 changes: 1 addition & 1 deletion _includes/code/automated-testing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Blog: Automated testing for Weaviate applications - Python code
#SATRT Connect # START ConnectAndCleanup
#START Connect # START ConnectAndCleanup
import weaviate
import os

Expand Down
13 changes: 13 additions & 0 deletions _includes/code/client-libraries/python_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
assert articles_config.name == "TestArticle"
assert len(articles_config.properties) == 1

# START CreateCollectionExample

client.close()
# END CreateCollectionExample

client = weaviate.connect_to_local()
for cname in ["TestArticle", "TestAuthor"]:
client.collections.delete(cname)
Expand Down Expand Up @@ -207,14 +212,20 @@
collection_config = collection.config.get()
assert collection_config.name == cname

# START CreateCollectionWithRefsExample

client.close()
# END CreateCollectionWithRefsExample

# START GetCollectionExample
import weaviate
import weaviate.classes as wvc

client = weaviate.connect_to_local()

collection = client.collections.get("TestArticle")

client.close()
# END GetCollectionExample

# =====================================================================================
Expand Down Expand Up @@ -562,3 +573,5 @@ class Question(TypedDict):
return_metadata=wvc.MetadataQuery(creation_time=True) # MetaDataQuery object is used to specify the metadata to be returned in the response
)
# END GenericsExample

client.close()
5 changes: 5 additions & 0 deletions _includes/code/graphql.additional.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,8 @@ def test_gqlresponse(response_in, gqlresponse_in):
# TEST DISABLED - sandbox needed
# gqlresponse = client.query.raw(gql_query)
# test_gqlresponse(response, gqlresponse)

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/graphql.aggregate.simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,8 @@
assert "inPublication" in response.properties.keys()
assert "wordCount" in response.properties.keys()
assert response.total_count > 0

# START-ANY

client.close()
# END-ANY
2 changes: 2 additions & 0 deletions _includes/code/graphql.filters.after.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ result = article.query.fetch_objects(
# highlight-end
)

client.close()

for o in result.objects:
print( f"Title: {o.properties["title"]}")
```
Expand Down
2 changes: 2 additions & 0 deletions _includes/code/graphql.filters.group.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ article=client.graphql_raw_query(
for a in article.get["Publication"]:
print(a)

client.close()

```

</TabItem>
Expand Down
2 changes: 2 additions & 0 deletions _includes/code/graphql.filters.limit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ result = article.query.fetch_objects(
# highlight-end
)

client.close()

for o in result.objects:
print( f"Title: {o.properties["title"]}")
```
Expand Down
5 changes: 5 additions & 0 deletions _includes/code/graphql.filters.nearText.generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
for o in response.objects:
print(o.properties)
print(o.metadata)
# END-ANY

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/graphql.filters.nearText.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@
for o in response.objects:
print(o.properties)
print(o.metadata)
# END-ANY

# START-ANY

client.close()
# END-ANY
2 changes: 2 additions & 0 deletions _includes/code/graphql.filters.offset.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ result = article.query.fetch_objects(
# highlight-end
)

client.close()

for o in result.objects:
print( f"Title: {o.properties["title"]}")

Expand Down
5 changes: 5 additions & 0 deletions _includes/code/graphql.filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@
# END FilterByGeoCoordinates

# TEST

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/graphql.get.simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@
assert "hasCategory" in list(o.references.keys())
# "title" in ro.properties.keys()
# assert "hasCategory" in o.references[0].keys()

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/graphql.metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@
print(o.uuid) # Inspect UUID (returned by default)
print(o.properties) # Inspect returned objects
# END MetadataUUIDDistance

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/graphql.search-operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,8 @@
"""
# END GraphQLQnAExample
'''

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/bq-compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,8 @@
]
)
# END BQWithOptions

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/configure.backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,8 @@

# Test
assert result["status"] == "SUCCESS"

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,8 @@

assert old_config.inverted_index_config.bm25.k1 == 1.2
assert new_config.inverted_index_config.bm25.k1 == 1.5

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.create.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@

# # TODO: update the assertion
# assert "thisPropShouldNotEndUpInTheSchema" in result["error"][0]["message"]

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.cross-refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,8 @@ def del_props(client: WeaviateClient, uuid_to_update: str, collection_name: str,
# "href": f"/v1/objects/JeopardyCategory/{museums_id}"
# }]
# END Test results

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@
# Test deletion
response = collection.aggregate.over_all(total_count=True)
assert response.total_count == 2

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.import.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,8 @@

# Clean up
client.collections.delete(collection.name)

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.migrate.data.v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,8 @@ def migrate_data(collection_src: Collection, collection_tgt: Collection):
resps = [r.query.near_text("Earthy but very drinkable", limit=1) for r in coll_list]
assert resps[0].objects[0].uuid == resps[1].objects[0].uuid

# START-ANY

client_src.close()
client_tgt.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.multi-tenancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,8 @@

# TODO - investigate whether the code above is wrong or this is related to the client
# assert result.references["hasCategory"][0]["href"] == f"/v1/objects/JeopardyCategory/{category_id}"

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/manage-data.read-all-objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@
tenants = multi_collection.tenants.get()
# highlight-end

# Iterate thourgh tenants
# Iterate through tenants
for tenant_name in tenants.keys():
# Iterate through objects within each tenant
# highlight-start
for item in multi_collection.with_tenant(tenant_name).iterator():
# highlight-end
print(f"{tenant_name}: {item.properties}")
# END ReadAllTenants

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.read.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@

# Test
# assert exists is True

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/manage-data.update.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,8 @@ def del_props(client: WeaviateClient, uuid_to_update: str, collection_name: str,
# Test
result = jeopardy.query.fetch_object_by_id(uuid)
assert result.properties == {}

# START-ANY

client.close()
# END-ANY
5 changes: 5 additions & 0 deletions _includes/code/howto/pq-compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,8 @@ def parse_data():
print(f"Centroids: { pq_config.centroids }")

# END GetSchema

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/search.aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" # Replace w/ your OPENAI API key
# }
# )
# TODOv4 - update this to call the wcs instace
# TODOv4 - update this to call the wcs instance
client = weaviate.connect_to_local(
headers={
"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"] # Replace with your inference API key
Expand Down Expand Up @@ -521,3 +521,8 @@
# END whereFilter Expected Results
)
# assert response == expected_response

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/search.basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,9 @@
// MultiTenancy Expected Results
pass
// END MultiTenancy Expected Results
"""
"""

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/search.bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,9 @@
# END BM25WithFilterGraphQL
"""
# gqlresponse = client.query.raw(gql_query)
# test_gqlresponse(response, gqlresponse)
# test_gqlresponse(response, gqlresponse)

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/search.filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" # Replace w/ your OPENAI API key
# }
# )
# TODOv4 - update this to call the wcs instace
# TODOv4 - update this to call the wcs instance
client = weaviate.connect_to_local(
headers={
"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"] # Replace with your inference API key
Expand Down Expand Up @@ -620,3 +620,8 @@

# TEST
assert str(response.objects[0].uuid) == target_id

# START-ANY

client.close()
# END-ANY
7 changes: 6 additions & 1 deletion _includes/code/howto/search.generative.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# "X-OpenAI-Api-Key": "YOUR-OPENAI-API-KEY" # Replace w/ your OPENAI API key
# }
# )
# TODOv4 - update this to call the wcs instace
# TODOv4 - update this to call the wcs instance
client = weaviate.connect_to_local(
headers={
"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"] # Replace with your inference API key
Expand Down Expand Up @@ -419,3 +419,8 @@
# assert gqlresponse["data"]["Get"]["JeopardyQuestion"][0].keys() == {"question", "points", "_additional"}
# assert "Australia" in gqlresponse["data"]["Get"]["JeopardyQuestion"][0]["_additional"]["generate"]["groupedResult"]
# End test

# START-ANY

client.close()
# END-ANY
4 changes: 4 additions & 0 deletions _includes/code/howto/search.hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,7 @@
# gqlresponse = client.query.raw(gql_query)
# test_gqlresponse(response, gqlresponse)

# START-ANY

client.close()
# END-ANY
Loading

0 comments on commit 366cb21

Please sign in to comment.