建立向量嵌入数据库

from langchain_community.document_loaders import TextLoader
from langchain_text_splitters import CharacterTextSplitter
from langchain.docstore.document import Document
from langchain_chroma.vectorstores import Chromaimport vertexai
from vertexai.language_models import TextEmbeddingModel

导入了一些用于构建 文本嵌入式向量检索系统(Embedding-based Retrieval System) 的模块,结合了 LangChain、Chroma 向量数据库、以及 Google Vertex AI 的文本嵌入模型。

从 LangChain 社区库 导入 TextLoader,用于从 .txt 文件中加载纯文本数据。
功能:将本地文本文件加载为 LangChain 的 Document 对象

导入 CharacterTextSplitter,是 LangChain 提供的一种 文本分割器。
功能:将长文本分割成较小的片段(例如按字符数),用于后续嵌入处理或问答检索。

功能:用于表示一个包含文本内容和可选元数据的文档对象,便于在整个链条中传递和处理。

导入 Chroma 类,它是 LangChain 支持的 向量数据库(Vector Store) 之一,基于 ChromaDB。
功能:将文本嵌入后保存到数据库中,可以用来做相似度搜索、向量检索等任务。

从 Vertex AI 的语言模型模块中导入 TextEmbeddingModel。
功能:调用 Google 预训练的嵌入模型,将文本转换为 嵌入向量(embedding vector),供后续存入向量数据库或进行相似度计算。

# 设置 GCP 项目参数
project_id = ""
location = "us-central1"  # 确保该地区支持 Gemini
import pandas as pdbooks = pd.read_csv("books_cleaned_new.csv")
books["tagged_description"]
0       9780002005883 A NOVEL THAT READERS and critics...
1       9780002261982 A new 'Christie for Christmas' -...
2       9780006178736 A memorable, mesmerizing heroine...
3       9780006280897 Lewis' work on the nature of lov...
4       9780006280934 "In The Problem of Pain, C.S. Le......                        
5192    9788172235222 On A Train Journey Home To North...
5193    9788173031014 This book tells the tale of a ma...
5194    9788179921623 Wisdom to Create a Life of Passi...
5195    9788185300535 This collection of the timeless ...
5196    9789027712059 Since the three volume edition o...
Name: tagged_description, Length: 5197, dtype: object
books["tagged_description"].to_csv("new_tagged_description.txt",sep = "\n",index = False,header = False)

将 books[“tagged_description”] 这一列保存为一个新的文本文件 new_tagged_description.txt,每行一个值,不含索引和列名。

sep=“\n”:每个元素用“换行”分隔,也就是每个值占一行。

index=False:不输出 DataFrame 的行号索引。

header=False:不输出列名(只保存纯文本内容)。

raw_documents = TextLoader("new_tagged_description.txt", encoding="utf-8").load()
text_splitter = CharacterTextSplitter(chunk_size=0, chunk_overlap=0, separator="\n")
documents = text_splitter.split_documents(raw_documents)

encoding=“utf-8”:确保以 UTF-8 编码读取文件。

创建一个文本切分器,按换行符 \n 作为分割依据,把长文本拆分成多个块(chunk)。

chunk_size=0:特殊用法,配合 separator=“\n”,表示按行完整切分,而不是定长字符数。

chunk_overlap=0:切分块之间没有重叠。

separator=“\n”:以换行符为切分依据。

将上一步加载的长文档切割成一个个较小的 Document 实例,每个实例代表一行文本。

