Create a store
Create a new, isolated store — Ahnlich's container for vectors and their metadata, like a collection in a document database or a table in a relational one.
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 | Unique name for the store. |
dimension | int | Vector dimensionality — every key must match this length. |
create_predicates | list · optional | Metadata fields to index for filtering (seeds a predicate index). |
non_linear_indices | list · optional | Non-linear algorithms for approximate search (see non-linear index). |
error_if_exists | bool | If true, returns an error when the store already exists. |
All requests accept an optional
schemafield. When omitted, the server uses thepublicschema.
Behavior
- Creates a new isolated store; many stores can coexist for different workloads.
- The
dimensionis fixed at creation — every vector key must match it. - You can seed predicate and non-linear indexes here, or add them later.
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 Unit
async def create_store():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)
response = await client.create_store(
db_query.CreateStore(
store="my_store",
schema="analytics",
dimension=4, # Fixed vector dimension
create_predicates=["label", "category"], # Index these metadata fields
non_linear_indices=[], # Optional: non-linear algorithms for faster search
error_if_exists=True
)
)
# response is Unit() on success
# All store_keys must match this dimension
# Example valid key:
valid_key = [1.0, 2.0, 3.0, 4.0, 5.0] # length = 5
assert isinstance(response, Unit)
if __name__ == "__main__":
asyncio.run(create_store())
TypeScript
import { createDbClient } from "ahnlich-client-node";
import { CreateStore } from "ahnlich-client-node/grpc/db/query_pb";
async function createStore() {
const client = createDbClient("127.0.0.1:1369");
await client.createStore(
new CreateStore({
store: "my_store",
schema: "analytics",
dimension: 4,
predicates: ["label", "category"],
errorIfExists: true,
})
);
console.log("Store created successfully");
}
createStore();
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"
nonlinear "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/algorithm/nonlinear"
)
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() }
// CreateStore example
func (c *ExampleDBClient) exampleCreateStore(store string, dimension int32) error {
_, err := c.client.CreateStore(c.ctx, &dbquery.CreateStore{
Store: store,
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
Dimension: uint32(dimension),
CreatePredicates: []string{}, // Optional: list of metadata fields to index for filtering
NonLinearIndices: []*nonlinear.NonLinearIndex{}, // Optional: non-linear algorithms (e.g., HNSW) for faster search
ErrorIfExists: true, // Return error if store already exists
})
if err != nil {
return err
}
fmt.Printf("Created store: %s (dimension: %d)\n", store, dimension)
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()
storeName := "my_store"
if err := client.exampleCreateStore(storeName, 4); err != nil {
log.Fatalf("CreateStore failed: %v", err)
}
}
Rust
use ahnlich_client_rs::db::DbClient;
use ahnlich_types::db::query::CreateStore;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to server
let db_client = DbClient::new("127.0.0.1:1369".to_string()).await?;
let tracing_id: Option<String> = None;
// Define parameters for store creation
let params = CreateStore {
store: "my_store".to_string(),
schema: Some("analytics".to_string()),
dimension: 4,
create_predicates: vec!["label".to_string(), "category".to_string()],
non_linear_indices: vec![],
error_if_exists: true,
};
// Call create_store
match db_client.create_store(params, tracing_id).await {
Ok(res) => {
println!("Store created successfully: {:?}", res);
}
Err(err) => {
eprintln!("Error creating store: {:?}", err);
}
}
Ok(())
}
CREATESTORE my_store DIMENSION 4 PREDICATES (label, category)- 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.ai.models import AiModel
async def create_store():
async with Channel(host="127.0.0.1", port=1370) as channel:
client = AiServiceStub(channel)
response = await client.create_store(
ai_query.CreateStore(
store="my_store",
schema="analytics",
query_model=AiModel.ALL_MINI_LM_L6_V2,
index_model=AiModel.ALL_MINI_LM_L6_V2,
predicates=["job"],
non_linear_indices=[], # Optional: non-linear algorithms for faster search
error_if_exists=True,
# Store original controls if we choose to store the raw inputs
# within the DB in order to be able to retrieve the originals again
# during query, else only store values are returned
store_original=True
)
)
print(response) # Unit()
if __name__ == "__main__":
asyncio.run(create_store())
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { CreateStore } from "ahnlich-client-node/grpc/ai/query_pb";
import { AIModel } from "ahnlich-client-node/grpc/ai/models_pb";
async function createStore() {
const client = createAiClient("127.0.0.1:1370");
await client.createStore(
new CreateStore({
store: "ai_store",
schema: "analytics",
queryModel: AIModel.ALL_MINI_LM_L6_V2,
indexModel: AIModel.ALL_MINI_LM_L6_V2,
predicates: ["brand", "category"],
errorIfExists: true,
storeOriginal: true,
})
);
console.log("AI store created successfully");
}
createStore();
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"
aimodel "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/ai/models"
aisvc "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/services/ai_service"
nonlinear "github.com/deven96/ahnlich/sdk/ahnlich-client-go/grpc/algorithm/nonlinear"
)
const AIAddr = "127.0.0.1:1370"
// ExampleAIClient holds the gRPC connection and AI client.
func stringPtr(value string) *string { return &value }
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()
}
// ---- CreateStore Example ----
// Create a new store for AI operations.
func (c *ExampleAIClient) exampleCreateStoreAI() error {
_, err := c.client.CreateStore(c.ctx, &aiquery.CreateStore{
Store: "ai_store",
Schema: stringPtr("analytics"), // Optional: defaults to public when omitted
QueryModel: aimodel.AIModel_ALL_MINI_LM_L6_V2,
IndexModel: aimodel.AIModel_ALL_MINI_LM_L6_V2,
Predicates: []string{}, // Optional: metadata fields to index for filtering
NonLinearIndices: []*nonlinear.NonLinearIndex{}, // Optional: non-linear algorithms (e.g., HNSW) for faster search
ErrorIfExists: true, // Return error if store already exists
StoreOriginal: true, // Store original input (needed for key deletion)
})
if err != nil {
return err
}
fmt.Println(" AI Store created: ai_store01")
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.exampleCreateStoreAI(); err != nil {
log.Fatalf("CreateStore failed: %v", err)
}
}
Rust
use ahnlich_types::ai::query::CreateStore;
use ahnlich_client_rs::ai::AiClient;
use ahnlich_types::ai::models::AiModel;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AiClient::new("http://127.0.0.1:1370".to_string()).await?;
// Create a new AI store
let create_params = CreateStore {
store: "Deven Kicks".to_string(),
schema: Some("analytics".to_string()),
index_model: AiModel::AllMiniLmL6V2 as i32,
query_model: AiModel::AllMiniLmL6V2 as i32,
predicates: vec![],
non_linear_indices: vec![],
error_if_exists: true,
store_original: true,
};
let result = client.create_store(create_params, None).await?;
println!("Store created: {:?}", result);
Ok(())
}
CREATESTORE my_store QUERYMODEL all-minilm-l6-v2 INDEXMODEL all-minilm-l6-v2 PREDICATES (label, category) STOREORIGINALResponse
A confirmation message (Unit).