pub struct Document {
pub id: PointId,
pub text: String,
pub metadata: JsonObject,
}Expand description
A text document with a typed ID and optional JSON metadata.
Fields§
§id: PointIdStable document identifier.
text: StringText embedded for similarity search.
metadata: JsonObjectApplication-defined metadata stored with the text.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(id: impl Into<PointId>, text: impl Into<String>) -> Self
pub fn new(id: impl Into<PointId>, text: impl Into<String>) -> Self
Creates a document with empty metadata.
Examples found in repository?
examples/text.rs (line 30)
25fn main() -> git_vdb::Result<()> {
26 let temporary = tempfile::TempDir::new()?;
27 let db = open(temporary.path().join("documents.git"))?;
28 let docs = db.text_collection("docs", ExampleEmbedder)?;
29 docs.upsert_documents([
30 Document::new("east", "A document about the east"),
31 Document::new("north", "A document about the north"),
32 ])?;
33 assert_eq!(
34 docs.search_text("north wind", 1)?[0].id.to_string(),
35 "north"
36 );
37 Ok(())
38}More examples
examples/text_fastembed.rs (line 10)
5fn main() -> git_vdb::Result<()> {
6 let temporary = tempfile::TempDir::new()?;
7 let db = open(temporary.path().join("documents.git"))?;
8 let docs = db.text_collection("docs", FastEmbedder::try_new()?)?;
9 docs.upsert_documents([
10 Document::new("git", "Git-native vector search"),
11 Document::new("fruit", "Fresh fruit at the market"),
12 ])?;
13 let hits = docs.search_text("versioned database search", 1)?;
14 println!("{}", hits[0].id);
15 Ok(())
16}Sourcepub fn with_metadata(self, metadata: impl Serialize) -> Result<Self>
pub fn with_metadata(self, metadata: impl Serialize) -> Result<Self>
Serializes object-shaped document metadata.
Trait Implementations§
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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