Created a chunk of size 1168, which is longer than the specified 0
Created a chunk of size 1214, which is longer than the specified 0
Created a chunk of size 373, which is longer than the specified 0
Created a chunk of size 309, which is longer than the specified 0
Created a chunk of size 483, which is longer than the specified 0
Created a chunk of size 482, which is longer than the specified 0
Created a chunk of size 960, which is longer than the specified 0
Created a chunk of size 188, which is longer than the specified 0
Created a chunk of size 843, which is longer than the specified 0
Created a chunk of size 296, which is longer than the specified 0
Created a chunk of size 197, which is longer than the specified 0
Created a chunk of size 881, which is longer than the specified 0
Created a chunk of size 1088, which is longer than the specified 0
Created a chunk of size 1189, which is longer than the specified 0
Created a chunk of size 304, which is longer than the specified 0
Created a chunk of size 270, which is longer than the specified 0
Created a chunk of size 211, which is longer than the specified 0
Created a chunk of size 214, which is longer than the specified 0
Created a chunk of size 513, which is longer than the specified 0
Created a chunk of size 752, which is longer than the specified 0
Created a chunk of size 388, which is longer than the specified 0
Created a chunk of size 263, which is longer than the specified 0
Created a chunk of size 253, which is longer than the specified 0
Created a chunk of size 306, which is longer than the specified 0
Created a chunk of size 728, which is longer than the specified 0
...
Created a chunk of size 1655, which is longer than the specified 0
Created a chunk of size 387, which is longer than the specified 0
Created a chunk of size 763, which is longer than the specified 0
Created a chunk of size 1032, which is longer than the specified 0
documents[0]
Document(metadata={'source': 'new_tagged_description.txt'}, page_content='9780002005883 A NOVEL THAT READERS and critics have been eagerly anticipating for over a decade, Gilead is an astonishingly imagined story of remarkable lives. John Ames is a preacher, the son of a preacher and the grandson (both maternal and paternal) of preachers. It’s 1956 in Gilead, Iowa, towards the end of the Reverend Ames’s life, and he is absorbed in recording his family’s story, a legacy for the young son he will never see grow up. Haunted by his grandfather’s presence, John tells of the rift between his grandfather and his father: the elder, an angry visionary who fought for the abolitionist cause, and his son, an ardent pacifist. He is troubled, too, by his prodigal namesake, Jack (John Ames) Boughton, his best friend’s lost son who returns to Gilead searching for forgiveness and redemption. Told in John Ames’s joyous, rambling voice that finds beauty, humour and truth in the smallest of life’s details, Gilead is a song of celebration and acceptance of the best and the worst the world has to offer. At its heart is a tale of the sacred bonds between fathers and sons, pitch-perfect in style and story, set to dazzle critics and readers alike.')
vertexai.init(project=project_id, location=location)
embedding_model = TextEmbeddingModel.from_pretrained("text-embedding-005")

初始化 Vertex AI 客户端,以便后续调用 Google Cloud 上的 AI 模型。

Vertex AI 是 Google Cloud 提供的机器学习平台,这一行的作用是连接到你的云项目和区域,使你能使用 Vertex AI 上部署的模型(如 Embedding、LLM、AutoML 等)。

从 Vertex AI 加载一个预训练的文本嵌入(Text Embedding)模型。

# 嵌入函数(批处理)
def get_gemini_embeddings(texts: list[str]) -> list[list[float]]:embeddings = embedding_model.get_embeddings(texts)return [e.values for e in embeddings]

定义了一个 批量生成文本嵌入向量的函数,用于将多个文本转换为数值表示(即向量)

返回值 是一个二维列表:每一条文本对应一个向量,每个向量是浮点数列表(如 768 维的向量)。

这是一个 列表推导式,将每个 embedding 对象的 .values 取出,构成最终的二维列表。

# 分批生成嵌入
BATCH_SIZE = 50
all_texts = [doc.page_content for doc in documents]
all_metadatas = [doc.metadata for doc in documents]batched_docs = []
batched_vectors = []for i in range(0, len(all_texts), BATCH_SIZE):batch_texts = all_texts[i:i+BATCH_SIZE]batch_metadatas = all_metadatas[i:i+BATCH_SIZE]batch_vectors = get_gemini_embeddings(batch_texts)for text, metadata, vector in zip(batch_texts, batch_metadatas, batch_vectors):batched_docs.append(Document(page_content=text, metadata=metadata))batched_vectors.append(vector)

在使用嵌入模型(如 Vertex AI 的 text-embedding-005)时,出于性能和 API 限制,不能一次性处理太多文本。因此通常使用「批处理」的方式进行嵌入生成。

从 documents 中提取:page_content:文本内容;metadata:与每条文本关联的元数据(如文件名、页码等)

batched_docs:保存文本和元数据的 Document 对象
batched_vectors:保存每个文本对应的向量(float 列表)

使用步长为 BATCH_SIZE 的循环,每次处理一批文本
调用之前定义的 get_gemini_embeddings 函数生成嵌入向量

将每个文本、元数据、向量打包成一个 Document 对象 + 向量
存入两个列表中,供后续使用(如构建向量索引)

