Struct Vector

Source
pub struct Vector<T> { /* private fields */ }
Expand description

A vector that contains a vectorized data and the original data. This struct pairs the original data with its vector representation and type information.

Implementations§

Source§

impl<DynamicImage> Vector<DynamicImage>

Source

pub fn from_image(data: DynamicImage) -> Self

Initialize a new vector from image data

§Arguments
  • data - The image data to be vectorized
§Returns

A new Vector instance containing the image data

Examples found in repository?
examples/vectorize_images.rs (line 22)
16async fn main() -> Result<(), Error> {
17    // Load image
18    let image_path: &str = "./examples/images/54e2c8ea-58ef-4871-ae3f-75eabd9a2c6c.jpg";
19    let test_image: DynamicImage = image::open(image_path).unwrap();
20
21    // Create a Vector object from the image
22    let mut vector: Vector<DynamicImage> = Vector::from_image(test_image);
23
24    // Initialize client
25    let client: Client<OpenAIConfig> = Client::with_config(
26        OpenAIConfig::new()
27            .with_api_base("http://192.168.0.101:11434/v1") // comment this out if you use OpenAI instead of Ollama
28            .with_api_key("your_api_key")
29    );
30
31    // Initialize prompts
32    let prompts: Vec<String> = vec![
33        "output in json. Rate the image's offensiveness from 0.0 to 10.0. {'offensiveness': your score}".to_string(),
34        "output in json. Rate the image's friendliness from 0.0 to 10.0. {'friendliness': your score}".to_string(),
35    ];
36
37    // Initialize model parameters
38    let model_parameters = ModelParameters::new(
39        "minicpm-v".to_string(), 
40        Some(0.7), 
41        None
42    );
43
44    // Vectorize image
45    vectorize_image_concurrently(
46        prompts,
47        &mut vector, 
48        client,
49        model_parameters
50    ).await?;
51
52    // Print vectorized result
53    println!("Vector: {:?}", vector.get_vector());
54    println!("Vector Length: {:?}", vector.get_vector().len());
55
56    Ok(())
57}
Source§

impl<String> Vector<String>

Source

pub fn from_text(data: String) -> Self

Initialize a new vector from text data

§Arguments
  • data - The text data to be vectorized
§Returns

A new Vector instance containing the text data

Examples found in repository?
examples/vectorize_texts.rs (lines 13-15)
7async fn main() -> Result<(), Error> {
8    // Load text
9    let test_text: String = "Hi, this is dim. I am here to vectorize whatever your want."
10        .to_string();
11    
12    // Create a Vector object from the image
13    let mut vector: Vector<String> = Vector::from_text(
14        test_text
15    );
16    
17    // Initialize client
18    let client: async_openai::Client<async_openai::config::OpenAIConfig> = async_openai::Client::with_config(
19        async_openai::config::OpenAIConfig::new()
20            .with_api_base("http://192.168.0.101:11434/v1") // comment this out if you use OpenAI instead of Ollama
21            .with_api_key("your_api_key")
22    );
23    
24    // Initialize prompts
25    let prompts: Vec<String> = vec![
26        "Score the sentiment intensity of the text from 1 (extremely negative) to 9 (extremely positive). Consider emotional language, tone, and context. Format your response exactly like this example: {'sentiment_score': 7}".to_string(),
27        "Rate the formality of the text from 1 (highly informal, slang-heavy) to 9 (highly formal, academic/professional). Format your response exactly like this example: {'formality_score': 4}".to_string(),
28        "Assess the emotional intensity of the text from 1 (neutral/clinical) to 9 (highly emotional, passionate, or provocative). Format your response exactly like this example: {'emotional_score': 8}".to_string(),
29        "Score how subjective the text is from 1 (purely factual/objective) to 9 (heavily opinionated/subjective). Format your response exactly like this example: {'subjectivity_score': 6}".to_string(),
30        "Rate the linguistic complexity of the text from 1 (simple vocabulary/short sentences) to 9 (dense jargon/long, intricate sentences). Format your response exactly like this example: {'complexity_score': 3}".to_string(),
31        "Score the dominant intent: 1-3 (informative/educational), 4-6 (persuasive/argumentative), 7-9 (narrative/storytelling). Format your response exactly like this example: {'intent_score': 5}".to_string(),
32        "Rate how urgent or time-sensitive the text feels from 1 (no urgency) to 9 (immediate action required). Format your response exactly like this example: {'urgency_score': 2}".to_string(),
33        "Score the specificity of details from 1 (vague/abstract) to 9 (highly specific/concrete examples). Format your response exactly like this example: {'specificity_score': 7}".to_string(),
34        "Rate the politeness of the tone from 1 (rude/confrontational) to 9 (extremely polite/deferential). Format your response exactly like this example: {'politeness_score': 8}".to_string(),
35        "Categorize the text's primary domain: 1-3 (technical/scientific), 4-6 (casual/everyday), 7-9 (artistic/creative). Format your response exactly like this example: {'domain_score': 4}".to_string(),
36    ];
37
38    // Vectorize image
39    let model_parameters = ModelParameters::new("minicpm-v".to_string(), None, None);
40    vectorize_string_concurrently(
41        prompts,
42        &mut vector, 
43        client,
44        model_parameters
45    ).await?;
46
47    // Print vectorized result
48    println!("Vector: {:?}", vector.get_vector());
49    println!("Vector Length: {:?}", vector.get_vector().len());
50    
51    Ok(())
52}

Trait Implementations§

Source§

impl<T: Clone> Clone for Vector<T>

Source§

fn clone(&self) -> Vector<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Vector<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, T> Deserialize<'de> for Vector<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for Vector<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> VectorOperations<T> for Vector<T>

Source§

fn get_vector(&self) -> Vec<f32>

Get the vector representation of the data Read more
Source§

fn get_data_type(&self) -> DataType

Get the type of data stored Read more
Source§

fn get_data(&self) -> &T

Get a reference to the original data Read more
Source§

fn overwrite_vector(&mut self, vector: Vec<f32>)

Write a new vector to the vector field Read more
Source§

fn get_dimensionality(&self) -> usize

Get dimensionality of the vector Read more

Auto Trait Implementations§

§

impl<T> Freeze for Vector<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector<T>
where T: Send,

§

impl<T> Sync for Vector<T>
where T: Sync,

§

impl<T> Unpin for Vector<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<U, <U as TryFrom<T>>::Error>> + 'async_trait>>
where T: 'async_trait,

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,