Elasticsearch:探索 CLIP 替代方案

作者:来自 Elastic Jeffrey Rengifo 及 Tomás Murúa

分析图像到图像和文本到图像搜索的 CLIP 模型的替代方案。

在本文中,我们将通过一个模拟房地产网站的实际示例介绍 CLIP 多模态模型,探索替代方案,并分析它们的优缺点,该网站允许用户使用图片作为参考来搜索房产。

什么是 CLIP?

CLIP(Contrastive Language–Image Pre-training - 对比语言 - 图像预训练)是由 OpenAI 创建的神经网络,使用图像和文本对进行训练,以解决在文本和图像之间寻找相似性的任务,并对 “零样本” 图像进行分类,因此模型不是使用固定标签进行训练的,而是我们为模型提供未知类别,以便它可以对我们提供的图像进行分类。

CLIP 一直是最先进的模型,你可以在此处阅读有关它的更多文章:

  • 实现图像搜索
  • 如何实现图像相似性搜索

然而,随着时间的推移,出现了更多的替代方案。

在本文中,我们将使用房地产示例介绍 CLIP 的两种替代方案的优缺点。以下是我们在本文中将遵循的步骤的摘要:

基本配置:CLIP 和 Elasticsearch

在我们的示例中,我们将使用 Python 创建一个带有交互式 UI 的小项目。我们将安装一些依赖项,例如 Python 转换器,这将授予我们访问我们将使用的某些模型的权限。

创建一个文件夹 /clip_comparison 并按照此处的安装说明进行操作。完成后,安装 Elasticsearch 的 Python 客户端、Cohere SDK 和 Streamlit:

注意:作为一种选择,我建议使用 Python 虚拟环境 (venv)。如果你不想在计算机上安装所有依赖项,这将非常有用。

pip install elasticsearch==8.15.0 cohere streamlit

Streamlit 是一个开源 Python 框架,可让你使用少量代码轻松获得 UI。

我们还将创建一些文件来保存稍后将使用的指令:

  • app.py:UI 逻辑。
  • /services/elasticsearch.py​​:Elasticsearch 客户端初始化、查询和批量 API 调用以索引文档。
  • /services/models.py:用于生成嵌入的模型实例和方法。
  • index_data.py:用于从本地源索引图像的脚本。
  • /data:我们的数据集目录。

我们的应用程序结构应如下所示:

/clip_comparison|--app.py|--index_data.py|--/data|--/venv # If you decide to use venv|--/services|-- __init__.py|-- models.py|-- elasticsearch.py

配置 Elasticsearch

按照以下步骤存储示例图像。然后我们将使用 knn 向量查询搜索它们。

注意:我们也可以存储文本文档,但对于此示例,我们将仅在图像中搜索。

索引映射

访问 Kibana 开发工具(从 Kibana:Management > Dev Tools)以使用这些映射构建数据结构:

[ ]
PUT clip-images
{"mappings": {"properties": {"image_name": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"image_embedding": {"type": "dense_vector","dims": 768,"index": "true","similarity": "cosine"},"image_data": {"type": "binary"}}}
}PUT embed-images
{"mappings": {"properties": {"image_name": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"image_embedding": {"type": "dense_vector","dims": 1024,"index": "true","similarity": "cosine"},"image_data": {"type": "binary"}}}
}
PUT jina-images
{"mappings": {"properties": {"image_name": {"type": "text","fields": {"keyword": {"type": "keyword"}}},"image_embedding": {"type": "dense_vector","dims": 768,"index": "true","similarity": "cosine"},"image_data": {"type": "binary"}}}
}

字段类型 dense_vector 将存储模型生成的嵌入。字段 binary 将以 base64 格式存储图像。

注意:将图像以二进制形式存储在 Elasticsearch 中不是一个好习惯。我们这样做只是为了这个例子的实际目的。建议使用静态文件存储库。

现在来看看代码。我们需要做的第一件事是使用 cloud id 和 api-key 初始化 Elasticsearch 客户端。在文件 /services/elasticsearch.py​​ 的开头写入以下代码:

