List connected clients
List every client currently connected to the server.
Every operation works on both Vector DB stores (you supply raw vectors) and AI stores (you supply text or images and Ahnlich AI generates the embeddings for you). Use the Vector DB / AI switch in the sample below.
Parameters
This request takes no arguments.
Behavior
- The server returns information about all active client connections, including their addresses.
Sample query
- Database engine
- AI proxy
- Python
- Node.js
- Go
- Rust
- CLI
Python
import asyncio
from grpclib.client import Channel
from ahnlich_client_py.grpc.services.db_service import DbServiceStub
from ahnlich_client_py.grpc.db import query as db_query
async def list_connected_clients():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)
response = await client.list_clients(db_query.ListClients())
# response.clients contains information about connected clients
for client_info in response.clients:
print(f"Connected client: {client_info.address}")
if __name__ == "__main__":
asyncio.run(list_connected_clients())
TypeScript
import { createDbClient } from "ahnlich-client-node";
import { ListClients } from "ahnlich-client-node/grpc/db/query_pb";
async function listConnectedClients() {
const client = createDbClient("127.0.0.1:1369");
const response = await client.listClients(new ListClients());
console.log(response.clients);
// Iterate over connected clients
for (const clientInfo of response.clients) {
console.log(`Client: ${clientInfo.address}`);
}
}
listConnectedClients();
Go
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
dbsvc "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/services/db_service"
dbquery "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/db/query"
)
const ServerAddr = "127.0.0.1:1369"
type ExampleDBClient struct {
conn *grpc.ClientConn
client dbsvc.DBServiceClient
ctx context.Context
}
func NewDBClient(ctx context.Context) (*ExampleDBClient, error) {
conn, err := grpc.NewClient(ServerAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("failed to dial DB server %q: %w", ServerAddr, err)
}
client := dbsvc.NewDBServiceClient(conn)
return &ExampleDBClient{conn: conn, client: client, ctx: ctx}, nil
}
func (c *ExampleDBClient) Close() error {
return c.conn.Close()
}
func (c *ExampleDBClient) exampleListConnectedClients() error {
resp, err := c.client.ListClients(c.ctx, &dbquery.ListClients{})
if err != nil {
return err
}
fmt.Println("Connected Clients:", resp.Clients)
return nil
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
client, err := NewDBClient(ctx)
if err != nil {
log.Fatalf("Failed to create DB client: %v", err)
}
defer client.Close()
if err := client.exampleListConnectedClients(); err != nil {
log.Fatalf("ListConnectedClients failed: %v", err)
}
}
Rust
use ahnlich_client_rs::db::DbClient;
use ahnlich_client_rs::error::AhnlichError;
#[tokio::main]
async fn main() -> Result<(), AhnlichError> {
// Set the DB server address
let addr = "127.0.0.1:1369".to_string();
// Initialize the DB client
let db_client = DbClient::new(addr).await?;
// Fetch the list of connected clients
let clients = db_client.list_clients(None).await?;
// Print the clients in a readable way
println!("Connected clients:");
for (i, client) in clients.clients.iter().enumerate() {
println!("{}. {:?}", i + 1, client);
}
Ok(())
}
This operation isn't exposed as a standalone CLI command — use one of the client libraries above.
- Python
- Node.js
- Go
- Rust
- CLI
Python
import asyncio
from grpclib.client import Channel
from ahnlich_client_py.grpc.services.ai_service import AiServiceStub
from ahnlich_client_py.grpc.ai import query as ai_query
async def list_connected_clients():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
response = await client.list_clients(ai_query.ListClients())
# response.clients contains information about connected clients
for client_info in response.clients:
print(f"Connected client: {client_info.address}")
if __name__ == "__main__":
asyncio.run(list_connected_clients())
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { ListClients } from "ahnlich-client-node/grpc/ai/query_pb";
async function listConnectedClients() {
const client = createAiClient("127.0.0.1:1370");
const response = await client.listClients(new ListClients());
console.log(response.clients);
// Iterate over connected clients
for (const clientInfo of response.clients) {
console.log(`Client: ${clientInfo.address}`);
}
}
listConnectedClients();
Go
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
aisvc "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/services/ai_service"
aiquery "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/ai/query"
)
const ServerAddr = "127.0.0.1:1370"
type ExampleAIClient struct {
conn *grpc.ClientConn
client aisvc.AIServiceClient
ctx context.Context
}
func NewAIClient(ctx context.Context) (*ExampleAIClient, error) {
conn, err := grpc.NewClient(ServerAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, fmt.Errorf("failed to dial AI server %q: %w", ServerAddr, err)
}
client := aisvc.NewAIServiceClient(conn)
return &ExampleAIClient{conn: conn, client: client, ctx: ctx}, nil
}
func (c *ExampleAIClient) Close() error {
return c.conn.Close()
}
func (c *ExampleAIClient) exampleListConnectedClients() error {
resp, err := c.client.ListClients(c.ctx, &aiquery.ListClients{})
if err != nil {
return err
}
fmt.Println("Connected Clients:", resp.Clients)
return nil
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
client, err := NewAIClient(ctx)
if err != nil {
log.Fatalf("Failed to create AI client: %v", err)
}
defer client.Close()
if err := client.exampleListConnectedClients(); err != nil {
log.Fatalf("ListConnectedClients failed: %v", err)
}
}
Rust
use ahnlich_client_rs::ai::AiClient;
use ahnlich_client_rs::error::AhnlichError;
#[tokio::main]
async fn main() -> Result<(), AhnlichError> {
// Connect to AI server
let addr = "127.0.0.1:1370".to_string();
let ai_client = AiClient::new(addr).await?;
// Fetch the list of connected clients
let clients = ai_client.list_clients(None).await?;
// Print the clients in a readable way
println!("Connected clients:");
for (i, client) in clients.clients.iter().enumerate() {
println!("{}. {:?}", i + 1, client);
}
Ok(())
}
This operation isn't exposed as a standalone CLI command — use one of the client libraries above.
Response
A list of connected client information (e.g. client addresses).