Delete by predicate
Delete every entry that matches a metadata condition.
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
| Parameter | Type | Description |
|---|---|---|
store | string | Name of the store to delete from. |
condition | predicate | A metadata predicate identifying the entries to remove. |
schema | string · optional | Schema to target. Defaults to public. |
All requests accept an optional
schemafield. When omitted, the server uses thepublicschema.
Behavior
- Deletes all entries satisfying the predicate in one call.
- Use a narrow predicate — there is no automatic confirmation step.
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 import predicates, metadata
from ahnlich_client_py.grpc.db.server import Del
async def delete_predicate():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)
condition = predicates.PredicateCondition(
value=predicates.Predicate(
equals=predicates.Equals(
key="label",
value=metadata.MetadataValue(raw_string="sorcerer")
)
)
)
response = await client.del_pred(
db_query.DelPred(
store="my_store",
schema="analytics",
condition=condition
)
)
# response.deleted_count shows how many items were deleted
if __name__ == "__main__":
asyncio.run(delete_predicate())
TypeScript
import { createDbClient } from "ahnlich-client-node";
import { DelPred } from "ahnlich-client-node/grpc/db/query_pb";
import { PredicateCondition, Predicate, Equals } from "ahnlich-client-node/grpc/predicate_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
async function deletePredicate() {
const client = createDbClient("127.0.0.1:1369");
const response = await client.delPred(
new DelPred({
store: "my_store",
schema: "analytics",
condition: new PredicateCondition({
kind: {
case: "value",
value: new Predicate({
kind: {
case: "equals",
value: new Equals({
key: "status",
value: new MetadataValue({ value: { case: "rawString", value: "archived" } }),
}),
},
}),
},
}),
})
);
console.log(`Deleted ${response.deleted} entries`);
}
deletePredicate();
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"
metadata "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/metadata"
predicates "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/predicates"
)
const ServerAddr = "127.0.0.1:1369"
func stringPtr(value string) *string { return &value }
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()
}
// -------------------- Delete Predicate --------------------
func (c *ExampleDBClient) exampleDeletePredicate() error {
condition := &predicates.PredicateCondition{
Kind: &predicates.PredicateCondition_Value{
Value: &predicates.Predicate{
Kind: &predicates.Predicate_Equals{
Equals: &predicates.Equals{
Key: "label",
Value: &metadata.MetadataValue{
Value: &metadata.MetadataValue_RawString{
RawString: "A",
},
},
},
},
},
},
}
_, err := c.client.DelPred(c.ctx, &dbquery.DelPred{
Store: "my_store",
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
Condition: condition,
})
if err != nil {
return err
}
fmt.Println("Deleted entries matching predicate from store: my_store")
return nil
}
// -------------------- Main --------------------
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.exampleDeletePredicate(); err != nil {
log.Fatalf("DeletePredicate failed: %v", err)
}
}
Rust
use ahnlich_types::db::query::DelPred;
use ahnlich_types::db::server::Del;
use ahnlich_types::predicates::{Predicate, PredicateCondition, predicate::Kind as PredicateKind, predicate_condition::Kind as PredicateConditionKind};
use ahnlich_client_rs::db::DbClient;
use ahnlich_types::metadata::{MetadataValue, metadata_value::Value};
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// gRPC server address
let addr = "http://127.0.0.1:1369".to_string();
let db_client = DbClient::new(addr).await?;
// Define the predicate condition to delete
let condition = PredicateCondition {
kind: Some(PredicateConditionKind::Value(Predicate {
kind: Some(PredicateKind::Equals(ahnlich_types::predicates::Equals {
key: "medal".into(),
value: Some(MetadataValue {
value: Some(Value::RawString("gold".into())),
}),
})),
})),
};
// Parameters for deleting predicate
let params = DelPred {
store: "my_store".to_string(), // your store name
schema: Some("analytics".to_string()),
condition: Some(condition),
};
// Call delete predicate
match db_client.del_pred(params, None).await {
Ok(Del { deleted_count }) => {
println!("Successfully deleted {} predicate(s).", deleted_count);
}
Err(e) => {
eprintln!("Error deleting predicate: {:?}", e);
}
}
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
from ahnlich_client_py.grpc import predicates, metadata
from ahnlich_client_py.grpc.ai.server import Del
async def delete_predicate():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
condition = predicates.PredicateCondition(
value=predicates.Predicate(
equals=predicates.Equals(
key="category",
value=metadata.MetadataValue(raw_string="archived")
)
)
)
response = await client.del_pred(
ai_query.DelPred(
store="my_ai_store",
schema="analytics",
condition=condition
)
)
# response.deleted_count shows how many items were deleted
if __name__ == "__main__":
asyncio.run(delete_predicate())
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { DelPred } from "ahnlich-client-node/grpc/ai/query_pb";
import { PredicateCondition, Predicate, Equals } from "ahnlich-client-node/grpc/predicate_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
async function deletePredicate() {
const client = createAiClient("127.0.0.1:1370");
// Create a predicate condition to match entries where "category" equals "outdated"
// Using oneof discriminated unions with { case: "...", value: ... } pattern
const condition = new PredicateCondition({
kind: {
case: "value",
value: new Predicate({
kind: {
case: "equals",
value: new Equals({
key: "category",
value: new MetadataValue({
value: {
case: "rawString",
value: "outdated"
}
})
})
}
})
}
});
const response = await client.delPred(
new DelPred({
store: "my_store",
schema: "analytics",
condition: condition
})
);
console.log(`Deleted ${response.deletedCount} items`);
}
deletePredicate();
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"
metadata "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/metadata"
predicates "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/predicates"
)
const ServerAddr = "127.0.0.1:1370"
func stringPtr(value string) *string { return &value }
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()
}
// -------------------- Delete Predicate --------------------
func (c *ExampleAIClient) exampleDeletePredicate() error {
condition := &predicates.PredicateCondition{
Kind: &predicates.PredicateCondition_Value{
Value: &predicates.Predicate{
Kind: &predicates.Predicate_Equals{
Equals: &predicates.Equals{
Key: "category",
Value: &metadata.MetadataValue{
Value: &metadata.MetadataValue_RawString{
RawString: "archived",
},
},
},
},
},
},
}
_, err := c.client.DelPred(c.ctx, &aiquery.DelPred{
Store: "my_ai_store",
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
Condition: condition,
})
if err != nil {
return err
}
fmt.Println("Deleted entries matching predicate from AI store: my_ai_store")
return nil
}
// -------------------- Main --------------------
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.exampleDeletePredicate(); err != nil {
log.Fatalf("DeletePredicate failed: %v", err)
}
}
Rust
use ahnlich_types::ai::query::DelPred;
use ahnlich_types::ai::server::Del;
use ahnlich_types::predicates::{Predicate, PredicateCondition, predicate::Kind as PredicateKind, predicate_condition::Kind as PredicateConditionKind};
use ahnlich_client_rs::ai::AiClient;
use ahnlich_types::metadata::{MetadataValue, metadata_value::Value};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// gRPC server address
let addr = "http://127.0.0.1:1370".to_string();
let ai_client = AiClient::new(addr).await?;
// Define the predicate condition to delete
let condition = PredicateCondition {
kind: Some(PredicateConditionKind::Value(Predicate {
kind: Some(PredicateKind::Equals(ahnlich_types::predicates::Equals {
key: "category".into(),
value: Some(MetadataValue {
value: Some(Value::RawString("archived".into())),
}),
})),
})),
};
// Parameters for deleting predicate
let params = DelPred {
store: "my_ai_store".to_string(),
schema: Some("analytics".to_string()),
condition: Some(condition),
};
// Call delete predicate
match ai_client.del_pred(params, None).await {
Ok(Del { deleted_count }) => {
println!("Successfully deleted {} record(s).", deleted_count);
}
Err(e) => {
eprintln!("Error deleting predicate: {:?}", e);
}
}
Ok(())
}
This operation isn't exposed as a standalone CLI command — use one of the client libraries above.
Response
The number of entries deleted.