Ping the server
Test connectivity to the server — a lightweight health check that confirms the service is up.
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. An optional tracing ID may be passed for distributed tracing.
Behavior
- The client sends a ping message and the server replies with a Pong.
- Handy for readiness/liveness probes, monitoring, and debugging connections.
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
from ahnlich_client_py.grpc.db.server import Pong
async def Ping():
"""
Test ping
"""
# Initialize client
async with Channel(host="127.0.0.1", port=1369) as channel:
db_client = DbServiceStub(channel)
# Prepare tracing metadata
tracing_id = "00-80e1afed08e019fc1110464cfa66635c-7a085853722dc6d2-01"
metadata = {"ahnlich-trace-id": tracing_id}
# Make request with metadata
response = await db_client.ping(
db_query.Ping(),
metadata=metadata
)
if __name__ == "__main__":
asyncio.run(Ping())
TypeScript
import { createDbClient } from "ahnlich-client-node";
import { Ping } from "ahnlich-client-node/grpc/db/query_pb";
async function ping() {
// Initialize client
const client = createDbClient("127.0.0.1:1369");
// Make request
const response = await client.ping(new Ping());
console.log(response); // Pong
}
ping();
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) examplePingDB() error {
resp, err := c.client.Ping(c.ctx, &dbquery.Ping{})
if err != nil {
return err
}
fmt.Println("Ping:", resp)
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.examplePingDB(); err != nil {
log.Fatalf("Ping failed: %v", err)
}
}
Rust
use ahnlich_client_rs::db::DbClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to your running ahnlich-db instance
let db_client = DbClient::new("127.0.0.1:1369".to_string()).await?;
// Optional tracing ID (can be None if you don’t use tracing)
let tracing_id: Option<String> = None;
// Call ping and print the response
let res = db_client.ping(tracing_id).await?;
println!("Ping response: {:?}", res);
Ok(())
}
PING- 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 ping():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
response = await client.ping(ai_query.Ping())
print(response) #Pong()
if __name__ == "__main__":
asyncio.run(ping())
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { Ping } from "ahnlich-client-node/grpc/ai/query_pb";
async function ping() {
const client = createAiClient("127.0.0.1:1370");
const response = await client.ping(new Ping());
console.log(response); // Pong
}
ping();
Go
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
aiquery "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/ai/query"
aisvc "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/services/ai_service"
)
const AIAddr = "127.0.0.1:1370"
// ExampleAIClient holds the gRPC connection and AI client.
type ExampleAIClient struct {
conn *grpc.ClientConn
client aisvc.AIServiceClient
ctx context.Context
}
// NewAIClient connects to the AI server and returns a client.
func NewAIClient(ctx context.Context) (*ExampleAIClient, error) {
conn, err := grpc.DialContext(ctx, AIAddr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
return nil, fmt.Errorf("failed to dial AI server %q: %w", AIAddr, err)
}
client := aisvc.NewAIServiceClient(conn)
return &ExampleAIClient{conn: conn, client: client, ctx: ctx}, nil
}
// Close closes the gRPC connection.
func (c *ExampleAIClient) Close() error {
return c.conn.Close()
}
// ---- Ping Example ----
func (c *ExampleAIClient) examplePingAI() error {
resp, err := c.client.Ping(c.ctx, &aiquery.Ping{})
if err != nil {
return err
}
fmt.Println(" AI Ping:", resp)
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.examplePingAI(); err != nil {
log.Fatalf("Ping failed: %v", err)
}
}
Rust
// src/bin/pingai.rs
use ahnlich_client_rs::ai::AiClient; // AiClient path
use ahnlich_client_rs::error::AhnlichError; // Error type
use ahnlich_types::ai::pipeline::AiResponsePipeline;
#[tokio::main]
async fn main() -> Result<(), AhnlichError> {
// AI server address
let addr = "http://127.0.0.1:1370";
// Initialize the AI client
let ai_client = AiClient::new(addr.to_string()).await?;
// Simple ping request
let pong = ai_client.ping(None).await?;
println!("AI Server Pong received: {:?}", pong);
// Using a pipeline to send a ping
let mut pipeline = ai_client.pipeline(None);
pipeline.ping();
let res: AiResponsePipeline = pipeline.exec().await?;
println!("Pipeline response: {:?}", res);
Ok(())
}
PINGResponse
A Pong message confirming connectivity.