mariadb(MariaDB 矢量版:專為 AI 設計)

時間:2025-01-26 23:06:09 閱讀:8

MariaDB 矢量版:專為 AI 計劃

在專門構建的人工智能數據庫年代,像 MariaDB 如此的傳統數據庫怎樣重塑本身以堅持干系性?在這篇中找出答案。

作為一名在干系數據庫體系方面擁有二十多年履歷的處理方案架構師,我邇來開頭探究 MariaDB 的新矢量版本,看看它對否可以處理我們面臨的一些人工智能數據挑唆。快速欣賞一下仿佛十分有壓服力,尤其是它怎樣將人工智能邪術直接帶入常規數據庫設置中。但是,我想用一個簡便的用例來測試它,看看它在實踐中的體現怎樣。

在本文中,我將經過運轉一個簡便的用例來分享我對 MariaDB向量功效的實踐履歷和察看。具體來說,我將把示例客戶批評加載到 MariaDB 中,并實行快速相似性搜刮來查找干系批評。

情況設置

  • Python 3.10 或更高版本
  • Docker 桌面

我的實行從使用包含矢量功效的 MariaDB最新版本 (11.6)設置Docker容器開頭。

# Pull the latest release docker pull quay.io/mariadb-foundation/mariadb-devel:11.6-vector-preview # Update password docker run -d --name mariadb_vector -e MYSQL_ROOT_PASSWORD=<replace_password> quay.io/mariadb-foundation/mariadb-devel:11.6-vector-preview

如今,創建一個表并加載示例客戶批評,此中包含每個批評的心情評分和嵌入。為了天生文本嵌入,我使用SentenceTransformer ,它允許您使用事后練習的模子。具體來說,我決定使用一個名為 paraphrase-MiniLM-L6-v2 的模子,該模子獲取我們的客戶批評并將其映射到 384 維空間。

import mysql.connector import numpy as np from sentence_transformers import SentenceTransformer model = SentenceTransformer('paraphrase-MiniLM-L6-v2') # I already have a database created with a name vectordb connection = mysql.connector.connect( host="localhost", user="root", password="<password>", # Replace me database="vectordb" ) cursor = connection.cursor() # Create a table to store customer reviews with sentiment score and embeddings. cursor.execute(""" CREATE TABLE IF NOT EXISTS customer_reviews ( id INT PRIMARY KEY AUTO_INCREMENT, product_name INT, customer_review TEXT, customer_sentiment_score FLOAT, customer_review_embedding BLOB, INDEX vector_idx (customer_review_embedding) USING HNSW ) ENGINE=ColumnStore; """) # Sample reviews reviews = [ (1, "This product exceeded my expectations. Highly recommended!", 0.9), (1, "Decent quality, but pricey.", 0.6), (2, "Terrible experience. The product does not work.", 0.1), (2, "Average product, ok ok", 0.5), (3, "Absolutely love it! Best purchase I have made this year.", 1.0) ] # Load sample reviews into vector DB for product_id, review_text, sentiment_score in reviews: embedding = model.encode(review_text) cursor.execute( "INSERT INTO customer_reviews (product_id, review_text, sentiment_score, review_embedding) VALUES (%s, %s, %s, %s)", (product_id, review_text, sentiment_score, embedding.tobytes())) connection.commit() connection.close()

如今,讓我們使用 MariaDB 的矢量功效來查找相似的批評。這更像是在問“其他主顧也說過相似的批評嗎? ”。在底下的示例中,我將找到相似于“我十分滿意! ”的客戶批評的前 2 條批評。為此,我使用最新版本中提供的矢量函數 ( VEC_Distance_Euclidean ) 之一。

# Convert the target customer review into vector target_review_embedding = model.encode("I am super satisfied!") # Find top 2 similar reviews using MariaDB's VEC_Distance_Euclidean function cursor.execute(""" SELECT review_text, sentiment_score, VEC_Distance_Euclidean(review_embedding, %s) AS similarity FROM customer_reviews ORDER BY similarity LIMIT %s """, (target_review_embedding.tobytes(), 2)) similar_reviews = cursor.fetchall()

察看后果

  • 它很容易設置,我們可以將布局化數據(如產物 ID 和心情分數)、非布局化數據(批評文本)及其向量表現情勢組合在一個表中。
  • 我喜好它使用 SQL 語法和向量運算的才能,這使得以前熟習干系數據庫的團隊可以輕松使用。以下是此版本中支持的向量函數的完備列表。
  • HNSW 索引提高了我迄今為止實驗過的較大數據集的相似性搜刮查詢的功能。

結論

總的來說,我印象深入! MariaDB 的矢量版將簡化某些人工智能驅動的架構。它彌合了傳統數據庫天下與人工智能東西不休提高的需求之間的差距。在接下去的幾個月中,我渴望看到這項武藝怎樣成熟以及社區如安在實踐使用中接納它。

版權聲明:本文來自互聯網整理發布,如有侵權,聯系刪除

原文鏈接:http://m.avtt22014.comhttp://m.avtt22014.com/shenghuojineng/57964.html


Copyright ? 2021-2022 All Rights Reserved 備案編號:閩ICP備2023009674號 網站地圖 聯系:dhh0407@outlook.com

主站蜘蛛池模板: 免费看男人j放进女人j色多多| 忘忧草日本在线播放www| 国产无卡一级毛片aaa| 亚洲制服欧美自拍另类| 888午夜不卡理论久久| 三级理论中文字幕在线播放| 韩国精品一区视频在线播放| 最新中文字幕在线| 国产成人亚洲综合一区| 免费黄色福利视频| 一级毛片无遮挡免费全部| 性欧美videos高清喷水| 欧美一级中文字幕| 国产成人影院在线观看| 久久亚洲国产成人精品无码区| 99免费在线视频| 欧美色图在线观看| 国产精品大片天天看片| 亚洲乱码一区二区三区在线观看 | 99久久精品国产免费| 欧美精选欧美极品| 国产精品久久久久久福利| 九月婷婷人人澡人人添人人爽 | 亚洲一区二区观看播放| 91在线丨亚洲| 无主之花2025韩语中字| 再深点灬舒服了灬太大了乡村 | 国模极品一区二区三区| 亚洲国产精品日韩专区av| GOGOGO免费观看国语| 精品人妻一区二区三区四区 | 国内精品福利在线视频| 亚洲国产精品综合久久网各| 日本人强jizz多人| 日本夫妇交换456高清| 天堂网在线观看| 六月丁香综合网| 97在线公开视频| 最近在线中文字幕影院网| 国产一级理仑片日本| uyghur69sexvideos|