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 Cloud

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogWhite PaperLive 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 Cloud
    iconOceanBase Cloud
    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

      Integrate OceanBase Cloud vector retrieval with LangChain

      Last Updated:2026-04-07 08:08:34  Updated
      Share
      What is on this page
      Prerequisites
      Step 1: Obtain the database connection information
      Step 2: Register an LLM account
      Step 3: Build an AI assistant
      Clone the relevant code repository for third-party integration on GitHub
      Load and split a document
      Insert the data into OceanBase Cloud
      Perform vector search

      folded

      Share

      OceanBase Database supports vector data storage, vector indexes, and embedding vector retrieval in V4.3.3 and later. You can store vectorized data in OceanBase Database for further retrieval.

      LangChain is a framework for developing language model-driven applications. It enables an application to have the following capabilities:

      • Context awareness: The application can connect language models to context sources, such as prompt instructions, a few examples, and content requiring responses.

      • Reasoning: The application can perform reasoning based on language models. For example, it can decide how to answer a question or what actions to take based on the provided context.

      This topic describes how to integrate the vector retrieval feature of OceanBase Cloud, Tongyi Qianwen (Qwen), and LangChain for Document Question Answering (DQA).

      Prerequisites

      • A transactional cluster instance of the MySQL compatible mode is available in your environment.

      • To use a cluster instance, you first need to create a tenant by referring to Create a tenant.

      • You have created a MySQL-compatible tenant, a database, and an account, and granted the read and write permissions to the database account. For more information, see Create an account and Create a database (MySQL compatible mode).

      • You have been granted the project admin or instance admin role to perform read and write operations on instances in the project. If you do not have the required permissions, contact the organization admin.

      • You have installed Python 3.9 or later and pip. If Python installed on your server is of an early version, you can use Miniconda to build a new environment of Python 3.9 or later. For more information, see Installing Miniconda.

      • You have installed Poetry, Pyobvector, and DashScope. The installation commands are as follows:

        python3 -m pip install poetry
        python3 -m pip install pyobvector
        python3 -m pip install dashscope
        
      • You have installed LangChain. The installation command is as follows:

        python3 -m pip install langchain
        

      Step 1: Obtain the database connection information

      1. Log in to the OceanBase Cloud console.

      2. In the instance list page, expand the the information of the target instance.

      3. Select Connect > Get Connection String under the target tenant.

      4. In the pop-up window, select Public Network as the connection method.

      5. Follow the prompts in the pop-up window to obtain the public endpoint and the connection string.

      Step 2: Register an LLM account

      Register an Alibaba Cloud Model Studio account, activate the model service, and obtain an API key.

      Notice

      Activating the model service requires you to visit a third-party platform. This operation will follow the billing rules of the third-party platform and may incur corresponding fees. Please visit its official website or view the relevant documentation to confirm and accept its billing standards before proceeding. If you disagree, please do not proceed with the operation.

      Specify the API key for the relevant environment variable.

      export DASHSCOPE_API_KEY="YOUR_DASHSCOPE_API_KEY"
      

      Step 3: Build an AI assistant

      Clone the relevant code repository for third-party integration on GitHub

      git clone -b obvec https://github.com/GITHUBear/langchain.git
      cd langchain/libs/community
      

      Load and split a document

      The project contains sample data, which is stored in ./../docs/docs/how_to/state_of_the_union.txt. Use CharacterTextSplitter to split the document of sample data into blocks, with each block containing about 1,000 characters.

      from langchain_community.document_loaders import TextLoader
      from langchain_community.embeddings import DashScopeEmbeddings
      from langchain_community.vectorstores import OceanBase
      from langchain_text_splitters import CharacterTextSplitter
      import os
      
      DASHSCOPE_API = os.environ.get("DASHSCOPE_API_KEY", "")
      embeddings = DashScopeEmbeddings(
          model="text-embedding-v1", dashscope_api_key=DASHSCOPE_API
      )
      loader = TextLoader("../../docs/docs/how_to/state_of_the_union.txt")
      documents = loader.load()
      text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
      docs = text_splitter.split_documents(documents)
      

      Insert the data into OceanBase Cloud

      connection_args = {
          "host": "127.0.0.1",
          "port": "2881",
          "user": "root@test",
          "password": "",
          "db_name": "test",
      }
      DEMO_TABLE_NAME = "demo_ann"
      ob = OceanBase(
          embedding_function=embeddings,
          table_name=DEMO_TABLE_NAME,
          connection_args=connection_args,
          drop_old=True,
          normalize=True,
      )
      res = ob.add_documents(documents=docs)
      

      Perform vector search

      Here is an example of searching for "What did the president say about Ketanji Brown Jackson" from state_of_the_union.txt:

      query = "What did the president say about Ketanji Brown Jackson"
      docs_with_score = ob.similarity_search_with_score(query, k=3)
      
      for doc, score in docs_with_score:
          print("-" * 80)
          print("Score: ", score)
          print(doc.page_content)
          print("-" * 80)
      

      The expected output is as follows:

      --------------------------------------------------------------------------------
      Score:  1.204783671324283
      Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. 
      
      Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. 
      
      One of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. 
      
      And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
      --------------------------------------------------------------------------------
      --------------------------------------------------------------------------------
      Score:  1.2146663629717394
      It is going to transform America and put us on a path to win the economic competition of the 21st Century that we face with the rest of the world—particularly with China.  
      
      As I’ve told Xi Jinping, it is never a good bet to bet against the American people. 
      
      We’ll create good jobs for millions of Americans, modernizing roads, airports, ports, and waterways all across America. 
      
      And we’ll do it all to withstand the devastating effects of the climate crisis and promote environmental justice. 
      
      We’ll build a national network of 500,000 electric vehicle charging stations, begin to replace poisonous lead pipes—so every child—and every American—has clean water to drink at home and at school, provide affordable high-speed internet for every American—urban, suburban, rural, and tribal communities. 
      
      4,000 projects have already been announced. 
      
      And tonight, I’m announcing that this year we will start fixing over 65,000 miles of highway and 1,500 bridges in disrepair.
      --------------------------------------------------------------------------------
      --------------------------------------------------------------------------------
      Score:  1.2193955178945004
      Vice President Harris and I ran for office with a new economic vision for America. 
      
      Invest in America. Educate Americans. Grow the workforce. Build the economy from the bottom up  
      and the middle out, not from the top down.  
      
      Because we know that when the middle class grows, the poor have a ladder up and the wealthy do very well. 
      
      America used to have the best roads, bridges, and airports on Earth. 
      
      Now our infrastructure is ranked 13th in the world. 
      
      We won’t be able to compete for the jobs of the 21st Century if we don’t fix that. 
      
      That’s why it was so important to pass the Bipartisan Infrastructure Law—the most sweeping investment to rebuild America in history. 
      
      This was a bipartisan effort, and I want to thank the members of both parties who worked to make it happen. 
      
      We’re done talking about infrastructure weeks. 
      
      We’re going to have an infrastructure decade.
      --------------------------------------------------------------------------------
      

      Previous topic

      Dify
      Last

      Next topic

      Tongyi Qianwen
      Next
      What is on this page
      Prerequisites
      Step 1: Obtain the database connection information
      Step 2: Register an LLM account
      Step 3: Build an AI assistant
      Clone the relevant code repository for third-party integration on GitHub
      Load and split a document
      Insert the data into OceanBase Cloud
      Perform vector search