{ Aggregate{ <Class> (groupBy:[<property>]){ groupedBy{# requires `groupBy` filter path value } meta{ count } <propertyOfDatatypeText> { count type topOccurrences(limit: <n_minimum_count>){ value occurs } } <propertyOfDatatypeNumberOrInteger> { count type minimum maximum mean median mode sum } <propertyOfDatatypeBoolean> { count type totalTrue totalFalse percentageTrue percentageFalse } <propertyWithReference> pointingTo type } } }
Below is an example query to obtain meta information about the Article collection. Note that the data is not grouped here, and results relate to all data objects in the Article collection.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
You can use a groupBy argument to get meta information about groups of data objects, from those matching a query. The groups can be based on a property of the data objects.
groupBy limitations
groupBy only works with near<Media> operators.
The groupBypath is limited to one property or cross-reference. Nested paths are not supported.
The groupBy argument is structured as follows for the Aggregate function:
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
import weaviate import weaviate.classes as wvc import os from weaviate.classes.aggregate import GroupByAggregate client = weaviate.connect_to_local() try: # Coming soon finally: client.close()
Aggregating data makes the topOccurrences property available. Note that the counts are not dependent on tokenization. The topOccurrences count is based on occurrences of the entire property, or one of the values if the property is an array.
You can optionally specify a limit parameter to limit the returned objects. For example, limit: 5 will return the top 5 most frequent occurrences.
Aggregating a Vector Search / Faceted Vector Search​
note
This feature was added in v1.13.0
You can combine a vector search (e.g. nearObject, nearVector, nearText, nearImage, etc.) with an aggregation. Internally, this is a two-step process where the vector search first finds the desired objects, then the results are aggregated.
Vector searches rank objects by similarity but do not exclude any objects. Thus, for a search operator to impact aggregation, you must limit the search space by setting either objectLimit or certainty for the query:
objectLimit, e.g. objectLimit: 100 tells Weaviate to aggregate the first 100 objects retrieved by the vector search query. This is useful when you know upfront how many results you want to serve, for example, in a recommendation scenario where you want to produce 100 recommendations.
certainty, e.g. certainty: 0.7 tells Weaviate to aggregate all vector search results with a certainty score of 0.7 or higher. This list has no fixed length, it depends on how many objects are good matches. This is useful in user-facing search scenarios, such as e-commerce. The user might be interested in all search results semantically similar to "apple iphone" and then generate facets.
The aggregation query will fail if neither objectLimit nor certainty is set.
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
package main import( "context" "fmt" "github.com/weaviate/weaviate-go-client/v5/weaviate" "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" ) funcmain(){ cfg := weaviate.Config{ Host:"localhost:8080", Scheme:"http", } client, err := weaviate.NewClient(cfg) if err !=nil{ panic(err) } title := graphql.Field{Name:"title"} url := graphql.Field{Name:"url"} wordCount := graphql.Field{ Name:"wordCount", Fields:[]graphql.Field{ {Name:"mean"}, {Name:"maximum"}, {Name:"median"}, {Name:"minimum"}, {Name:"mode"}, {Name:"sum"}, {Name:"type"}, }, } inPublication := graphql.Field{ Name:"inPublication", Fields:[]graphql.Field{ {Name:"pointingTo"}, {Name:"count"}, }, } // nearObject withNearObject := client.GraphQL().NearObjectArgBuilder(). WithDistance(0.85).// At least one of distance or objectLimit need to be set WithID("00037775-1432-35e5-bc59-443baaef7d80") result, err := client.GraphQL(). Aggregate(). WithFields(title, url, wordCount, inPublication). WithNearObject(nearObject). WithClassName("Article"). WithObjectLimit(100).// At least one of certainty or objectLimit need to be set Do(context.Background()) if err !=nil{ panic(err) } fmt.Printf("%v", result) }
packageio.weaviate; importio.weaviate.client.Config; importio.weaviate.client.WeaviateClient; importio.weaviate.client.base.Result; importio.weaviate.client.v1.graphql.model.GraphQLResponse; importio.weaviate.client.v1.graphql.query.argument.NearObjectArgument; importio.weaviate.client.v1.graphql.query.fields.Field; publicclassApp{ publicstaticvoidmain(String[] args){ Config config =newConfig("http","localhost:8080"); WeaviateClient client =newWeaviateClient(config); Field meta =Field.builder() .name("meta") .fields(newField[]{ Field.builder().name("count").build() }).build(); Field wordCount =Field.builder() .name("wordCount") .fields(newField[]{ Field.builder().name("mean").build(), Field.builder().name("maximum").build(), Field.builder().name("median").build(), Field.builder().name("minimum").build(), Field.builder().name("mode").build(), Field.builder().name("sum").build(), Field.builder().name("type").build() }).build(); Field inPublication =Field.builder() .name("inPublication") .fields(newField[]{ Field.builder().name("pointingTo").build(), Field.builder().name("count").build() }).build(); NearObjectArgument nearObject =NearObjectArgument.builder() // prior to v1.14 use certainty instead of distance .distance(0.6f)// at least one of certainty or objectLimit need to be set .id("00037775-1432-35e5-bc59-443baaef7d80") .build(); Result<GraphQLResponse> result = client.graphQL().aggregate() .withClassName("Article") .withFields(meta, wordCount, inPublication) .withNearObject(nearObject) .withObjectLimit(100)// at least one of certainty or objectLimit need to be set .run(); if(result.hasErrors()){ System.out.println(result.getError()); return; } System.out.println(result.getResult()); } }
echo '{ "query": "{ Aggregate { Article(nearObject:{ id: \"00037775-1432-35e5-bc59-443baaef7d80\" distance: 0.6 }, objectLimit: 200) { meta { count } inPublication { pointingTo type } wordCount { count maximum mean median minimum mode sum type } } } }" }' | curl \ -X POST \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer learn-weaviate' \ -d @- \ https://edu-demo.weaviate.network/v1/graphql
{ Aggregate{ Article( nearObject:{ id:"00037775-1432-35e5-bc59-443baaef7d80" # prior to v1.14, use `certainty` instead of `distance` distance:0.6 }, # at least one of "objectLimit" and/or "distance" must be set when using near<Media> objectLimit:200 ){ meta{ count } inPublication{ pointingTo type } wordCount{ count maximum mean median minimum mode sum type } } } }
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
package main import( "context" "fmt" "github.com/weaviate/weaviate-go-client/v5/weaviate" "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" ) funcmain(){ cfg := weaviate.Config{ Host:"localhost:8080", Scheme:"http", } client, err := weaviate.NewClient(cfg) if err !=nil{ panic(err) } title := graphql.Field{Name:"title"} url := graphql.Field{Name:"url"} wordCount := graphql.Field{ Name:"wordCount", Fields:[]graphql.Field{ {Name:"mean"}, {Name:"maximum"}, {Name:"median"}, {Name:"minimum"}, {Name:"mode"}, {Name:"sum"}, {Name:"type"}, }, } inPublication := graphql.Field{ Name:"inPublication", Fields:[]graphql.Field{ {Name:"pointingTo"}, {Name:"count"}, }, } // nearVector nearVector :=&graphql.NearVectorArgumentBuilder{} nearVector.WithCertainty(0.85).// At least one of certainty or objectLimit need to be set WithVector([]float32{0.1,0.2,-0.3}) result, err := client.GraphQL(). Aggregate(). WithFields(title, url, wordCount, inPublication). WithNearVector(nearVector). WithClassName("Article"). WithObjectLimit(100).// At least one of certainty or objectLimit need to be set Do(context.Background()) if err !=nil{ panic(err) } fmt.Printf("%v", result) }
packageio.weaviate; importio.weaviate.client.Config; importio.weaviate.client.WeaviateClient; importio.weaviate.client.base.Result; importio.weaviate.client.v1.graphql.model.GraphQLResponse; importio.weaviate.client.v1.graphql.query.argument.NearVectorArgument; importio.weaviate.client.v1.graphql.query.fields.Field; publicclassApp{ publicstaticvoidmain(String[] args){ Config config =newConfig("http","localhost:8080"); WeaviateClient client =newWeaviateClient(config); Field meta =Field.builder() .name("meta") .fields(newField[]{ Field.builder().name("count").build() }).build(); Field wordCount =Field.builder() .name("wordCount") .fields(newField[]{ Field.builder().name("mean").build(), Field.builder().name("maximum").build(), Field.builder().name("median").build(), Field.builder().name("minimum").build(), Field.builder().name("mode").build(), Field.builder().name("sum").build(), Field.builder().name("type").build() }).build(); Field inPublication =Field.builder() .name("inPublication") .fields(newField[]{ Field.builder().name("pointingTo").build(), Field.builder().name("count").build() }).build(); Float[] vector =newFloat[]{1.0f,2.0f,-3.0f}; NearVectorArgument nearVector =NearVectorArgument.builder() .certainty(0.7f)// at least one of certainty or objectLimit need to be set .vector(vector) .build(); Result<GraphQLResponse> result = client.graphQL().aggregate() .withClassName("Article") .withFields(meta, wordCount, inPublication) .withNearVector(nearVector) .withObjectLimit(100)// at least one of certainty or objectLimit need to be set .run(); if(result.hasErrors()){ System.out.println(result.getError()); return; } System.out.println(result.getResult()); } }
echo '{ "query": "{ Aggregate { Article(nearVector:{ vector: [0.1, 0.2, -0.3] certainty: 0.7 }, objectLimit: 200) { meta { count } inPublication { pointingTo type } wordCount { count maximum mean median minimum mode sum type } } } }" }' | curl \ -X POST \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer learn-weaviate' \ -d @- \ https://edu-demo.weaviate.network/v1/graphql
{ Aggregate{ Article(nearVector:{ vector:[0.1,0.2,-0.3] certainty:0.7# at least one of "objectLimit", },# and/or "certainty" must be set objectLimit:200){# when using near<Media> meta{ count } inPublication{ pointingTo type } wordCount{ count maximum mean median minimum mode sum type } } } }
More infoCode snippets in the documentation reflect the latest client library and Weaviate Database version. Check the Release notes for specific versions.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
package main import( "context" "fmt" "github.com/weaviate/weaviate-go-client/v5/weaviate" "github.com/weaviate/weaviate-go-client/v5/weaviate/graphql" ) funcmain(){ cfg := weaviate.Config{ Host:"localhost:8080", Scheme:"http", } client, err := weaviate.NewClient(cfg) if err !=nil{ panic(err) } title := graphql.Field{Name:"title"} url := graphql.Field{Name:"url"} wordCount := graphql.Field{ Name:"wordCount", Fields:[]graphql.Field{ {Name:"mean"}, {Name:"maximum"}, {Name:"median"}, {Name:"minimum"}, {Name:"mode"}, {Name:"sum"}, {Name:"type"}, }, } inPublication := graphql.Field{ Name:"inPublication", Fields:[]graphql.Field{ {Name:"pointingTo"}, {Name:"count"}, }, } // nearText nearText :=&graphql.NearTextArgumentBuilder{} nearText.WithDistance(0.85).// prior to v1.14 use WithCertainty() WithConcepts([]string{"apple iphone"}) result, err := client.GraphQL(). Aggregate(). WithFields(title, url, wordCount, inPublication). WithNearText(nearText). WithClassName("Article"). WithObjectLimit(100).// at least one of distance or objectLimit need to be set Do(context.Background()) if err !=nil{ panic(err) } fmt.Printf("%v", result) }
packageio.weaviate; importio.weaviate.client.Config; importio.weaviate.client.WeaviateClient; importio.weaviate.client.base.Result; importio.weaviate.client.v1.graphql.model.GraphQLResponse; importio.weaviate.client.v1.graphql.query.argument.NearTextArgument; importio.weaviate.client.v1.graphql.query.fields.Field; publicclassApp{ publicstaticvoidmain(String[] args){ Config config =newConfig("http","localhost:8080"); WeaviateClient client =newWeaviateClient(config); Field meta =Field.builder() .name("meta") .fields(newField[]{ Field.builder().name("count").build() }).build(); Field wordCount =Field.builder() .name("wordCount") .fields(newField[]{ Field.builder().name("mean").build(), Field.builder().name("maximum").build(), Field.builder().name("median").build(), Field.builder().name("minimum").build(), Field.builder().name("mode").build(), Field.builder().name("sum").build(), Field.builder().name("type").build() }).build(); Field inPublication =Field.builder() .name("inPublication") .fields(newField[]{ Field.builder().name("pointingTo").build(), Field.builder().name("count").build() }).build(); NearTextArgument nearText =NearTextArgument.builder() .distance(0.7f)// prior to v1.14 use .certainty() .concepts(newString[]{"pizza"}) .build(); Result<GraphQLResponse> result = client.graphQL().aggregate() .withClassName("Article") .withFields(meta, wordCount, inPublication) .withNearText(nearText) .withObjectLimit(100)// at least one of distance or objectLimit need to be set .run(); if(result.hasErrors()){ System.out.println(result.getError()); return; } System.out.println(result.getResult()); } }
# See the notes from the GraphQL example echo '{ "query": "{ Aggregate { Article(nearText:{ concepts: [\"apple iphone\"] distance: 0.7 }, objectLimit: 200) { meta { count } inPublication { pointingTo type } wordCount { count maximum mean median minimum mode sum type } } } }" }' | curl \ -X POST \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer learn-weaviate' \ -H "X-OpenAI-Api-Key: $OPENAI_API_KEY" \ -d @- \ https://edu-demo.weaviate.network/v1/graphql
{ Aggregate{ Article(nearText:{ concepts:["apple iphone"] distance:0.7# prior to v1.14 use "certainty" instead of "distance" }, objectLimit:200){# at least one of "objectLimit", meta{# and/or "distance" must be set count# when using near media filters } inPublication{ pointingTo type } wordCount{ count maximum mean median minimum mode sum type } } } }