Struct weaviate_community::Objects
source · pub struct Objects { /* private fields */ }
Expand description
All objects endpoints and functionality described in Weaviate objects API documentation
Implementations§
source§impl Objects
impl Objects
sourcepub async fn list(
&self,
parameters: ObjectListParameters
) -> Result<MultiObjects, Box<dyn Error>>
pub async fn list( &self, parameters: ObjectListParameters ) -> Result<MultiObjects, Box<dyn Error>>
List the data objects.
§Parameters
- parameters: the ObjectListParameters to use in the request.
§Example
use weaviate_community::WeaviateClient;
use weaviate_community::collections::objects::ObjectListParameters;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
//let params = ObjectListParameters::builder().with_class_name("MyClass").build();
let params = ObjectListParameters::new();
let res = client.objects.list(params).await?;
Ok(())
}
sourcepub async fn create(
&self,
new_object: &Object,
consistency_level: Option<ConsistencyLevel>
) -> Result<Object, Box<dyn Error>>
pub async fn create( &self, new_object: &Object, consistency_level: Option<ConsistencyLevel> ) -> Result<Object, Box<dyn Error>>
Create a new data object. The provided meta-data and schema values are validated.
When inserting a large number of objects, it is more efficient to use the batch
insert
methods.
§Parameters
- new_object: the new object to create
- consistency_level: the consistency_level of the new object
§Example
use weaviate_community::WeaviateClient;
use weaviate_community::collections::objects::Object;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let properties = serde_json::json!({
"name": "Jodi Kantor",
});
let new = Object::builder("Publication", properties).build();
let res = client.objects.create(
&new,
None
);
Ok(())
}
sourcepub async fn get(
&self,
class_name: &str,
id: &Uuid,
include: Option<&str>,
consistency_level: Option<ConsistencyLevel>,
tenant_key: Option<&str>
) -> Result<Object, Box<dyn Error>>
pub async fn get( &self, class_name: &str, id: &Uuid, include: Option<&str>, consistency_level: Option<ConsistencyLevel>, tenant_key: Option<&str> ) -> Result<Object, Box<dyn Error>>
Collect an individual data object given it’s UUID.
§Parameters
- class_name: the name of the class that the object belongs to
- id: the uuid of the object
- include: extra fields to include (classification, vector)
- consistency_level: the consistency_level of the object
- tenant_key: the tenant that the object is associated with
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid = Uuid::parse_str("ee22d1b8-3b95-4e94-96d5-9a2b60fbd303").unwrap();
let res = client
.objects
.get("TestListObject", &uuid, None, None, None).await;
Ok(())
}
sourcepub async fn exists(
&self,
class_name: &str,
id: &Uuid,
consistency_level: Option<ConsistencyLevel>,
tenant_name: Option<&str>
) -> Result<bool, Box<dyn Error>>
pub async fn exists( &self, class_name: &str, id: &Uuid, consistency_level: Option<ConsistencyLevel>, tenant_name: Option<&str> ) -> Result<bool, Box<dyn Error>>
Check if a data object exists without returning the object itself.
This works the same as the get
method, but uses HEAD
HTTP method.
§Parameters
- class_name: the class name of the object to check for
- id: the uuid of the object
- consistency_level: the consistency_level of the object
- tenant_name: the name of the tenant the object is associated with
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid = Uuid::parse_str("ee22d1b8-3b95-4e94-96d5-9a2b60fbd303").unwrap();
let res = client
.objects
.exists("TestListObject", &uuid, None, None).await;
Ok(())
}
sourcepub async fn update(
&self,
properties: &Value,
class_name: &str,
id: &Uuid,
consistency_level: Option<ConsistencyLevel>
) -> Result<bool, Box<dyn Error>>
pub async fn update( &self, properties: &Value, class_name: &str, id: &Uuid, consistency_level: Option<ConsistencyLevel> ) -> Result<bool, Box<dyn Error>>
Updates the given property values of the data object.
To replace all property values, use the replace
method.
Note that if the class is configured with a vectorizer, Weaviate will only compute a new vector for an updated object if the update changes the underlying text to be vectorized.
§Parameters
- properties: the properties to update the object with
- class_name: the name of the class the object belongs to
- id: the uuid of the object
- consistency_level: the consistency_level of the object
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid = Uuid::parse_str("ee22d1b8-3b95-4e94-96d5-9a2b60fbd303").unwrap();
let properties = serde_json::json!({
"name": "new name",
});
let res = client
.objects
.update(&properties, "Article", &uuid, None).await;
Ok(())
}
sourcepub async fn replace(
&self,
properties: &Value,
class_name: &str,
id: &Uuid,
consistency_level: Option<ConsistencyLevel>
) -> Result<Object, Box<dyn Error>>
pub async fn replace( &self, properties: &Value, class_name: &str, id: &Uuid, consistency_level: Option<ConsistencyLevel> ) -> Result<Object, Box<dyn Error>>
Replaces all property values of the data object.
Use the update
method if only modifying some properties.
Note that if the class is configured with a vectorizer, Weaviate will only compute a new vector for an updated object if the update changes the underlying text to be vectorized.
§Parameters
- properties: the properties to replace with
- class_name: the name of the class the object belongs to
- id: the uuid of the object to replace
- consistency_level: the consistency_level of the object
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid = Uuid::parse_str("ee22d1b8-3b95-4e94-96d5-9a2b60fbd303").unwrap();
let properties = serde_json::json!({
"properties": {
"name": "Jodi Kantor",
}
});
let res = client
.objects
.replace(&properties, "Publication", &uuid, None).await;
Ok(())
}
sourcepub async fn delete(
&self,
class_name: &str,
id: &Uuid,
consistency_level: Option<ConsistencyLevel>,
tenant_name: Option<&str>
) -> Result<bool, Box<dyn Error>>
pub async fn delete( &self, class_name: &str, id: &Uuid, consistency_level: Option<ConsistencyLevel>, tenant_name: Option<&str> ) -> Result<bool, Box<dyn Error>>
Delete an individual data object from Weaviate.
§Parameters
- class_name: the name of the class the object belongs to
- id: the uuid of the object to delete
- consistency_level: the consistency_level of the object
- tenant_name: the name of the tenant the object is associated to
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid = Uuid::parse_str("ee22d1b8-3b95-4e94-96d5-9a2b60fbd303").unwrap();
let res = client
.objects
.delete("Article", &uuid, None, None)
.await;
Ok(())
}
sourcepub async fn validate(
&self,
class_name: &str,
properties: &Value,
id: &Uuid
) -> Result<bool, Box<dyn Error>>
pub async fn validate( &self, class_name: &str, properties: &Value, id: &Uuid ) -> Result<bool, Box<dyn Error>>
Validate an object’s schema and metadata without creating it.
§Parameters
- class_name: the name of the class you want to validate against
- properties: the properties you want to validate
- id: the uuid you want to set the new object
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let properties = serde_json::json!({
"name": "New York Times"
});
let uuid = Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap();
let res = client.objects.validate("Publication", &properties, &uuid).await;
Ok(())
}
sourcepub async fn reference_add(
&self,
reference: Reference
) -> Result<bool, Box<dyn Error>>
pub async fn reference_add( &self, reference: Reference ) -> Result<bool, Box<dyn Error>>
Add a reference to the array of cross-references of the given property in the source object specified by its class name and id.
More on cross-references can be found here
§Parameters
- from_class_name: the class to add the beacon to
- from_uuid: the uuid of the object to add the beacon to
- from_property_name: the name of the property the beacon should be added to
- to_class_name: the name of the class to beacon to
- to_uuid: the uuid of the object you want to create a beacon to
- consistency_level: the consistency level to set
- tenant_name: the name of the tenant the
from_uuid
belongs to
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
use weaviate_community::collections::objects::Reference;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid1 = Uuid::parse_str("12345678-1234-1234-1234-123456789012")?;
let uuid2 = Uuid::parse_str("20ffc68d-986b-5e71-a680-228dba18d7ef")?;
let reference = Reference::new(
"JeopardyQuestion",
&uuid1,
"hasCategory",
"JeopardyCategory",
&uuid2,
);
let res = client.objects.reference_add(reference).await;
Ok(())
}
sourcepub async fn reference_update(
&self,
from_class_name: &str,
from_uuid: &Uuid,
from_property_name: &str,
to_class_names: Vec<&str>,
to_uuids: Vec<&Uuid>,
consistency_level: Option<ConsistencyLevel>,
tenant_name: Option<&str>
) -> Result<Object, Box<dyn Error>>
pub async fn reference_update( &self, from_class_name: &str, from_uuid: &Uuid, from_property_name: &str, to_class_names: Vec<&str>, to_uuids: Vec<&Uuid>, consistency_level: Option<ConsistencyLevel>, tenant_name: Option<&str> ) -> Result<Object, Box<dyn Error>>
Update all references in a specified property of an object specified by its class name and id.
Requires the same length of to_class_names as to_uuids as input.
§Parameters
- from_class_name: the class that has the beacons
- from_uuid: the uuid of the object to update the beacons of
- from_property_name: the name of the property containing the beacons
- to_class_names: the names of the classes to beacon to
- to_uuids: the uuids of the objects you want to update the beacons to
- consistency_level: the consistency level to set
- tenant_name: the name of the tenant the
from_uuid
belongs to
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid1 = Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap();
let uuid2 = Uuid::parse_str("20ffc68d-986b-5e71-a680-228dba18d7ef").unwrap();
let res = client.objects.reference_update(
"JeopardyQuestion",
&uuid1,
"hasCategory",
vec!["JeopardyCategory"],
vec![&uuid2],
None,
None
).await;
Ok(())
}
sourcepub async fn reference_delete(
&self,
reference: Reference
) -> Result<bool, Box<dyn Error>>
pub async fn reference_delete( &self, reference: Reference ) -> Result<bool, Box<dyn Error>>
Delete the single reference that is given in the body from the list of references that the specified property of a given object has, if it exists in the list. Will return true both when the reference existed, and when it didn’t.
§Parameters
- from_class_name: the class that has the beacons
- from_uuid: the uuid of the object to update the beacons of
- from_property_name: the name of the property containing the beacons
- to_class_name: the names of the class to remove beacon to
- to_uuid: the uuid of the object you want to remove the beacon to
- consistency_level: the consistency level to set
- tenant_name: the name of the tenant the
from_uuid
belongs to
§Example
use uuid::Uuid;
use weaviate_community::WeaviateClient;
use weaviate_community::collections::objects::Reference;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = WeaviateClient::builder("http://localhost:8080").build()?;
let uuid1 = Uuid::parse_str("12345678-1234-1234-1234-123456789012").unwrap();
let uuid2 = Uuid::parse_str("20ffc68d-986b-5e71-a680-228dba18d7ef").unwrap();
let reference = Reference::new(
"JeopardyQuestion",
&uuid1,
"hasCategory",
"JeopardyCategory",
&uuid2,
);
let res = client.objects.reference_delete(reference).await;
Ok(())
}