举例说明
假设你有 120 段文本,每段都要生成向量,代码会像这样运行:
第一批:第 0~49 条 → 嵌入 → 加入结果
第二批:第 50~99 条 → 嵌入 → 加入结果
第三批:第 100~119 条 → 嵌入 → 加入结果

使用 Chroma 创建一个持久化向量数据库,将文本及其嵌入向量保存进去,并用 LangChain 封装以供后续问答或检索使用。

from chromadb import PersistentClient
from langchain_chroma.vectorstores import Chroma# 先建立 Chroma 客户端
client = PersistentClient(path="./new_chroma_books")# 创建向量库集合
collection = client.get_or_create_collection(name="books")# 插入数据(确保你的向量数目和文本数目一致)
collection.add(documents=[doc.page_content for doc in batched_docs],embeddings=batched_vectors,metadatas=[doc.metadata for doc in batched_docs],ids=[f"doc_{i}" for i in range(len(batched_docs))]
)# 用 langchain 封装向量库
db_books = Chroma(client=client,collection_name="books",embedding_function=lambda x: batched_vectors  # 注意:这里最好改为动态函数
)

chromadb: 向量数据库 Chroma 的 Python 客户端

langchain_chroma.vectorstores.Chroma: LangChain 封装的 Chroma 适配器,便于在 LangChain 中集成向量库

PersistentClient:用于创建一个持久化本地向量数据库客户端

Chroma:LangChain 的向量数据库接口封装类

在 ./new_chroma_books 路径下创建或打开一个本地向量数据库

所有数据会保存在这个文件夹中,下次运行也能加载

创建一个名为 books 的集合(collection),类似于数据库中的表。

插入以下内容到 books 集合中:
documents: 原始文本内容(字符串列表)
embeddings: 每条文本的向量(二维 float 列表)
metadatas: 每条文本的元数据(字典列表)
ids: 每条记录的唯一 ID,如 doc_0, doc_1, …

封装为 LangChain 可用的向量数据库对象 db_books
传入当前客户端和集合名
embedding_function:嵌入函数,这里用了一个固定返回 batched_vectors 的 lambda

根据查询语句生成嵌入向量,并在向量数据库中查找最相似的 10 条文档。

# 示例查询
query = "A book to teach children about nature"
query_embedding = get_gemini_embeddings([query])[0]
docs = db_books.similarity_search_by_vector(query_embedding, k=10)

使用之前定义的 get_gemini_embeddings 函数,把查询转化为向量(嵌入表示)。
get_gemini_embeddings 返回的是列表(批处理),所以这里取第一个 [0] 得到该查询的向量。

使用 db_books(封装好的向量数据库)对查询向量进行相似度搜索。
similarity_search_by_vector(query_embedding, k=10) 表示返回与该向量最接近的 10 条文档。

变量 docs 中保存的是 与查询语句最相关的 10 本书的描述文本与元数据