[ ]
from elasticsearch import Elasticsearch, exceptions, helpers
ELASTIC_ENDPOINT = "https://your-elastic-endpoint.com:9243"
ELASTIC_API_KEY = "your-elasticsearch-api-key"
# Elasticsearch client
es_client = Elasticsearch(ELASTIC_ENDPOINT,api_key=ELASTIC_API_KEY,
)
# index documents using bulk api
def index_images(index_name: str, images_obj_arr: list):actions = [{"_index": index_name,"_source": {"image_data": obj["image_data"],"image_name": obj["image_name"],"image_embedding": obj["image_embedding"],},}for obj in images_obj_arr]try:response = helpers.bulk(es_client, actions)return responseexcept exceptions.ConnectionError as e:return e# knn search
def knn_search(index_name: str, query_vector: list, k: int):query = {"size": 4,"_source": ["image_name", "image_data"],"query": {"knn": {"field": "image_embedding","query_vector": query_vector,"k": k,"num_candidates": 100,"boost": 10,}},}try:response = es_client.search(index=index_name, body=query)return responseexcept exceptions.ConnectionError as e:return e
# match all query
def get_all_query(index_name: str):query = {"size": 400,"source": ["image_name", "image_data"],"query": {"match_all": {}},}try:return es_client.search(index=index_name, body=query)except exceptions.ConnectionError as e:return e

配置模型

要配置模型,请将模型实例及其方法放入此文件中:/services/models.py。

Cohere Embed-3 模型作为 Web 服务工作,因此我们需要一个 API 密钥才能使用它。你可以在此处免费获取一个。试用限制为每分钟 5 次调用,每月 1,000 次调用。

要配置模型并使图像可在 Elasticsearch 中搜索,请按照以下步骤操作:

  • 使用 CLIP 将图像转换为向量
  • 将图像像量存储在 Elasticsearch 中
  • 将我们要与存储的图像进行比较的图像或文本向量化。
  • 运行查询以将上一步的条目与存储的图像进行比较并获取最相似的图像。
[ ]
# /services/models.py
# dependencies
import base64
import io
import cohere
from PIL import Image
from transformers import CLIPModel, CLIPProcessor, AutoModel
COHERE_API_KEY = "your-cohere-api-key"
## CLIP model call
clip_model = CLIPModel.from_pretrained("openai/clip-vit-large-patch14")
clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14")
# JinaCLip model call
jina_model = AutoModel.from_pretrained("jinaai/jina-clip-v1", trust_remote_code=True)
# Cohere client initialization
co = cohere.ClientV2(COHERE_API_KEY)

配置 CLIP

要配置 CLIP,我们需要在 models.py 文件中添加生成图像和文本嵌入的方法。

# /services/models.py
# convert images to vector using CLIP
async def clip_image_embeddings(image: Image.Image):try:inputs = clip_processor(images=image, return_tensors="pt", padding=True)outputs = clip_model.get_image_features(**inputs)return outputs.detach().cpu().numpy().flatten().tolist()except Exception as e:print(f"Error generating embeddings: {e}")return None
# convert text to to vector
async def clip_text_embeddings(description: str):try:inputs = clip_processor([description], padding=True, return_tensors="pt")outputs = clip_model.get_text_features(**inputs)return outputs.detach().cpu().numpy().flatten().tolist()except Exception as e:print(f"Error generating embeddings: {e}")return None

对于所有模型,你需要声明类似的方法:一个用于从图像生成嵌入(clip_image_embeddings),另一个用于从文本生成嵌入(clip_text_embeddings)。

outputs.detach().cpu().numpy().flatten().tolist() 链是一种将 pytorch tensors 转换为更可用格式的常见操作:

  • .detach():从计算图中删除张量,因为我们不再需要计算梯度。
  • .cpu():将 tensors 从 GPU 移动到 CPU,因为 numpy 仅支持 CPU。
  • .numpy():将 tensors 转换为 numPy 数组。
  • .flatten():转换为 1D 数组。
  • .toList():转换为 Python 列表。

此操作将多维 tensor 转换为可用于嵌入操作的纯数字列表。

现在让我们看一些 CLIP 替代方案。

竞争对手 1:JinaCLIP

JinaCLIP 是 Jina AI 开发的 CLIP 变体,专门用于改进多模态应用中的图像和文本搜索。它通过增加图像和文本表示的灵活性来优化 CLIP 性能。

