diff --git a/_includes/code/howto/search.basics.py b/_includes/code/howto/search.basics.py index a3a465ff..5caf05bf 100644 --- a/_includes/code/howto/search.basics.py +++ b/_includes/code/howto/search.basics.py @@ -17,7 +17,7 @@ auth_credentials=Auth.api_key(weaviate_api_key), headers={ "X-OpenAI-Api-Key": openai_api_key, - } + }, ) # ============================== @@ -73,7 +73,7 @@ response = jeopardy.query.fetch_objects( # highlight-start limit=1, - offset=1 + offset=1, # highlight-end ) @@ -88,6 +88,32 @@ # End test +# ========================== +# ===== FILTERED FETCH ===== +# ========================== + +# START GetWithFilter +from weaviate.classes.query import Filter + +jeopardy = client.collections.use("JeopardyQuestion") +response = jeopardy.query.fetch_objects( + # highlight-start + filters=Filter.by_property("round").equal("Double Jeopardy!"), + # highlight-end + limit=3, +) + +for o in response.objects: + print(o.properties) +# END GetWithFilter + +# Test results +assert response.objects[0].collection == "JeopardyQuestion" +assert "question" in response.objects[0].properties.keys() +assert len(response.objects) == 3 +# End test + + # ========================================== # ===== GET OBJECT PROPERTIES EXAMPLES ===== # ========================================== @@ -97,7 +123,7 @@ response = jeopardy.query.fetch_objects( # highlight-start limit=1, - return_properties=["question", "answer", "points"] + return_properties=["question", "answer", "points"], # highlight-end ) @@ -122,7 +148,7 @@ # highlight-start include_vector=True, # highlight-end - limit=1 + limit=1, ) print(response.objects[0].vector["default"]) @@ -170,13 +196,10 @@ response = jeopardy.query.fetch_objects( # highlight-start return_references=[ - QueryReference( - link_on="hasCategory", - return_properties=["title"] - ), + QueryReference(link_on="hasCategory", return_properties=["title"]), ], # highlight-end - limit=2 + limit=2, ) for o in response.objects: @@ -203,7 +226,7 @@ response = jeopardy.query.fetch_objects( limit=1, # highlight-start - return_metadata=MetadataQuery(creation_time=True) + return_metadata=MetadataQuery(creation_time=True), # highlight-end ) diff --git a/docs/weaviate/search/basics.md b/docs/weaviate/search/basics.md index 1844b91b..f1a8c08c 100644 --- a/docs/weaviate/search/basics.md +++ b/docs/weaviate/search/basics.md @@ -264,6 +264,21 @@ The output is like this: To paginate through the entire database, use a [cursor](../manage-objects/read-all-objects.mdx) instead of offset and limit. +## Filter results + +For more specific results, use a [`filter`](../api/graphql/filters.md) to narrow your search. + + + + + + + ## Retrieve object `properties` You can specify which object properties to return. By default, all properties and object UUIDs are returned. Blob and reference properties are excluded unless specified otherwise (_this does not apply to the Go and Java v5 client libraries)_.