OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.4.2

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.4.2
    iconOceanBase Database
    SQL - V 4.4.2
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Integrate OceanBase vector search with Spring AI Alibaba

    Last Updated:2026-04-09 08:31:39  Updated
    Share
    What is on this page
    Prerequisites
    Step 1: Obtain the database connection information
    Step 2: Set up the Maven project
    Create a project
    Configure the pom.xml file
    Step 3: Configure the connection information of OceanBase
    Step 4: Create the main application class and controller
    Create an application startup class
    Create a vector storage controller
    Step 5: Start and test the Maven project
    Start the project using an IDE
    Test the project
    FAQ
    OceanBase connection failure
    Dependency conflict
    SNAPSHOT dependency cannot be downloaded

    folded

    Share

    OceanBase supports vector data storage, vector indexing, and embedding-based vector search starting with V4.3.3. You can store vectorized data in OceanBase for further search.

    The Spring AI Alibaba project is an open-source project that uses Spring AI and provides the best practices for developing Java applications with AI. It simplifies the AI application development process and adapts to cloud-native infrastructure. It helps developers quickly build AI applications.

    This topic describes how to integrate the vector search capability of OceanBase with Spring AI Alibaba to implement data import and similarity search features. By configuring vector storage and search services, developers can easily build AI application scenarios based on OceanBase, supporting advanced features such as text similarity search and content recommendation.

    Prerequisites

    • You have deployed OceanBase Database and created a MySQL-compatible user tenant. For more information, see Create a tenant.

      • You have set the ob_vector_memory_limit_percentage parameter to enable vector search. We recommend that you set the value to 30. For more information about how to calculate this parameter, see ob_vector_memory_limit_percentage.
    • Download JDK 17+. Make sure that you have installed Java 17 and configured the environment variables.

    • Download Maven. Make sure that you have installed Maven 3.6+ for building projects and managing dependencies.

    • Download IntelliJ IDEA or Eclipse. Choose the version that suits your operating system and install it.

    Step 1: Obtain the database connection information

    Contact the OceanBase deployment personnel or administrator to obtain the database connection string. For example:

    obclient -h$host -P$port -u$user_name -p$password -D$database_name
    

    Parameters:

    • $host: the IP address for connecting to OceanBase Database. If you connect to OceanBase Database through OceanBase Database Proxy (ODP), specify an ODP IP address. If you connect to OceanBase Database directly, specify the IP address of an OBServer node.

    • $port: the port for connecting to OceanBase Database. If you connect to OceanBase Database through ODP, the default port is 2883, which can be customized when you deploy ODP. If you connect to OceanBase Database directly, the default port is 2881, which can be customized when you deploy OceanBase Database.

    • $database_name: the name of the database to be accessed.

      Notice

      The user for connecting to the tenant must have the CREATE, INSERT, DROP, and SELECT privileges on the database. For more information about user privileges, see Privilege types in MySQL-compatible mode.

    • $user_name: the tenant connection account. If you connect to OceanBase Database through ODP, the account is in the username@tenant name#cluster name or cluster name:tenant name:username format. If you connect to OceanBase Database directly, the account is in the username@tenant name format.

    • $password: the account password.

    For more information about the connection string, see Connect to an OceanBase tenant by using OBClient.

    Step 2: Set up the Maven project

    Maven is a project management and build tool used in this topic. This step describes how to create a Maven project and add project dependencies by configuring the pom.xml file.

    Create a project

    1. Run the following Maven command to create a project.

      mvn archetype:generate -DgroupId=com.alibaba.cloud.ai.example -DartifactId=vector-oceanbase-example -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
      
    2. Go to the project directory.

      cd vector-oceanbase-example
      

    Configure the pom.xml file

    The pom.xml file is the core configuration file of the Maven project, used to manage project dependencies, plugins, configurations, and other information. To build the project, you need to modify the pom.xml file and add Spring AI Alibaba, OceanBase vector storage, and other necessary dependencies.

    Open the pom.xml file and replace the existing content with the following:

        <project xmlns="http://maven.apache.org/POM/4.0.0"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
            <modelVersion>4.0.0</modelVersion>
            <parent>
                <groupId>com.alibaba.cloud.ai.example</groupId>
                <artifactId>spring-ai-alibaba-vector-databases-example</artifactId>
                <version>1.0.0</version>
            </parent>
    
            <artifactId>vector-oceanbase-example</artifactId>
    
            <properties>
                <maven.compiler.source>17</maven.compiler.source>
                <maven.compiler.target>17</maven.compiler.target>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            </properties>
    
            <dependencies>
                <!-- Alibaba Cloud AI starter -->
                <dependency>
                    <groupId>com.alibaba.cloud.ai</groupId>
                    <artifactId>spring-ai-alibaba-starter</artifactId>
                </dependency>
    
                <!-- Spring Boot Web support -->
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-web</artifactId>
                </dependency>
    
                <!-- Spring AI auto-configuration -->
                <dependency>
                    <groupId>org.springframework.ai</groupId>
                    <artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
                </dependency>
    
                <!-- Spring JDBC support -->
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jdbc</artifactId>
                </dependency>
    
                <!-- Transformers model support -->
                <dependency>
                    <groupId>org.springframework.ai</groupId>
                    <artifactId>spring-ai-transformers</artifactId>
                </dependency>
    
                <!-- OceanBase Vector Database starter -->
                <dependency>
                    <groupId>com.alibaba.cloud.ai</groupId>
                    <artifactId>spring-ai-alibaba-starter-oceanbase-store</artifactId>
                    <version>1.0.0-M6.2-SNAPSHOT</version>
                </dependency>
    
                <!-- OceanBase JDBC driver -->
                <dependency>
                    <groupId>com.oceanbase</groupId>
                    <artifactId>oceanbase-client</artifactId>
                    <version>2.4.14</version>
                </dependency>
            </dependencies>
    
            <!-- SNAPSHOT repository configuration -->
            <repositories>
                <repository>
                    <id>sonatype-snapshots</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                    <releases>
                        <enabled>false</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
        </project>
    

    Step 3: Configure the connection information of OceanBase

    This step configures the application.yml file to add the connection information of OceanBase.

    Create the application.yml file in the src/main/resources directory of the project and add the following content:

    server:
      port: 8080
    
    spring:
      application:
        name: oceanbase-example
      ai:
        dashscope:
          api-key: ${DASHSCOPE_API_KEY}  # Replace with your DashScope API Key
        vectorstore:
          oceanbase:
            enabled: true
            url: jdbc:oceanbase://xxx:xxx/xxx  # URL for connecting to OceanBase
            username: xxx                     # Username of OceanBase
            password: xxx                     # Password of OceanBase
            tableName: vector_table           # Name of the vector table (automatically created)
            defaultTopK: 2                    # Default number of similar results to return
            defaultSimilarityThreshold: 0.8   # Similarity threshold (0~1, smaller values indicate higher similarity)
    

    Step 4: Create the main application class and controller

    Create the startup class and controller class of the Spring Boot application to implement the data import and similarity search features.

    Create an application startup class

    Create a file named OceanBaseApplication.java in the src/main/java/com/alibaba/cloud/ai/example/vector directory, and add the following code to the file:

    package com.alibaba.cloud.ai.example.vector;  // The package name must be consistent with the directory structure.
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    
    @SpringBootApplication  // Enable Spring Boot auto-configuration
    public class OceanBaseApplication {
        public static void main(String[] args) {
            SpringApplication.run(OceanBaseApplication.class, args);  // Start the Spring Boot application
        }
    }
    

    The sample code creates the core startup class for the project, which is used to start the Spring Boot application.

    Create a vector storage controller

    Create the OceanBaseController.java file in the src/main/java/com/alibaba/cloud/ai/example/vector directory and add the following code:

    package com.alibaba.cloud.ai.example.vector.controller;  // The package name must be consistent with the directory structure.
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.ai.document.Document;
    import org.springframework.ai.vectorstore.SearchRequest;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import com.alibaba.cloud.ai.vectorstore.oceanbase.OceanBaseVectorStore;
    
    @RestController  // Mark the class as a REST controller.
    @RequestMapping("/oceanbase")  // Set the base path to /oceanbase.
    public class OceanBaseController {
    
        private static final Logger logger = LoggerFactory.getLogger(OceanBaseController.class);  // The logger.
    
        @Autowired  // Automatically inject the OceanBase vector store service.
        private OceanBaseVectorStore oceanBaseVectorStore;
    
        // The data import interface.
        @GetMapping("/import")
        public void importData() {
            logger.info("Start importing data");
    
            // Create sample data.
            HashMap<String, Object> map = new HashMap<>();
            map.put("id", "12345");
            map.put("year", "2025");
            map.put("name", "yingzi");
    
            // Create a list that contains three documents.
            List<Document> documents = List.of(
                new Document("The World is Big and Salvation Lurks Around the Corner"),
                new Document("You walk forward facing the past and you turn back toward the future.", Map.of("year", 2024)),
                new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", map)
            );
    
            // Add the documents to the vector store.
            oceanBaseVectorStore.add(documents);
        }
    
        // The similar document search interface.
        @GetMapping("/search")
        public List<Document> search() {
            logger.info("Start searching data");
    
            // Perform a similarity search for documents that contain "Spring" and return the two most similar results.
            return oceanBaseVectorStore.similaritySearch(SearchRequest.builder()
                                                         .query("Spring")
                                                         .topK(2)
                                                         .build());
        }
    }
    

    Step 5: Start and test the Maven project

    Start the project using an IDE

    The following example shows how to start the project using IntelliJ IDEA.

    The steps are as follows:

    1. Open the project by clicking File > Open and selecting pom.xml.
    2. Select Open as a project.
    3. Find the main class OceanBaseApplication.java.
    4. Right-click and select Run 'OceanBaseApplication.main()'.

    Test the project

    1. Import the test data by visiting the following URL:

      http://localhost:8080/oceanbase/import
      
    2. Perform vector search by visiting the following URL:

      http://localhost:8080/oceanbase/search
      

      The expected result is as follows:

      [
          {
              "id": "03fe9aad-13cc-4d25-807b-ca1bc314f571",
              "text": "Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!",
              "metadata": {
                  "name": "yingzi",
                  "id": "12345",
                  "year": "2025",
                  "distance": "7.274442499114312"
              }
          },
          {
              "id": "75864954-0a23-4fa1-8e18-b78fd870d474",
              "text": "Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!",
              "metadata": {
                  "name": "yingzi",
                  "id": "12345",
                  "year": "2025",
                  "distance": "7.274442499114312"
              }
          }
      ]
      

    FAQ

    OceanBase connection failure

    • Cause: The URL, username, or password is incorrect.
    • Solution: Check the OceanBase configuration in application.yml and make sure the database service is running.

    Dependency conflict

    • Cause: Conflicts between multiple Spring Boot versions.
    • Solution: Run mvn dependency:tree to view the dependency tree and exclude the conflicting versions.

    SNAPSHOT dependency cannot be downloaded

    • Cause: The SNAPSHOT repository is not configured.
    • Solution: Make sure that the sonatype-snapshots repository is added in pom.xml.

    Previous topic

    Trae
    Last

    Next topic

    Cline
    Next
    What is on this page
    Prerequisites
    Step 1: Obtain the database connection information
    Step 2: Set up the Maven project
    Create a project
    Configure the pom.xml file
    Step 3: Configure the connection information of OceanBase
    Step 4: Create the main application class and controller
    Create an application startup class
    Create a vector storage controller
    Step 5: Start and test the Maven project
    Start the project using an IDE
    Test the project
    FAQ
    OceanBase connection failure
    Dependency conflict
    SNAPSHOT dependency cannot be downloaded