与原始 OpenAI CLIP 模型相比,JinaCLIP 在文本转文本、文本转图像、图像转文本和图像转图像任务中表现更好,如下图所示:

ModelText-TextText-to-ImageImage-to-TextImage-Image
jina-clip-v10.4290.8990.8030.916
openai-clip-vit-b160.1620.8810.7560.816
%increase vs OpenAI CLIP165%2%6%12%

它能够提高不同类型查询的精度,因此非常适合需要更精确、更详细分析的任务。

你可以在此处阅读有关 JinaCLIP 的更多信息。

要在我们的应用中使用 JinaCLIP 并生成嵌入,我们需要声明以下方法:

[ ]
# /services/models.py
# convert images to vector using JinaClip model
async def jina_image_embeddings(image: Image.Image):try:image_embeddings = jina_model.encode_image([image])return image_embeddings[0].tolist()except Exception as e:print(f"Error generating embeddings: {e}")return None
# convert text to vector
async def jina_text_embeddings(description: str):try:text_embeddings = jina_model.encode_text(description)return text_embeddings.tolist()except Exception as e:print(f"Error generating embeddings: {e}")return None

竞争对手 2:Cohere Image Embeddings V3

Cohere 开发了一种名为 Embed-3 的图像嵌入模型,它是 CLIP 的直接竞争对手。主要区别在于 Cohere 专注于企业数据(如图表、产品图像和设计文件)的表示。Embed-3 使用一种先进的架构,可以降低对文本数据的偏见风险,这目前是 CLIP 等其他多模态模型的劣势,因此它可以在文本和图像之间提供更精确的结果。

你可以在下方看到 Cohere 的图表,该图表显示了在这种数据中使用 Embed 3 与 CLIP 相比的改进结果:

有关更多信息,请访问 Embed3。

就像我们对之前的模型所做的那样,让我们​​声明使用 Embed 3 的方法:

[ ]
# /services/models.py
# convert images to vector using Cohere Embed model
async def embed_image_embeddings(image: Image.Image):try:img_byte_arr = io.BytesIO()image.save(img_byte_arr, format="JPEG")img_byte_arr = img_byte_arr.getvalue()stringified_buffer = base64.b64encode(img_byte_arr).decode("utf-8")content_type = "image/jpeg"image_base64 = f"data:{content_type};base64,{stringified_buffer}"response = co.embed(model="embed-english-v3.0",input_type="image",embedding_types=["float"],images=[image_base64],)return response.embeddings.float_[0]except Exception as e:print(f"Error generating embeddings: {e}")return None
# convert text to vector
async def embed_text_embeddings(description: str):try:response = co.embed(texts=[description],model="embed-english-v3.0",input_type="classification",embedding_types=["float"],)return response.embeddings.float_[0]except Exception as e:print(f"Error generating embeddings: {e}")return None

准备好函数后,让我们通过在文件 index_data.py 中添加以下代码来在 Elasticsearch 中索引数据集:

[ ]
# dependencies
import asyncio
import base64
import os
from PIL import Image
from services.elasticsearch import index_images
from services.models import (clip_image_embeddings,embed_image_embeddings,jina_image_embeddings,
)
# function to encode images
def encode_image_to_base64(image_path):with open(image_path, "rb") as img_file:return base64.b64encode(img_file.read()).decode("utf-8")
async def main():# folder with imagesfolder_path = "./data"jina_obj_arr = []embed_obj_arr = []clip_obj_arr = []for filename in os.listdir(folder_path):img_path = os.path.join(folder_path, filename)print(f"Processing {filename}...")try:image_data = Image.open(img_path)# generating images embeddingsclip_result, embed_result, jina_result = await asyncio.gather(clip_image_embeddings(image_data),embed_image_embeddings(image_data),jina_image_embeddings(image_data),)image_base64 = encode_image_to_base64(img_path)# building documentsjina_obj_arr.append({"image_name": filename,"image_embedding": jina_result,"image_data": image_base64,})embed_obj_arr.append({"image_name": filename,"image_embedding": embed_result,"image_data": image_base64,})clip_obj_arr.append({"image_name": filename,"image_embedding": clip_result,"image_data": image_base64,})except Exception as e:print(f"Error with {filename}: {e}")print("Indexing images in Elasticsearch...")# indexing imagesjina_count, _ = index_images(jina_index, jina_obj_arr)cohere_count, _ = index_images(embed_index, cohere_obj_arr)openai_count, _ = index_images(clip_index, openai_obj_arr)print("Cohere count: ", cohere_count)print("Jina count: ", jina_count)print("OpenAI count: ", openai_count)
if __name__ == "__main__":asyncio.run(main())

