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.
jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects() for o in response.objects: print(o.properties)
const myCollection = client.collections.use('JeopardyQuestion'); const result =await myCollection.query.fetchObjects() console.log(JSON.stringify(result,null,2));
var jeopardy = client.Collections.Use("JeopardyQuestion"); var response =await jeopardy.Query.FetchObjects(); foreach(var o in response.Objects) { Console.WriteLine(JsonSerializer.Serialize(o.Properties)); }
{ Get{ JeopardyQuestion{ question } } }
Example response
The output is like this:
{ "data":{ "Get":{ "JeopardyQuestion":[ { "question":"This prophet passed the time he spent inside a fish offering up prayers" }, // shortened for brevity ] } } }
Additional information
Specify the information that you want your query to return. You can return object properties, object IDs, and object metadata.
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.
jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( limit=1 ) for o in response.objects: print(o.properties)
CollectionHandle<Map<String,Object>> jeopardy = client.collections.use("JeopardyQuestion"); var response = jeopardy.query.fetchObjects( q -> q.limit(1) ); for(var o : response.objects()){ System.out.println(o.properties()); }
Result<List<WeaviateObject>> resultObj = client.data().objectsGetter() .withClassName(className) .withLimit(1)// Object IDs are included by default with the Java client .run();
var jeopardy = client.Collections.Use<Dictionary<string,object>>("JeopardyQuestion"); var response =await jeopardy.Query.FetchObjects( limit:1 ); foreach(var o in response.Objects) { Console.WriteLine(JsonSerializer.Serialize(o.Properties)); }
{ "data":{ "Get":{ "JeopardyQuestion":[ { "question":"This prophet passed the time he spent inside a fish offering up prayers" }, // Note this will only have one result as we limited it to 1 ] } } }
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.
jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( limit=1, offset=1 ) for o in response.objects: print(o.properties)
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.
jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( limit=1, return_properties=["question","answer","points"] ) for o in response.objects: print(o.properties)
var jeopardy = client.Collections.Use<Dictionary<string,object>>("JeopardyQuestion"); var response =await jeopardy.Query.FetchObjects( limit:1, returnProperties:new[]{"question","answer","points"} ); foreach(var o in response.Objects) { Console.WriteLine(JsonSerializer.Serialize(o.Properties)); }
{ "data":{ "Get":{ "JeopardyQuestion":[ { "answer":"Jonah", "points":100, "question":"This prophet passed the time he spent inside a fish offering up prayers" }, ] } } }
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.
var jeopardy = client.Collections.Use<Dictionary<string,object>>("JeopardyQuestion"); var response =await jeopardy.Query.FetchObjects( returnMetadata:(MetadataOptions.Vector,["default"]), limit:1 ); // Note: The C# client returns a dictionary of named vectors. // We assume the default vector name is 'default'. //TODO[g-despot]: Why is vector not returned? Console.WriteLine("Vector for 'default':"); Console.WriteLine(JsonSerializer.Serialize(response.Objects.First()));
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.
jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( # Object IDs are included by default with the `v4` client! :) limit=1 ) for o in response.objects: print(o.uuid)
const myCollection = client.collections.use('JeopardyQuestion'); const result =await myCollection.query.fetchObjects({ // Object IDs are included by default with the `v3` client! :) limit:1, }) for(let object of result.objects){ console.log(JSON.stringify(object.uuid,null,2)); }
CollectionHandle<Map<String,Object>> jeopardy = client.collections.use("JeopardyQuestion"); var response = jeopardy.query.fetchObjects( // Object IDs are included by default with the v6 client! :) q -> q.limit(1)); for(var o : response.objects()){ System.out.println(o.uuid()); }
Queries involving cross-references can be slower than queries that do not involve cross-references, especially at scale such as for multiple objects or complex queries.
At the first instance, we strongly encourage you to consider whether you can avoid using cross-references in your data schema. As a scalable AI database, Weaviate is well-placed to perform complex queries with vector, keyword and hybrid searches involving filters. You may benefit from rethinking your data schema to avoid cross-references where possible.
For example, instead of creating separate "Author" and "Book" collections with cross-references, consider embedding author information directly in Book objects and using searches and filters to find books by author characteristics.
To retrieve properties from cross-referenced objects, specify:
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.
from weaviate.classes.query import QueryReference jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( return_references=[ QueryReference( link_on="hasCategory", return_properties=["title"] ), ], limit=2 ) for o in response.objects: print(o.properties["question"]) # print referenced objects for ref_obj in o.references["hasCategory"].objects: print(ref_obj.properties)
{ "data":{ "Get":{ "JeopardyQuestion":[ { "hasCategory":[{"title":"THE BIBLE"}], "question":"This prophet passed the time he spent inside a fish offering up prayers", }, { "hasCategory":[{"title":"ANIMALS"}], "question":"Pythons are oviparous, meaning they do this", }, ] } } }
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.
from weaviate.classes.query import MetadataQuery jeopardy = client.collections.use("JeopardyQuestion") response = jeopardy.query.fetch_objects( limit=1, return_metadata=MetadataQuery(creation_time=True) ) for o in response.objects: print(o.properties)# View the returned properties print(o.metadata.creation_time)# View the returned creation time
const myCollection = client.collections.use('JeopardyQuestion'); const result =await myCollection.query.fetchObjects({ limit:2, returnMetadata:['creationTime',] }) for(let object of result.objects){ console.log(JSON.stringify(object.properties,null,2)); console.log(JSON.stringify(object.metadata?.creationTime,null,2)); }
CollectionHandle<Map<String,Object>> jeopardy = client.collections.use("JeopardyQuestion"); var response = jeopardy.query.fetchObjects( q -> q .limit(1) .returnMetadata(Metadata.CREATION_TIME_UNIX) ); for(var o : response.objects()){ System.out.println(o.properties());// View the returned properties System.out.println(o.metadata().creationTimeUnix());// View the returned creation time }
var jeopardy = client.Collections.Use<Dictionary<string,object>>("JeopardyQuestion"); var response =await jeopardy.Query.FetchObjects( limit:1, returnMetadata: MetadataOptions.CreationTime ); foreach(var o in response.Objects) { Console.WriteLine(JsonSerializer.Serialize(o.Properties));// View the returned properties Console.WriteLine(o.Metadata.CreationTime);// View the returned creation time }
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.
# Connect to the collection mt_collection = client.collections.use("WineReviewMT") # Get the specific tenant's version of the collection collection_tenant_a = mt_collection.with_tenant("tenantA") # Query tenantA's version response = collection_tenant_a.query.fetch_objects( return_properties=["review_body","title"], limit=1, ) print(response.objects[0].properties)
// Connect to the collection CollectionHandle<Map<String,Object>> mtCollection = client.collections.use("WineReviewMT"); // Get the specific tenant's version of the collection var collectionTenantA = mtCollection.withTenant("tenantA"); // Query tenantA's version var response = collectionTenantA.query.fetchObjects( q -> q .returnProperties("review_body","title") .limit(1)); if(!response.objects().isEmpty()){ System.out.println(response.objects().get(0).properties()); }
var mtCollection = client.Collections.Use<Dictionary<string,object>>("WineReviewMT"); // In the C# client, the tenant is specified directly in the query method // rather than creating a separate tenant-specific collection object. var response =await mtCollection.Query.FetchObjects( tenant:"tenantA", returnProperties:new[]{"review_body","title"}, limit:1 ); Console.WriteLine(JsonSerializer.Serialize(response.Objects.First().Properties));
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.
from weaviate.classes.config import ConsistencyLevel questions = client.collections.use(collection_name).with_consistency_level( consistency_level=ConsistencyLevel.QUORUM ) response = collection.query.fetch_object_by_id("36ddd591-2dee-4e7e-a3cc-eb86d30a4303") # The parameter passed to `withConsistencyLevel` can be one of: # * 'ALL', # * 'QUORUM' (default), or # * 'ONE'. # # It determines how many replicas must acknowledge a request # before it is considered successful. for o in response.objects: print(o.properties)# Inspect returned objects
const myCollection = client.collections.use('Article').withConsistency('QUORUM'); const result =await myCollection.query.fetchObjectById("36ddd591-2dee-4e7e-a3cc-eb86d30a4303") console.log(JSON.stringify(result,null,2)); // The parameter passed to `withConsistencyLevel` can be one of: // * 'ALL', // * 'QUORUM' (default), or // * 'ONE'. // // It determines how many replicas must acknowledge a request // before it is considered successful.
package main import( "context" "fmt" "github.com/weaviate/weaviate-go-client/v5/weaviate/data/replication"// for consistency levels "github.com/weaviate/weaviate-go-client/v5/weaviate" ) funcmain(){ cfg := weaviate.Config{ Host:"localhost:8080", Scheme:"http", } client, err := weaviate.NewClient(cfg) if err !=nil{ panic(err) } data, err := client.Data().ObjectsGetter(). WithClassName("MyClass"). WithID("36ddd591-2dee-4e7e-a3cc-eb86d30a4303"). WithConsistencyLevel(replication.ConsistencyLevel.ONE).// default QUORUM Do(context.Background()) if err !=nil{ panic(err) } fmt.Printf("%v", data) } // The parameter passed to "WithConsistencyLevel" can be one of: // * replication.ConsistencyLevel.ALL, // * replication.ConsistencyLevel.QUORUM (default), or // * replication.ConsistencyLevel.ONE. // // It determines how many replicas must acknowledge a request // before it is considered successful.
CollectionHandle<Map<String,Object>> jeopardy = client.collections.use("JeopardyQuestion") .withConsistencyLevel(ConsistencyLevel.QUORUM); var response = jeopardy.query.fetchObjects(c -> c.where(Where.uuid().eq("36ddd591-2dee-4e7e-a3cc-eb86d30a4303"))); for(var o : response.objects()){ System.out.println(o.properties()); }
packageio.weaviate; importjava.util.List; importio.weaviate.client.Config; importio.weaviate.client.WeaviateClient; importio.weaviate.client.base.Result; importio.weaviate.client.v1.data.model.WeaviateObject; importio.weaviate.client.v1.data.replication.model.ConsistencyLevel; publicclassApp{ publicstaticvoidmain(String[] args){ Config config =newConfig("http","localhost:8080"); WeaviateClient client =newWeaviateClient(config); Result<List<WeaviateObject>> result = client.data().objectsGetter() .withClassName("MyClass") .withID("36ddd591-2dee-4e7e-a3cc-eb86d30a4303") .withConsistencyLevel(ConsistencyLevel.ONE)// default QUORUM .run(); if(result.hasErrors()){ System.out.println(result.getError()); return; } System.out.println(result.getResult()); } } // The parameter passed to `withConsistencyLevel` can be one of: // * ConsistencyLevel.ALL, // * ConsistencyLevel.QUORUM (default), or // * ConsistencyLevel.ONE. // // It determines how many replicas must acknowledge a request // before it is considered successful.
var jeopardy = client.Collections.Use<Dictionary<string,object>>("JeopardyQuestion").WithConsistencyLevel(ConsistencyLevels.Quorum); var response =await jeopardy.Query.FetchObjectByID( Guid.Parse("36ddd591-2dee-4e7e-a3cc-eb86d30a4303") ); // The parameter passed to `withConsistencyLevel` can be one of: // * 'ALL', // * 'QUORUM' (default), or // * 'ONE'. // // It determines how many replicas must acknowledge a request // before it is considered successful. Console.WriteLine(response);
curl "http://localhost:8080/v1/objects/MyClass/36ddd591-2dee-4e7e-a3cc-eb86d30a4303?consistency_level=QUORUM" # The parameter "consistency_level" can be one of ALL, QUORUM (default), or ONE. Determines how many # replicas must acknowledge a request before it is considered successful. # curl "/v1/objects/{ClassName}/{id}?consistency_level=ONE"