Crate tcvectordb_rust

Source
Expand description

§Tencent VectorDB Rust SDK

Rust SDK for Tencent Cloud VectorDB.

§Features

  • Database and collection management
  • Document CRUD operations
  • Vector similarity search
  • Index management
  • Filter support

§Example

use tcvectordb_rust::{VectorDBClient, Document, Index, VectorIndex, FilterIndex};
use tcvectordb_rust::enums::{IndexType, MetricType, FieldType, ReadConsistency};
 
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = VectorDBClient::new(
        "http://localhost:8100",
        "root",
        "your-api-key",
        ReadConsistency::EventualConsistency,
        30,
    )?;
 
    // Create database
    let db = client.create_database("test_db").await?;
 
    // Create collection with index
    let mut index = Index::new();
    index.add_vector_index(VectorIndex::new(
        "vector",
        3,
        IndexType::HNSW,
        MetricType::COSINE,
        None,
    ));
    index.add_filter_index(FilterIndex::new(
        "id",
        FieldType::String,
        IndexType::PRIMARY_KEY,
    ));
 
    let collection = db.create_collection(
        "test_collection",
        3,
        2,
        Some("Test collection"),
        Some(index),
        None,
        None,
    ).await?;
 
    // Upsert documents
    let documents = vec![
        Document::new()
            .with_id("doc1")
            .with_vector(vec![0.1, 0.2, 0.3])
            .with_field("title", "Document 1"),
    ];
 
    collection.upsert(documents, None, true).await?;
 
    // Search similar vectors
    let results = collection.search(
        vec![vec![0.1, 0.2, 0.3]],
        None,
        None,
        false,
        10,
        None,
        None,
        None,
    ).await?;
 
    println!("Search results: {:?}", results);
 
    Ok(())
}

Re-exports§

pub use client::VectorDBClient;
pub use database::Database;
pub use collection::Collection;
pub use document::Document;
pub use index::Index;
pub use index::VectorIndex;
pub use index::FilterIndex;
pub use index::SparseIndex;
pub use error::VectorDBError;
pub use error::Result;
pub use filter::Filter;

Modules§

client
collection
database
document
enums
error
filter
index