[Document(id='doc_3751', metadata={'source': 'new_tagged_description.txt'}, page_content='9780786808717 A very special puddle sets Violet the mouse off on her latest nature discovery. It is through this puddle that Violet observes the effect rain has on the world around her. A Mylar puddle on the last page offers children a chance to see their reflection in a puddle, just like Violet!'),Document(id='doc_3747', metadata={'source': 'new_tagged_description.txt'}, page_content='9780786808069 Children will discover the exciting world of their own backyard in this introduction to familiar animals from cats and dogs to bugs and frogs. The combination of photographs, illustrations, and fun facts make this an accessible and delightful learning experience.'),Document(id='doc_442', metadata={'source': 'new_tagged_description.txt'}, page_content='"9780067575208 First published more than three decades ago, this reissue of Rachel Carson\'s award-winning classic brings her unique vision to a new generation of readers. Stunning new photographs by Nick Kelsh beautifully complement Carson\'s intimate account of adventures with her young nephew, Roger, as they enjoy walks along the rocky coast of Maine and through dense forests and open fields, observing wildlife, strange plants, moonlight and storm clouds, and listening to the ""living music"" of insects in the underbrush. ""If a child is to keep alive his inborn sense of wonder."" Writes Carson, ""he needs the companionship of at least one adult who can share it, rediscovering with him the joy, excitement and mystery of the world we live in."" The Sense of Wonder is a refreshing antidote to indifference and a guide to capturing the simple power of discovery that Carson views as essential to life. In her insightful new introduction, Linda Lear remembers Rachel Carson\'s groundbreaking achievements in the context of the legendary environmentalist\'s personal commitment to introducing young and old to the miracles of nature. Kelsh\'s lush photographs inspire sensual, tactile reactions: masses of leaves floating in a puddle are just waiting to be scooped up and examined more closely. An image of a narrow path through the trees evokes the earthy scent of the woods after a summer rain. Close-ups of mosses and miniature lichen fantasy-lands will spark innocent\'as well as more jaded\'imaginations. Like a curious child studying things underfoot and within reach, Kelsh\'s camera is drawn to patterns in nature that too often elude hurried adults\'a stand of beech trees in the springtime, patches of melting snow and the ripples from a pebble tossed into a slow-moving stream. The Sense of Wonder is a timeless volume that will be passed on from children to grandchildren, as treasured as the memory of an early-morning walk when the song of a whippoorwill was heard as if for the first time."'),Document(id='doc_3442', metadata={'source': 'new_tagged_description.txt'}, page_content='9780744578263 Washed up on the beach during a storm, the sea-thing child clings fearfully to the shore until he discovers his true destiny. Suggested level: primary.'),Document(id='doc_3797', metadata={'source': 'new_tagged_description.txt'}, page_content='9780789458209 Photographs and text explore the anatomy and life cycle of trees, examining the different kinds of bark, seeds, and leaves, the commercial processing of trees to make lumber, the creatures that live in trees, and other aspects.'),Document(id='doc_1639', metadata={'source': 'new_tagged_description.txt'}, page_content='9780374422080 This Newbery Honor Book tells the story of 11 -year-old Primrose, who lives in a small fishing village in British Columbia. She recounts her experiences and all she learns about human nature and the unpredictability of life after her parents are lost at sea.'),Document(id='doc_3750', metadata={'source': 'new_tagged_description.txt'}, page_content="9780786808397 Introduce your baby to birds, cats, dogs, and babies through fine art, illustration, and photographs. These books are a rare opportunity to exopse little ones to a range of images on a single subject, from simple child's drawings and abstract art to playful photos. A brief text accompanies each image, introducing baby to some basic -- and sometimes playful -- information about the subjects."),Document(id='doc_3748', metadata={'source': 'new_tagged_description.txt'}, page_content="9780786808373 Introducing your baby to birds, cats, dogs, and babies through fine art, illsutration and photographs. These books are a rare opportunity to expose little ones to a range of images on a single subject, from simple child's drawings and abstract art to playful photos. A brief text accompanies each image, introducing baby to some basic -- and sometimes playful -- information on the subjects."),Document(id='doc_3522', metadata={'source': 'new_tagged_description.txt'}, page_content='9780753459645 What is a leap year? Why are bees busy in summer? Who eats the moon? Why does it get dark at night? In I Wonder Why the Sun Rises by Brenda Walpole children will find out the answers to these and many more questions about time and seasons.'),Document(id='doc_3749', metadata={'source': 'new_tagged_description.txt'}, page_content="9780786808380 Introduce your babies to birds, cats, dogs, and babies through fine art, illustration, and photographs. These books are a rare opportunity to expose little ones to a range of images on a single subject, from simple child's drawings and abstract art to playful photos. A brief text accompanies each image, introducing the baby to some basic -- and sometimes playful -- information about the subjects.")]
books[books["isbn13"] == int(docs[0].page_content.split()[0].strip())]

取出第一个相似文档的文本内容,将文本按照空格拆分,并取第一个词,即为该文档关联的 ISBN-13 编号,去除该字符串首尾可能的空白字符(虽然对 ISBN 一般没必要,但保险起见)。
将字符串转为整数(因为 books[“isbn13”] 是整数类型)。
根据 docs[0] 文本中的 ISBN 编号,找到其在原始 books 表中的完整信息(如标题、作者、评分、分类等)。

根据自然语言查询语句,从语义上推荐相关图书,并返回包含这些图书详细信息的 DataFrame。

def retrieve_semantic_recommendations(query: str,top_k: int = 10,
) -> pd.DataFrame:query_embedding = get_gemini_embeddings([query])[0]recs = db_books.similarity_search_by_vector(query_embedding, k = 50)books_list = []for i in range(0, len(recs)):books_list += [int(recs[i].page_content.strip('"').split()[0])]return books[books["isbn13"].isin(books_list)]

