Skip to main content
Supply chains rarely fail because of a single obvious signal. More often, disruptions build gradually and combine into a hidden risk pattern:
  • Supplier delays slow replenishment before stock runs out.
  • Rising demand accelerates inventory depletion.
  • Regional logistics issues block inbound shipments.
  • Warehouse imbalances leave some locations critically understocked.
Traditional inventory systems track structured data well, but they are not designed to recognize semantically similar incidents across messy operational events. In this tutorial, you will build an AI supply chain inventory risk intelligence agent. It uses Actian VectorAI DB to detect inventory risk patterns before they become stockouts. The system will:
  • Ingest supply chain events and convert them into embeddings.
  • Store events with structured metadata in Actian VectorAI DB.
  • Retrieve similar historical incidents using semantic search and payload filters.
  • Generate risk alerts using a lightweight reasoning layer.

Architecture overview

The agent is built around four connected stages:
  • Ingestion pipeline — Converts raw supply chain events into embeddings and stores them in Actian VectorAI DB.
  • Query pipeline — Embeds incoming natural-language questions.
  • Retrieval layer — Combines semantic search with payload filters to surface relevant historical incidents.
  • Risk reasoning layer — Evaluates each result against five rule-based checks to generate actionable alerts.
The diagram below shows how supply chain events flow through embeddings, vector storage, semantic retrieval with payload filters, and the risk reasoning layer.

Environment setup

This tutorial requires Python, a sentence embedding model, and the Actian VectorAI Python SDK. Run the following command to install both required packages:
Each package serves a specific role in the pipeline:
  • actian-vectorai-client — Official Python SDK for Actian VectorAI DB (async/sync clients, Filter DSL, gRPC transport).
  • sentence-transformers — For generating text embeddings with all-MiniLM-L6-v2.

Implementation

This section walks through the implementation steps for building the inventory risk intelligence workflow using Actian VectorAI DB.

Step 1: Import dependencies and configure

The following block imports the Actian VectorAI client, the embedding model, and defines the connection endpoint and collection settings. Running it prints a confirmation that the configuration was loaded correctly.
Every component is configured upfront. The key settings are:
  • VectorAI server - The Actian VectorAI gRPC endpoint (default port 6574).
  • Collection name — Identifies the vector collection for supply chain events.
  • Embedding model — Converts event text into 384-dimensional dense vectors.
Running this configuration block prints the following confirmation:

Step 2: Define embedding helpers

The following functions wrap the embedding model so the rest of the pipeline can convert event text to vectors with a single call. embed_text handles single strings; embed_texts processes a list of strings in one model pass, which is more efficient when ingesting batches.
The embedding model turns natural-language event summaries into numerical representations that preserve semantic meaning. This allows the vector database to retrieve related incidents even when the wording is different. For example, these two event descriptions map to nearby vectors:
  • “Supplier delay caused battery shortage risk.”
  • “Low battery stock after repeated replenishment delays.”

Step 3: Initialize the vector database collection

Collections in Actian VectorAI DB define the vector dimensionality, distance metric, and index parameters. The following code calls get_or_create, which is idempotent. It creates the collection if it does not exist and skips creation if it already does. Running this block prints a confirmation that the collection is ready.
This step creates a dedicated vector space for supply chain risk events. The configuration tells VectorAI DB the following:
  • Vectors will have 384 dimensions.
  • Similarity is computed with cosine distance.
  • The HNSW index uses m=32 connections and ef_construct=256 for high recall.
Once the collection is ready, the following message is printed:

Step 4: Prepare sample supply chain events

The following block defines a dataset of realistic supply chain incidents. Each event includes an event_text field for semantic meaning and structured fields for payload filtering. Running it prints the number of events loaded.
Actian VectorAI DB stores rich payload metadata alongside vectors, making it possible to combine semantic similarity with operational filtering. Each event carries both unstructured text (for embeddings) and structured fields (for filters).

Step 5: Embed and ingest events into VectorAI DB

The following code embeds each event description, packages it as a PointStruct with payload, and upserts all points into the collection in a single operation. Running it prints the number of events ingested and the updated total stored in the collection.
Each supply chain event becomes a searchable point in VectorAI DB. The three fields that make up each point are:
  • id — Sequential integer identifier.
  • vector — 384-dim dense embedding from all-MiniLM-L6-v2.
  • payload — All structured metadata (category, supplier, stock level, region, etc.).
The vde.flush() call ensures vectors are persisted to disk immediately. After ingestion, the pipeline prints the following confirmation:
The following code embeds a natural-language inventory risk query and uses points.search to retrieve the most semantically similar events from the collection. Running it prints each result’s ID, similarity score, and a preview of the event text.
This is the semantic search core of the system. The points.search method accepts the following parameters:
  • vector — The query embedding.
  • limit — Number of results.
  • with_payload — Whether to return metadata.
