Skip to main content

Crate lvv_macros

Crate lvv_macros 

Source
Expand description

Derive macros for lvv, turning Rust structs into vector points.

  • VectorDatabaseItem makes a record type produce one point: the text to embed, a category, and the payload stored next to the vector.
  • VectorDatabase makes a container struct produce the points of every item it holds.

Both implement traits from lvv::points. The generated code refers to ::lvv, so the crate using the derives must depend on lvv under that name. Enable lvv’s derive feature instead of depending on this crate directly; it re-exports both macros next to the traits they implement:

[dependencies]
lvv = { version = "0.5", features = ["derive"] }
serde = { version = "1", features = ["derive"] }

§Example

ⓘ
use lvv::points::{VectorDatabase, VectorDatabaseItem};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, VectorDatabaseItem)]
struct Project {
    #[lvv(description)]
    name: String,
    #[lvv(description)]
    summary: String,
    #[lvv(rename = "stack")]
    technologies: Vec<String>,
    #[lvv(skip)]
    private_notes: String,
}

#[derive(VectorDatabase)]
struct Portfolio {
    projects: Vec<Project>,
    featured: Option<Project>,
    #[lvv(skip)]
    owner: String,
}

for draft in portfolio.point_drafts()? {
    // Embed `draft.description`, store `draft.payload` next to the vector.
    println!("{}: {}", draft.category, draft.description);
}

For a complete lvv pipeline built on these derives, from reading files to writing Qdrant collections, see lvv’s examples/derive.rs.

Derive Macros§

VectorDatabase
Derives VectorDatabase for a struct whose fields hold VectorDatabaseItems.
VectorDatabaseItem
Derives VectorDatabaseItem for a struct, so each value becomes one vector point.