Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
NUMBER_OF_DATABASE=3
DATABASE_PATH1=Enter-path-1-here
DATABASE_NAME1=Enter-name-1-here
DATABASE_PATH2=Enter-path-2-here
DATABASE_NAME2=Enter-name-2-here
DATABASE_PATH3=Enter-path-3-here
DATABASE_NAME3=Enter-name-3-here
# HTTP Server
HTTP_HOST=127.0.0.1
HTTP_PORT=3000

# gRPC Server
GRPC_HOST=127.0.0.1
GRPC_PORT=50051
# required
GRPC_ROOT_PASSWORD=your-secure-password

# Database Configuration
# Storage: inmemory, rocksdb
# Index: flat, kdtree, hnsw
STORAGE_TYPE=rocksdb
INDEX_TYPE=flat
DIMENSION=512

DATA_PATH=./data

# Server Options
LOGGING=true
DISABLE_HTTP=false

# Embedding Services (TUI)
TEXT_EMBEDDING_URL=http://localhost:8080/vectors
IMAGE_EMBEDDING_URL=http://localhost:8080/vectors_img
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/data/
.TODO
/databases
.env
86 changes: 53 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ members = [
"crates/storage",
"crates/index",
"crates/server",
"crates/http_server",
"crates/http",
"crates/tui",
"crates/grpc_server",
"crates/grpc",
]

# You can define shared dependencies for all crates here
Expand Down
1 change: 1 addition & 0 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl VectorDb {
}
}

#[derive(Debug)]
pub struct DbConfig {
pub storage_type: StorageType,
pub index_type: IndexType,
Expand Down
3 changes: 3 additions & 0 deletions crates/defs/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ impl std::fmt::Display for DbError {
}

impl std::error::Error for DbError {}

// Error type for server
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
2 changes: 1 addition & 1 deletion crates/grpc_server/Cargo.toml → crates/grpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "grpc_server"
name = "grpc"
version = "0.1.0"
edition = "2024"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions crates/grpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pub mod constants;
pub mod errors;
pub mod interceptors;
pub mod service;
pub mod utils;

use api::VectorDb;
use defs::BoxError;
use service::{VectorDBService, run_server};
use std::net::SocketAddr;
use std::sync::Arc;
use utils::ServerEndpoint;

/// Runs the gRPC server on the specified address.
pub async fn run_grpc_server(
db: Arc<VectorDb>,
addr: SocketAddr,
root_password: String,
logging: bool,
) -> Result<(), BoxError> {
let vector_db_service = VectorDBService::new(db, logging);
run_server(
vector_db_service,
ServerEndpoint::Address(addr),
root_password,
)
.await
.map_err(|e| -> BoxError { e.to_string().into() })
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::str::FromStr;
use std::sync::Arc;

use crate::interceptors;
use crate::service::vectordb::{ContentType, Uuid};
Expand All @@ -18,10 +19,16 @@ pub mod vectordb {
}

pub struct VectorDBService {
pub vector_db: api::VectorDb,
pub vector_db: Arc<api::VectorDb>,
pub logging: bool,
}

impl VectorDBService {
pub fn new(vector_db: Arc<api::VectorDb>, logging: bool) -> Self {
Self { vector_db, logging }
}
}

#[tonic::async_trait]
impl VectorDb for VectorDBService {
async fn insert_vector(
Expand Down
22 changes: 5 additions & 17 deletions crates/grpc_server/src/tests.rs → crates/grpc/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
use crate::config::GRPCServerConfig;
use crate::constants::AUTHORIZATION_HEADER_KEY;
use crate::service::vectordb::vector_db_client::VectorDbClient;
use crate::service::vectordb::{DenseVector, InsertVectorRequest, Payload, PointId, SearchRequest};
use crate::service::{VectorDBService, run_server};
use crate::utils::ServerEndpoint;
use api;
use api::DbConfig;
use index::IndexType;
use std::net::SocketAddr;
use std::sync::Arc;
use storage::StorageType;
use tempfile::tempdir;
use tokio;
use tonic::transport::Channel;

// Inspired from https://github.com/hyperium/tonic/discussions/924#discussioncomment-9854088
Expand All @@ -35,28 +33,18 @@ async fn start_test_server() -> Result<SocketAddr, Box<dyn std::error::Error>> {
dimension: 3,
};

let config = GRPCServerConfig {
addr: "127.0.0.1:0".parse()?,
root_password: TEST_AUTH_BEARER_TOKEN.to_string(),
logging: false,
db_config,
};

let vector_db_api = api::init_api(config.db_config)?;
let vector_db_api = api::init_api(db_config)?;

let vector_db_service = VectorDBService {
vector_db: vector_db_api,
logging: config.logging,
};
let vector_db_service = VectorDBService::new(Arc::new(vector_db_api), false);

let listener = tokio::net::TcpListener::bind(config.addr).await?;
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?;
let listener_addr = listener.local_addr()?;

tokio::spawn(async move {
let _ = run_server(
vector_db_service,
ServerEndpoint::Listener(listener),
config.root_password,
TEST_AUTH_BEARER_TOKEN.to_string(),
)
.await
.inspect_err(|err| panic!("Could not start test server : {:?}", err));
Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions crates/grpc_server/.sample.env

This file was deleted.

Loading
Loading