Clear a store
Delete every entry from a store without deleting the store itself.
This operation works on both Vector DB stores and AI stores. Use the Database engine / AI proxy switch in the sample below.
Parameters
| Parameter | Type | Description |
|---|---|---|
store | string | Name of the store to clear. |
schema | string · optional | Schema containing the store. Defaults to public. |
Behavior
- Deletes every entry and returns the number removed.
- Preserves the store, its creation information, dimension, predicate indexes, and non-linear index configuration.
- Returns
deleted_count: 0when the store is already empty.
warning
Clearing a store permanently deletes its entries. This operation cannot be undone.
ClearStore compared with DropStore
| Operation | Entries | Store configuration |
|---|---|---|
ClearStore | Deleted | Preserved |
DropStore | Deleted | Deleted |
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.db import query as db_query
from ahnlich_client_py.grpc.services.db_service import DbServiceStub
async def clear_store():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)
response = await client.clear_store(
db_query.ClearStore(store="movies", schema="public")
)
print(f"Deleted {response.deleted_count} entries")
asyncio.run(clear_store())
TypeScript
import { createDbClient } from "@deven96/ahnlich-client-node";
import { ClearStore } from "@deven96/ahnlich-client-node/grpc/db/query_pb";
const client = createDbClient("127.0.0.1:1369");
const response = await client.clearStore(
new ClearStore({ store: "movies", schema: "public" }),
);
console.log(`Deleted ${response.deletedCount.toString()} entries`);
Go
package main
import (
"context"
"fmt"
dbquery "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/db/query"
dbsvc "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/services/db_service"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
conn, err := grpc.NewClient(
"127.0.0.1:1369",
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
panic(err)
}
defer conn.Close()
client := dbsvc.NewDBServiceClient(conn)
schema := "public"
response, err := client.ClearStore(
context.Background(),
&dbquery.ClearStore{Store: "movies", Schema: &schema},
)
if err != nil {
panic(err)
}
fmt.Printf("Deleted %d entries\n", response.DeletedCount)
}
Rust
use ahnlich_client_rs::db::DbClient;
use ahnlich_types::db::query::ClearStore;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = DbClient::new("http://127.0.0.1:1369".to_string()).await?;
let response = client
.clear_store(
ClearStore {
store: "movies".to_string(),
schema: Some("public".to_string()),
},
None,
)
.await?;
println!("Deleted {} entries", response.deleted_count);
Ok(())
}
Text
CLEARSTORE movies SCHEMA public
- Python
- Node.js
- Go
- Rust
- CLI
Python
import asyncio
from grpclib.client import Channel
from ahnlich_client_py.grpc.ai import query as ai_query
from ahnlich_client_py.grpc.services.ai_service import AiServiceStub
async def clear_store():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
response = await client.clear_store(
ai_query.ClearStore(store="movies", schema="public")
)
print(f"Deleted {response.deleted_count} entries")
asyncio.run(clear_store())
TypeScript
import { createAiClient } from "@deven96/ahnlich-client-node";
import { ClearStore } from "@deven96/ahnlich-client-node/grpc/ai/query_pb";
const client = createAiClient("127.0.0.1:1370");
const response = await client.clearStore(
new ClearStore({ store: "movies", schema: "public" }),
);
console.log(`Deleted ${response.deletedCount.toString()} entries`);
Go
package main
import (
"context"
"fmt"
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"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func main() {
conn, err := grpc.NewClient(
"127.0.0.1:1370",
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
panic(err)
}
defer conn.Close()
client := aisvc.NewAIServiceClient(conn)
schema := "public"
response, err := client.ClearStore(
context.Background(),
&aiquery.ClearStore{Store: "movies", Schema: &schema},
)
if err != nil {
panic(err)
}
fmt.Printf("Deleted %d entries\n", response.DeletedCount)
}
Rust
use ahnlich_client_rs::ai::AiClient;
use ahnlich_types::ai::query::ClearStore;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AiClient::new("http://127.0.0.1:1370".to_string()).await?;
let response = client
.clear_store(
ClearStore {
store: "movies".to_string(),
schema: Some("public".to_string()),
},
None,
)
.await?;
println!("Deleted {} entries", response.deleted_count);
Ok(())
}
Text
CLEARSTORE movies SCHEMA public
Response
The response contains deleted_count, the number of entries removed.
Use ClearStore when the store should remain available for new entries. Use DropStore when the store and its configuration are no longer needed.