query: 用户输入的自然语言查询,例如 “Books about space exploration for kids”。
top_k: 期望返回的图书数

用 Gemini 模型生成查询的向量嵌入(embedding)表示,用于语义相似度比较。
在之前构建的 Chroma 向量数据库中查找与该嵌入最相似的 50 本书。

recs 是一个由 Document 组成的列表,每个 Document 的 page_content 包含如 “9780316015844 This book is about…” 的字符串。

逐个提取每本推荐书的 ISBN 编号(在 page_content 中作为第一个词),并将其转换为 int 后存入 books_list。

从 books 数据框中筛选出 ISBN 在 books_list 中的记录,返回包含书名、评分、页数、描述等元数据的表格。

retrieve_semantic_recommendations("A book to teach children about nature")

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

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

相关文章

【Go-4】函数

函数 函数是编程中的基本构建块,用于封装可重用的代码逻辑。Go语言中的函数功能强大,支持多种特性,如多返回值、可变参数、匿名函数、闭包以及将函数作为值和类型传递。理解和掌握函数的使用对于编写高效、可维护的Go程序至关重要。本章将详…

【已解决】HBuilder X编辑器在外接显示器或者4K显示器怎么界面变的好小问题

触发方式:主要涉及DPI缩放问题,可能在电脑息屏有概率触发 修复方式: 1.先关掉软件直接更改屏幕缩放,然后打开软件,再关掉软件恢复原来的缩放,再打开软件就好了 2.(不推荐)右键HBuilder在属性里…

spark调度系统核心组件SparkContext、DAGSchedul、TaskScheduler、Taskset介绍