Results are ranked by cosine similarity. The search returns the three ingested events in the following order:

Step 7: Apply structured payload filters using the Filter DSL

Actian VectorAI provides a type-safe Field / FilterBuilder API for payload filtering. The following code adds a server-side filter that restricts results to electronics events with stock below 20 before ranking by similarity. Running it prints only the two events that pass both the category and stock-level filters.
This combines semantic search with Actian VectorAI’s Filter DSL. The three filter expressions used here are:
  • Field("category").eq("electronics") — Exact match filter.
  • Field("stock_level").lt(20.0) — Numeric range filter.
  • FilterBuilder().must(...) — AND logic.
The filter is applied server-side before ranking, so only matching points are considered. With the category and stock filters applied, only the two low-stock laptop battery events are returned:

Step 8: Add boolean logic with must, should, and must_not

The Filter DSL supports must (AND), should (OR/preference), and must_not (exclusion) for complex business queries. The following code demonstrates all three clause types in a single filter. Running it returns only the Supplier Alpha events that match the low-stock electronics criteria, with the deprecated-region events excluded.
The Filter DSL supports three clause types, each with different matching behavior:
  • .must() — All conditions must match (AND logic). Used here to require category = electronics and stock_level < 20.
  • .should() — Preference boost. Events from Supplier Alpha are ranked higher but not excluded if absent.
  • .must_not() — Hard exclusion. Events from Deprecated Region are removed from results entirely.
This lets the agent answer realistic business questions such as: find low-stock electronics events, prefer Supplier Alpha, and exclude deprecated regions. The boolean filter keeps only the high-risk Supplier Alpha events:

Step 9: Build the hybrid inventory risk query

This step combines semantic search with multiple filter dimensions — category, stock level, risk, and supplier — into a single reusable function. Each filter parameter is optional, so the function adapts to different query scenarios without code changes. Running the example call returns the high-risk, low-stock electronics events that are semantically closest to the query.
Hybrid retrieval combines vector similarity with structured constraints to deliver results that are both semantically relevant and operationally valid. The hybrid query narrows results to high-risk, low-stock electronics events matching the query:

Step 10: Build the risk reasoning layer

Retrieval alone is not enough. The following function adds a rule-based reasoning layer that evaluates each retrieved event’s payload and returns a list of structured risk alerts. Each alert includes a rule name, severity, recommended message, and action.
This is where the system becomes an agent rather than a search tool. The risk engine runs five rules against each event, as shown in the table below:

Step 11: Run the end-to-end flow

The following code connects all the pieces into a single pipeline function and runs it with a sample query. Calling run_risk_intelligence performs a hybrid semantic search, then runs the risk reasoning layer on every result and prints all triggered alerts with their severity and recommended action.
The end-to-end pipeline prints the query, applied filters, and all risk alerts for each matched event:

Step 12: Retrieve a specific event by ID for risk assessment

Actian VectorAI DB supports retrieving points by ID using points.get, which is useful for inspecting individual events without running a vector search. The following code fetches event ID 0 and runs the risk reasoning layer against it, printing the event summary and any triggered alerts.
Direct point retrieval via points.get allows the system to inspect specific events without a vector search, which is useful for dashboards and audit trails.

Step 13: Collection administration

Actian VectorAI provides Vector Data Engine (VDE) operations for managing collections. Use get_vector_count to check collection size and flush to persist data to disk (already shown in step 5). To remove a collection entirely, call client.collections.delete(COLLECTION).

Actian VectorAI features used

The following table summarizes every Actian VectorAI DB API used in this tutorial and the role each one plays:

Conclusion

This tutorial built an AI supply chain inventory risk intelligence agent using Actian VectorAI DB as the retrieval engine. The full pipeline covered the following steps:
  • Create a collection with VectorParams and HnswConfigDiff.
  • Embed supply chain events with all-MiniLM-L6-v2 (384-dim).
  • Store vectors with rich payload metadata via PointStruct.
  • Run semantic search with points.search.
  • Refine results with the type-safe Field / FilterBuilder DSL.
  • Retrieve specific events by ID with points.get.
  • Apply a rule-based risk reasoning layer.
  • Generate actionable inventory risk alerts.
This pattern is a strong fit for vector databases. Supply chain failures are rarely caused by one keyword or one threshold crossing. They emerge from combinations of semantically related events, metadata, recency, and location. Actian VectorAI’s semantic retrieval and payload filter DSL let you detect these risk patterns before they turn into costly disruptions.

Next steps

Explore these related tutorials to deepen your understanding of the Actian VectorAI DB features used in this workflow:

Reranking search results

Improve relevance with cross-encoder and reciprocal rank fusion reranking

Similarity search

Learn the core similarity search workflow

Predicate filters

Combine vector search with structured payload constraints

Retrieval quality

Measure and optimize search accuracy using precision, recall, and MRR