| Crates.io | vectordb-client |
| lib.rs | vectordb-client |
| version | 0.2.0 |
| created_at | 2025-04-16 11:08:59.62419+00 |
| updated_at | 2025-04-19 04:58:15.015905+00 |
| description | Client library for interacting with the VectorDB semantic code search service. |
| homepage | https://gitlab.com/amulvany/vectordb-cli |
| repository | https://gitlab.com/amulvany/vectordb-cli |
| max_upload_size | |
| id | 1636321 |
| size | 88,048 |
A Rust client library for interacting with the VectorDB semantic code search service.
Add the dependency to your Cargo.toml:
[dependencies]
vectordb-client = "0.1.0"
tokio = { version = "1.0", features = ["full"] }
use vectordb_client::VectorDBClient;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Create a client with default configuration (localhost:50051)
let mut client = VectorDBClient::default().await?;
// Get server info
let server_info = client.get_server_info().await?;
println!("Connected to server version: {}", server_info.version);
// List collections
let collections = client.list_collections().await?;
println!("Available collections:");
for collection in collections.collections {
println!(" - {}", collection);
}
// Create a test collection
let result = client.create_collection(
"test_collection".to_string(),
384,
"cosine".to_string()
).await?;
if result.success {
println!("Collection created successfully");
} else {
println!("Failed to create collection: {}", result.message);
}
Ok(())
}
use vectordb_client::{VectorDBClient, ClientConfig};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Create a custom client configuration
let config = ClientConfig::new("http://my-server.example.com:50051")
.with_tls(true)
.with_api_key("my-api-key");
// Connect with the custom configuration
let mut client = VectorDBClient::new(config).await?;
// Use the client...
Ok(())
}
use vectordb_client::VectorDBClient;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut client = VectorDBClient::default().await?;
// Edit a specific function by element name
let result = client.edit_file_by_element(
"src/main.rs".to_string(), // File path
"function:process_data".to_string(), // Element query
"fn process_data(input: &str) -> String {\n // Add better documentation\n format!(\"processed: {}\", input)\n}".to_string(), // New content
true, // Format the code
false, // Don't update references
).await?;
if result.success {
println!("Edit applied successfully!");
} else {
println!("Edit failed: {}", result.error_message.unwrap_or_default());
}
// Edit specific lines in a file
let result = client.edit_file_by_lines(
"src/lib.rs".to_string(), // File path
10, 15, // Start and end line (inclusive)
" // Replace these lines with a comment".to_string(), // New content
false, // Don't format
false, // Don't update references
).await?;
if result.success {
println!("Line edit applied successfully!");
} else {
println!("Line edit failed: {}", result.error_message.unwrap_or_default());
}
Ok(())
}
The client provides methods for all VectorDB operations:
get_server_info() - Get information about the servercreate_collection(name, vector_size, distance) - Create a new collectionlist_collections() - List all collectionsdelete_collection(name) - Delete a collectionclear_collection(name) - Clear a collectionindex_files(collection_name, paths, extensions) - Index files into a collectionquery_collection(collection_name, query_text, limit, language, element_type) - Search a collectionadd_repository(url, local_path, name, branch, remote, ssh_key_path, ssh_passphrase) - Add a Git repositorylist_repositories() - List all repositoriesuse_repository(name) - Set the active repositoryremove_repository(name, skip_confirmation) - Remove a repositorysync_repository(name, extensions, force) - Sync a repositoryuse_branch(branch_name, repository_name) - Set the active branchedit_file_by_lines(file_path, start_line, end_line, content, format, update_references) - Edit a file by line rangeedit_file_by_element(file_path, element_query, content, format, update_references) - Edit a semantic elementvalidate_edit_by_lines(file_path, start_line, end_line, content, format, update_references) - Validate a line editvalidate_edit_by_element(file_path, element_query, content, format, update_references) - Validate an element editWhen targeting semantic elements, use the following syntax:
function:name - Target a functionclass:ClassName - Target a classmethod:ClassName.method_name - Target a class methodstruct:StructName - Target a struct (Rust)impl:StructName - Target an implementation block (Rust)This project is licensed under the MIT License.