目录 1. SparkContext2.DAGScheduler3. TaskScheduler4. 协作关系5 TaskSet的定义6. 组件关系说明Spark调度系统的核心组件主要有SparkContext、DAGScheduler和TaskScheduler SparkContext介绍 1. SparkContext 1、资源申请: SparkContext是Spark应用程序与集群管理器(如St…

VSCode+EIDE通过KeilC51编译,使VSCode+EIDE“支持”C和ASM混编

在使用Keil C51时,要让Keil C51支持混编则需要在混编的.c文件上右键选择Options for File *(ALTF7),打开选项界面后,在 Properties 页 勾上 Generate Assembler SRC File 和 Assemble SRC File ,如下图所示: 这样设置后…

SQLynx:一款跨平台的企业级数据库管理工具

SQLynx 是一款支持跨平台(Windows、Linux、macOS、Web)的企业级数据库管理和 SQL 工具,可以提供高效、安全且适配国产化技术栈的数据库管理解决方案。 数据源 SQLynx 支持连接各种关系型数据库、非关系型数据库以及大数据平台,包…

实战项目8(实训)

目录 项目01 【sw1】配置 【sw2】配置 任务结果截图 项目02 【sw1】配置 【sw2】配置 任务结果截图 项目03 【sw1】配置 任务结果截图 项目04 【sw1】配置 【r1】配置 任务结果截图 项目05 【r1】配置 【r2】配置 【r3】配置 任务结果截图 项目06 【r1】…

TCP为什么是三次握手,而不是二次?

为什么需要三次握手? 想象一下,你要给远方的朋友寄一份重要文件。你会怎么做? 普通人的做法: 直接扔进邮箱,祈祷别丢了 聪明人的做法: 先打电话确认地址,再发快递,最后确认收到 T…

dubbo使用nacos作为注册中心配置

<dubbo:registry protocol"nacos" address"${dubbo.registry.address.nacos}" /> <dubbo:metadata-report address"${dubbo.metadata-report.address}"/> 如果有多个地址&#xff0c;这块如何配置呢&#xff1f; nacos://ip:端口?…

教师角色的转变:从知识传授者到学习引导者

教师角色的转变&#xff1a;从知识传授者到学习引导者 随着人工智能&#xff08;AI&#xff09;和信息技术的迅速发展&#xff0c;教育正在经历深刻的变革。其中&#xff0c;教师角色的转变尤为关键。传统上&#xff0c;教师主要承担“知识传授者”的职责&#xff0c;即向学生…

PostgreSQL 用户权限与安全管理

1 系统默认角色 postgres# select rolname from pg_roles; rolname ----------------------------- postgres pg_database_owner pg_read_all_data pg_write_all_data pg_monitor pg_read_all_settings pg_read_all_stats pg_stat_scan_tables …

C++构造函数和析构函数

C++构造函数和析构函数 C++的构造函数和析构函数是类的特殊成员函数,用于对象的创建和销毁,分别在对象的生命周期开始和结束时自动调用。它们的使用对资源管理和对象的初始化/清理至关重要。 1. 构造函数 定义 构造函数在对象创建时自动调用,用于初始化对象的数据成员。构造…

根据Cortex-M3(STM32F1)权威指南讲解MCU内存架构与如何查看编译器生成的地址具体位置

首先我们先查看官方对于Cortex-M3预定义的存储器映射 1.存储器映射 1.1 Cortex-M3架构的存储器结构 内部私有外设总线&#xff1a;即AHB总线&#xff0c;包括NVIC中断&#xff0c;ITM硬件调试&#xff0c;FPB, DWT。 外部私有外设总线&#xff1a;即APB总线&#xff0c;用于…

软件设计师“测试用例”考点分析——求三连

一、测试用例设计核心要点解析 1. 白盒测试覆盖标准 &#xff08;1&#xff09;路径覆盖&#xff1a;需覆盖程序中所有可能的路径。如2018年真题路径覆盖需要3组测试用例&#xff08;①②、①③、①③④&#xff09;&#xff0c;2020年流程图则需4个用例覆盖ace/abd/abe/acd四…

Linux 用户无法远程连接服务器

前言 昨天深夜一点多接到客户电话&#xff0c;客户说OS用户下午下班前还能正常登录。因为晚上一点半需要关闭所有服务进行迁移&#xff0c;但是用户无法登录了&#xff0c;导致后续流程无法执行。我让他先通过root用户紧急修改了密码&#xff0c;先保证业务正常流转。 问题 …

多模态大语言模型arxiv论文略读(八十八)

MammothModa: Multi-Modal Large Language Model ➡️ 论文标题&#xff1a;MammothModa: Multi-Modal Large Language Model ➡️ 论文作者&#xff1a;Qi She, Junwen Pan, Xin Wan, Rui Zhang, Dawei Lu, Kai Huang ➡️ 研究机构: ByteDance, Beijing, China ➡️ 问题背景…

svn迁移到git保留记录和Python字符串格式化 f-string的进化历程

svn迁移到git保留记录 and Python字符串格式化(二&#xff09;&#xff1a; f-string的进化历程 在将项目从SVN迁移到Git时&#xff0c;保留完整的版本历史记录非常重要。下面是详细的步骤和工具&#xff0c;可以帮助你完成这一过程&#xff1a; 安装Git和SVN工具 首先&#…

springboot配置mysql druid连接池,以及连接池参数解释

文章目录 前置配置方式参数解释 前置 springboot 项目javamysqldruid 连接池 配置方式 在 springboot 的 application.yml 中配置基本方式 # Druid 配置&#xff08;Spring Boot YAML 格式&#xff09; spring:datasource:url: jdbc:mysql://localhost:3306/testdb?useSSL…

vue实现高亮文字效果——advanced-mark.js

组件介绍-advanced-mark.js&#xff1a; advanced-mark.js 是一个用于 Vue 的高亮文字组件&#xff0c;它可以帮助你在文本中高亮显示指定的关键词或短语。 组件地址&#xff1a;https://angezid.github.io/advanced-mark.js/doc-v2/getting-started.html 主要功能&#xff1…

DC30V/2.5A同步降压芯片SL1581 输入24V降压5V 12V2A电流

在工业自动化、汽车电子等领域&#xff0c;24V 电源系统向 5V/12V 双轨供电的需求日益增长。针对这一痛点&#xff0c;森利威尔电子重磅推出 DC30V/2.5A 同步降压芯片 SL1581&#xff0c;凭借卓越的性能和创新设计&#xff0c;为工程师提供高可靠性、高性价比的电源解决方案。 …

React 第四十四节Router中 usefetcher的使用详解及注意事项

前言 useFetcher 是 React Router 中一个强大的钩子&#xff0c;用于在不触发页面导航的情况下执行数据加载&#xff08;GET&#xff09;或提交&#xff08;POST&#xff09;。 一、useFetcher 应用场景&#xff1a; 1、后台数据预加载&#xff08;如鼠标悬停时加载数据&…