Skip to main content

we_trust_vector/
lib.rs

1#![warn(missing_docs)]
2
3pub mod codec;
4pub use codec::{VectorCodec, VectorSearchRequest, VectorSearchResponse};
5
6use futures::{SinkExt, StreamExt};
7use tokio::net::TcpStream;
8use tokio_util::codec::Framed;
9use tracing::{error, info};
10use yykv_types::DsError;
11
12pub type Result<T> = std::result::Result<T, DsError>;
13
14/// 使用 tokio Framed 完全重写的 Vector 搜索连接处理器
15pub async fn handle_connection(stream: TcpStream) -> Result<()> {
16    let mut framed = Framed::new(stream, VectorCodec);
17    info!("New Vector connection established");
18
19    while let Some(result) = framed.next().await {
20        match result {
21            Ok(req) => {
22                info!(
23                    "Received Vector search request for collection: {}, dim: {}",
24                    req.collection,
25                    req.vector.len()
26                );
27                let resp = VectorSearchResponse {
28                    ids: vec![],
29                    scores: vec![],
30                };
31                framed.send(resp).await?;
32            }
33            Err(e) => {
34                error!("Vector protocol error: {}", e);
35                break;
36            }
37        }
38    }
39
40    Ok(())
41}