使用以下命令对文档进行索引:

python index_data.py

一旦数据集被索引,我们就可以创建 UI。

测试 UI

创建 UI

我们将使用 Streamlit 构建 UI 并并排比较这三种替代方案。

要构建 UI,我们首先将导入和依赖项添加到文件 app.py:

[ ]
# app.py
import asyncio
import base64
from io import BytesIO
import streamlit as st
from PIL import Image
from services.elasticsearch import get_all_query, knn_search
# declared functions imports
from services.models import (clip_image_embeddings,clip_text_embeddings,embed_image_embeddings,embed_text_embeddings,jina_image_embeddings,jina_text_embeddings,
)

对于此示例,我们将使用两个视图;一个用于图像搜索,另一个用于查看图像数据集:

[ ]
# app.py
if "selected_view" not in st.session_state:st.session_state.selected_view = "Index"
def change_view(view):st.session_state.selected_view = view
st.sidebar.title("Menu")
if st.sidebar.button("Search image"):change_view("Index")
if st.sidebar.button("All images"):change_view("Images")

让我们添加搜索图像的视图代码:

[ ]
if st.session_state.selected_view == "Index":# Index pagest.title("Image Search")col1, col_or, col2 = st.columns([2, 1, 2])uploaded_image = Nonewith col1:uploaded_image = st.file_uploader("Upload image", type=["jpg", "jpeg", "png"])with col_or:st.markdown("<h3 style='text-align: center; margin-top: 50%;'>OR</h3>",unsafe_allow_html=True,)input_text = Nonewith col2:st.markdown("<div style='display: flex; margin-top: 3rem;  align-items: center; height: 100%; justify-content: center;'>",unsafe_allow_html=True,)input_text = st.text_input("Type text")st.markdown("</div>", unsafe_allow_html=True)st.write("")st.write("")search_button = st.markdown("""<style>.stButton>button {width: 50%;height: 50px;font-size: 20px;margin: 0 auto;display: block;}</style>""",unsafe_allow_html=True,)submit_button = st.button("Search")if uploaded_image:st.image(uploaded_image, caption="Uploaded Image", use_container_width=True)if submit_button:if uploaded_image or input_text:async def fetch_embeddings():data = Noneif uploaded_image:image = Image.open(uploaded_image)data = imageelif input_text:data = input_text# Getting image or text embeddingsif uploaded_image:openai_result, cohere_result, jina_result = await asyncio.gather(clip_image_embeddings(data),embed_image_embeddings(data),jina_image_embeddings(data),)elif input_text:openai_result, cohere_result, jina_result = await asyncio.gather(clip_text_embeddings(data),embed_text_embeddings(data),jina_text_embeddings(data),)return openai_result, cohere_result, jina_resultresults = asyncio.run(fetch_embeddings())openai_result, cohere_result, jina_result = resultsif openai_result and cohere_result and jina_result:# calling knn queryclip_search_results = knn_search("clip-images", openai_result, 5)jina_search_results = knn_search("jina-images", jina_result, 5)embed_search_results = knn_search("embed-images", cohere_result, 5)clip_search_results = clip_search_results["hits"]["hits"]jina_search_results = jina_search_results["hits"]["hits"]embed_search_results = embed_search_results["hits"]["hits"]st.subheader("Search Results")col1, spacer1, col2, spacer2, col3 = st.columns([3, 0.2, 3, 0.2, 3])def print_results(results):for hit in results:image_data = base64.b64decode(hit["_source"]["image_data"])image = Image.open(BytesIO(image_data))st.image(image, use_container_width=True)st.write("score: ", hit["_score"])# printing resultswith col1:st.write("CLIP")print_results(clip_search_results)with col2:st.write("JinaCLIP")print_results(jina_search_results)with col3:st.write("Cohere")print_results(embed_search_results)else:st.warning("Please upload an image or type text to search.")

