Drop predicate index
Remove a predicate index when it's no longer needed or to reduce storage overhead.
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 | Store to modify. |
predicates | list | Metadata fields whose indexes should be dropped. |
error_if_not_exists | bool · optional | If true, errors when the index doesn't exist. |
schema | string · optional | Schema to target. Defaults to public. |
All requests accept an optional
schemafield. When omitted, the server uses thepublicschema.
Behavior
- Deletes the index only — the underlying entries and metadata remain.
- Queries on the field still work, just without the index speed-up.
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 Del
async def drop_predicate_index():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)
response = await client.drop_pred_index(
db_query.DropPredIndex(
store="my_store",
schema="analytics",
predicates=["label"],
error_if_not_exists=True
)
)
# response.deleted_count shows how many indexes were removed
print(response)
if __name__ == "__main__":
asyncio.run(drop_predicate_index())
TypeScript
import { createDbClient } from "ahnlich-client-node";
import { DropPredIndex } from "ahnlich-client-node/grpc/db/query_pb";
async function dropPredicateIndex() {
const client = createDbClient("127.0.0.1:1369");
await client.dropPredIndex(
new DropPredIndex({
store: "my_store",
schema: "analytics",
predicates: ["label"],
errorIfNotExists: true,
})
);
console.log("Predicate index dropped successfully");
}
dropPredicateIndex();
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"
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()
}
// -------------------- Drop Predicate Index --------------------
func (c *ExampleDBClient) exampleDropPredicateIndex() error {
_, err := c.client.DropPredIndex(c.ctx, &dbquery.DropPredIndex{
Store: "my_store",
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
Predicates: []string{"label"},
ErrorIfNotExists: true,
})
if err != nil {
return err
}
fmt.Println("Dropped predicate index for 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.exampleDropPredicateIndex(); err != nil {
log.Fatalf("DropPredicateIndex failed: %v", err)
}
}
Rust
use ahnlich_client_rs::db::DbClient;
use ahnlich_types::db::query::DropPredIndex;
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "http://127.0.0.1:1369";
let client = DbClient::new(addr.to_string()).await?;
// Drop the "label" predicate index from store "my_store"
let drop_index_params = DropPredIndex {
store: "my_store".to_string(),
schema: Some("analytics".to_string()),
predicates: vec!["label".to_string()],
error_if_not_exists: true, // fail if it doesn't exist
};
match client.drop_pred_index(drop_index_params, None).await {
Ok(result) => println!("Dropped predicate index: {:?}", result),
Err(e) => eprintln!("Error: {:?}", e),
}
Ok(())
}
DROPPREDINDEX (category) IN my_store- 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 drop_predicate_index():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
response = await client.drop_pred_index(
ai_query.DropPredIndex(
store="my_store",
schema="analytics",
predicates=["job"],
error_if_not_exists=True
)
)
print(response) # Del(deleted_count=1)
if __name__ == "__main__":
asyncio.run(drop_predicate_index())
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { DropPredIndex } from "ahnlich-client-node/grpc/ai/query_pb";
async function dropPredicateIndex() {
const client = createAiClient("127.0.0.1:1370");
await client.dropPredIndex(
new DropPredIndex({
store: "ai_store",
schema: "analytics",
predicates: ["brand"],
errorIfNotExists: true,
})
);
console.log("Predicate index dropped");
}
dropPredicateIndex();
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 wraps the connection + AIService client
func stringPtr(value string) *string { return &value }
type ExampleAIClient struct {
conn *grpc.ClientConn
client aisvc.AIServiceClient
ctx context.Context
}
// NewAIClient creates and connects the AI 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
}
func (c *ExampleAIClient) Close() error {
return c.conn.Close()
}
// ---- DropPredIndex standalone ----
func (c *ExampleAIClient) exampleDropPredicateIndexAI() error {
_, err := c.client.DropPredIndex(c.ctx, &aiquery.DropPredIndex{
Store: "ai_store",
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
Predicates: []string{"f"},
ErrorIfNotExists: true,
})
if err != nil {
return err
}
fmt.Println(" Successfully dropped predicate index for Predicates: [\"f\"] in store ai_store")
return nil
}
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 15*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.exampleDropPredicateIndexAI(); err != nil {
log.Fatalf(" DropPredIndex failed: %v", err)
}
}
Rust
use ahnlich_client_rs::ai::AiClient;
use ahnlich_client_rs::error::AhnlichError;
use ahnlich_types::ai::query::DropPredIndex;
use ahnlich_types::ai::server::Del;
#[tokio::main]
async fn main() -> Result<(), AhnlichError> {
// Connect to the AI service
let ai_client = AiClient::new("http://127.0.0.1:1370".to_string())
.await
.expect("Failed to connect AI client");
// Define which store and which predicate index to drop
let params = DropPredIndex {
store: "Deven Kicks".to_string(),
schema: Some("analytics".to_string()),
predicates: vec!["Brand".to_string()],
error_if_not_exists: true, // 👈 required field, prevents silent no-op
};
// Call the API
let response: Del = ai_client.drop_pred_index(params, None).await?;
println!(" Dropped predicate index result: {:?}", response);
Ok(())
}
DROPPREDINDEX (category) IN my_storeResponse
The number of indexes deleted.