现在,图像视图的代码:

[ ]
elif st.session_state.selected_view == "Images":# images pagest.header("All images")# getting all imagesimages = get_all_query("jina-images")hits = images["hits"]["hits"]columns = st.columns(5)for idx, hit in enumerate(hits):image_data = base64.b64decode(hit["_source"]["image_data"])image = Image.open(BytesIO(image_data))with columns[idx % 5]:st.image(image, use_container_width=True)

我们将使用以下命令运行该应用程序:

streamlit run app.py

使用 Elasticsearch 来进行图形搜索 - CLIP 替代品

由于多模态性,我们可以在图像数据库中根据文本(文本到图像的相似性)或图像(图像到图像的相似性)运行搜索。

使用 UI 搜索

为了比较这三种模型,我们将使用一个场景,即房地产网页希望通过允许用户使用图像或文本进行搜索来改善其搜索体验。我们将讨论每种模型提供的结果。

我们将上传 “rustic home” 的图片:

以下是搜索结果。如你所见,根据我们上传的图像,每个模型都生成了不同的结果:

此外,你还可以看到根据文本查找房屋特征的结果:

如果搜索 “modern”,这三个模型都会显示良好的结果。但是,JinaCLIP 和 Cohere 会在第一个位置显示相同的房屋。

功能比较

下面是本文中介绍的三个选项的主要功能和价格的摘要:

ModelCreated byEstimated PriceFeatures
CLIPOpenAI每次重复运行 0.00058 美元 (https://replicate.com/krthr/clip-embeddings)针对文本和图像的通用多模态模型;适用于无需特定训练的各种应用。
JinaCLIPJina AI每 100 万枚 Jina tokens 需 0.018 美元 (https://jina.ai/embeddings/)针对多模式应用优化的 CLIP 变体。提高了检索文本和图像的精度。
Embed-3CohereCohere 上每 100 万个 tokens 收费 0.10 美元,每份数据和图像收费 0.0001 美元(https://cohere.com/pricing)专注于企业数据。改进了图形和图表等复杂视觉数据的检索。

如果你要搜索长图像描述,或者想要进行文本转文本和图像转文本,则应放弃 CLIP,因为 JinaCLIP 和 Embed-3 都针对此用例进行了优化。

JinaCLIP 是一种通用模型,而 Cohere 的模型更侧重于企业数据,如产品或图表。

在数据上测试模型时,请确保涵盖:

  • 你感兴趣的所有模式:文本转图像、图像转文本、文本转文本
  • 长图像描述和短图像描述
  • 相似概念匹配(同一类型对象的不同图像)
  • 负面
    • 硬负面:与预期输出相似但仍然错误
    • 简单负面:与预期输出不相似且错误
  • 具有挑战性的场景
    • 不同的角度/视角
    • 各种照明条件
    • 抽象概念(“modern”、“cozy”、“luxurious”)
  • 特定领域案例
    • 技术图表或图表(尤其是 Embed-3)
    • 产品变化(颜色、尺寸、样式)

结论

虽然 CLIP 是进行图像相似性搜索时的首选模型,但在某些情况下,商业和非商业替代方案都可以表现得更好。

JinaCLIP 是一款强大的一体化工具,据称在文本到文本嵌入方面比 CLIP 更精确。

Embed-3 遵循 Cohere 的路线,通过使用典型的业务文档使用真实数据训练模型来满足业务客户的需求。

在我们的小实验中,我们可以看到 JinaClip 和 Cohere 都显示了有趣的图像到图像和文本到图像结果,并且在这些类型的任务中表现与 CLIP 非常相似。

Elasticsearch 允许你搜索嵌入,将向量搜索与全文搜索相结合,使你能够搜索图像和其中的文本。

想要获得 Elastic 认证?了解下一次 Elasticsearch 工程师培训的时间!

Elasticsearch 包含新功能,可帮助你为你的用例构建最佳搜索解决方案。深入了解我们的示例笔记本以了解更多信息,开始免费云试用,或立即在本地机器上试用 Elastic。

原文:Exploring CLIP alternatives - Elasticsearch Labs

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/20909.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Spring中的日志

日志 了解一下 (有个印象) 门面模式 (外观模式) 含有两种角色&#xff1a; Facade (外观角色 / 门面角色): 系统对外的统一接口。SubSystem (子系统角色): 可以含有多个子系统&#xff0c;每个子系统都不是单独的类&#xff0c;而是一个类的集合。 Facade 对 SubSystem 是…

uniapp邪门事件

很久之前在这篇《THREEJS 在 uni-app 中使用&#xff08;微信小程序&#xff09;》&#xff1a;THREEJS 在 uni-app 中使用&#xff08;微信小程序&#xff09;_uni-app_帶刺的小葡萄-华为开发者空间 中学到了如何在uniapp的微信小程序里接入three.js的3d模型 由于小程序自身很…

C#项目04——递归求和

实现逻辑 利用递归&#xff0c;求取1~N以内的和 知识点 正常情况下&#xff0c;C#每条线程都会分配1MB的地址空间&#xff0c;因此执行递归的层次不能太深&#xff0c;否则就会出现溢出的风险&#xff0c; 业务设计 程序代码 private void button1_Click(object sender, E…

SQLMesh 系列教程6- 详解 Python 模型

本文将介绍 SQLMesh 的 Python 模型&#xff0c;探讨其定义、优势及在企业业务场景中的应用。SQLMesh 不仅支持 SQL 模型&#xff0c;还允许通过 Python 编写数据模型&#xff0c;提供更高的灵活性和可编程性。我们将通过一个电商平台的实例&#xff0c;展示如何使用 Python 模…

docker修改镜像默认存储路径(基于 WSL2 的迁移方法)

文章目录 打开powershell窗口1、停止 WSL2、导出数据3、取消注册4、导入数据到新位置5、确认转移情况6、重新启动 Docker Desktop7、查看 打开powershell窗口 任意地方shift右键 1、停止 WSL wsl --shutdown2、导出数据 wsl --export docker-desktop-data E:\docker\Docke…

Java开发实习面试笔试题(含答案)

在广州一家中大公司面试&#xff08;BOSS标注是1000-9999人&#xff0c;薪资2-3k&#xff09;&#xff0c;招聘上写着Java开发&#xff0c;基本没有标注前端要求&#xff0c;但是到场知道是前后端分离人不分离。开始先让你做笔试&#xff08;12道问答4道SQL题&#xff09;&…

火语言RPA--Excel读取内容

【组件功能】&#xff1a;读取Excel内指定位置的内容或读取整篇Sheet页内容 配置预览 配置说明 读取位置 单元格&#xff1a;读取指定单元格中的内容。 行&#xff1a;读取指定行内容。 列&#xff1a;读取指定列内容。 区域&#xff1a;读取指定区域内容。 整篇sheet页&…

基于Flask的第七次人口普查数据分析系统的设计与实现

【Flask】基于Flask的第七次人口普查数据分析系统的设计与实现&#xff08;完整系统源码开发笔记详细部署教程&#xff09;✅ 目录 一、项目简介二、项目界面展示三、项目视频展示 一、项目简介 基于Flask的人口普查可视化分析系统 二、项目界面展示 登录/注册 首页/详情 …

国产编辑器EverEdit -告别东找西找!一键打开当前文件所在目录!

1 文件操作 2 应用场景 在文件编辑过程中&#xff0c;有时需要对文件进行一些操作&#xff0c;比如&#xff1a;在命令窗口输入文件路径、文件名&#xff0c;进入到文件目录&#xff0c;对文件进行压缩等&#xff0c;如果没有直达命令&#xff0c;用户需要通过文件管理器找到目…

html网络安全工具源码 网络安全前端

&#x1f345; 点击文末小卡片 &#xff0c;免费获取网络安全全套资料&#xff0c;资料在手&#xff0c;涨薪更快 前端常见的网络安全包括&#xff1a;xss&#xff08;跨站脚本攻击&#xff09;、csrf&#xff08;跨站请求伪造&#xff09;、sql注入攻击等。 1&#xff09;跨站…

【分布式理论14】分布式数据库存储:分表分库、主从复制与数据扩容策略

文章目录 一、分表分库1. 数据分表的必要性与方式2. 数据分库原则与优势 二、主从复制1. 读写分离架构设计2. 数据复制方式3. MySQL实现主从复制4. MySQL主从复制实践与高可用方案 三、数据扩容 随着业务的不断发展和数据量的增长&#xff0c;传统的单机关系型数据库已经逐渐不…

汇能感知的光谱相机/模块产品有哪些?

CM020A 分辨率&#xff1a;1600H1200V 光谱范围&#xff1a;350~950nm 光谱分辨率&#xff1a;1nm 接口&#xff1a;USB2.0 帧率&#xff1a;16001200 (6帧) 输出格式&#xff1a;Raw 8bit FOV&#xff1a;D73.5H58.8V44.1 相机尺寸&#xff1a;505055mm VM02S10 分辨率…

sentinel集成nacos做持久化配置

sentinel提供了非常强大的控制台来提供流控等功能&#xff0c;但是控制台只是临时的配置&#xff0c;想要将流控配置永久的保存&#xff0c;或者在项目启动的时候就加载&#xff0c;不需要手动设置&#xff0c;就需要使用到nacos与sentinel做集成配置。这里都是不变代码&#x…

SpringBoot速成概括

视频&#xff1a;黑马程序员SpringBoot3Vue3全套视频教程&#xff0c;springbootvue企业级全栈开发从基础、实战到面试一套通关_哔哩哔哩_bilibili 图示&#xff1a;

【含文档+PPT+源码】基于微信小程序的猎兔汽车保养维修美容服务平台的设计与实现

项目介绍 本课程演示的是一款基于微信小程序的猎兔汽车保养维修美容服务平台的设计与实现&#xff0c;主要针对计算机相关专业的正在做毕设的学生与需要项目实战练习的 Java 学习者。 1.包含&#xff1a;项目源码、项目文档、数据库脚本、软件工具等所有资料 2.带你从零开始部…

Python在网络安全中的应用 python与网络安全

前言 网络安全是保护网络、系统和程序免受数字攻击的做法。据估计&#xff0c; 2019 年该行业价值 1120 亿美元&#xff0c;到2021 年估计有 350 万个职位空缺。 许多编程语言用于执行与网络安全相关的日常任务&#xff0c;但其中一种已成为行业标准&#xff1a;Python&#…

Mac 清理缓存,提高内存空间

步骤 1.打开【访达】 2.菜单栏第五个功能【前往】&#xff0c;点击【个人】 3.【command shift J】显示所有文件&#xff0c;打开【资源库】 4.删除【Containers】和【Caches】文件 Containers 文件夹&#xff1a;用于存储每个应用程序的沙盒数据&#xff0c;确保应用程序…

基于SpringBoot实现的宠物领养系统平台功能一

一、前言介绍&#xff1a; 1.1 项目摘要 宠物领养需求增加&#xff1a;随着人们生活水平的提高和对宠物养护意识的增强&#xff0c;越来越多的人选择领养宠物作为家庭的一员。这导致了宠物领养需求的显著增加。 传统领养方式存在问题&#xff1a;传统的宠物领养方式&#xf…

智慧能源管理新标杆:安科瑞EMS3.0解锁工业园区经济效益与环保双赢

智慧能源平台是一种集成分布式能源、储能系统、负荷管理和智能控制技术的综合能源管理系统。它能够实现能源的高效利用、优化调度和智能化管理&#xff0c;为用户提供稳定、经济、绿色的能源解决方案。工业园区作为能源消耗和管理的核心场景之一&#xff0c;对微电网能源管理平…

Spotify AI 技术(1)使用 TensorFlow 和 TF-Agents

介绍 我们的许多音乐推荐问题都涉及为用户提供有序的项目集&#xff0c;以满足用户在那个时间点的收听偏好和意图。我们根据以前与应用程序的交互来提供当前的推荐&#xff0c;抽象地说&#xff0c;由于我们不断向用户推荐内容&#xff0c;因此我们面临着一个连续的决策过程。 …