langchain教程-5.DocumentLoader/多种文档加载器

news2025/2/7 6:24:39

前言

该系列教程的代码: https://github.com/shar-pen/Langchain-MiniTutorial

我主要参考 langchain 官方教程, 有选择性的记录了一下学习内容

这是教程清单

  • 1.初试langchain
  • 2.prompt
  • 3.OutputParser/输出解析
  • 4.model/vllm模型部署和langchain调用
  • 5.DocumentLoader/多种文档加载器
  • 6.TextSplitter/文档切分
  • 7.Embedding/文本向量化
  • 8.VectorStore/向量数据库存储和检索
  • 9.Retriever/检索器
  • 10.Reranker/文档重排序
  • 11.RAG管道/多轮对话RAG
  • 12.Agent/工具定义/Agent调用工具/Agentic RAG

Document

用于存储一段文本及其相关元数据的类。

  • page_content (必需):以字符串形式存储一段文本。
  • metadata (可选):以字典形式存储与 page_content 相关的元数据。
from langchain_core.documents import Document

document = Document(page_content="Hello, welcome to LangChain Open Tutorial!")

document
Document(metadata={}, page_content='Hello, welcome to LangChain Open Tutorial!')

文档加载器(Document Loader)

文档加载器是一个用于从各种来源加载 Document 的类。

以下是一些常见的文档加载器示例:

  • PyPDFLoader :加载 PDF 文件
  • CSVLoader :加载 CSV 文件
  • UnstructuredHTMLLoader :加载 HTML 文件
  • JSONLoader :加载 JSON 文件
  • TextLoader :加载纯文本文件
  • DirectoryLoader :从目录中批量加载文档
from langchain_community.document_loaders import PyPDFLoader

# Set up the loader
FILE_PATH = "./data/01-document-loader-sample.pdf"
loader = PyPDFLoader(FILE_PATH)

load()

  • 加载文档,并以 list[Document] 的形式返回。
docs = loader.load()
print(len(docs))
print('-'*3)
docs[0:2]
48
---





[Document(metadata={'source': './data/01-document-loader-sample.pdf', 'page': 0}, page_content=' \n \n \nOctober 2016 \n \n \n \n \n \n \n \n \n \nTHE NATIONAL  \nARTIFICIAL INTELLIGENCE \nRESEARCH AND DEVELOPMENT \nSTRATEGIC PLAN  \nNational Science and Technology Council \n \nNetworking and Information Technology \nResearch and Development Subcommittee \n '),
 Document(metadata={'source': './data/01-document-loader-sample.pdf', 'page': 1}, page_content=' ii \n \n ')]

aload()

  • 异步加载文档,并以 list[Document] 的形式返回。
# Load Documents asynchronously
docs = await loader.aload()

lazy_load()

  • 顺序加载文档,并以 Iterator[Document] 的形式返回。
docs = loader.lazy_load()

for doc in docs:
    print(doc.metadata)
    break  # Used to limit the output length

alazy_load()

  • 异步顺序加载文档,并以 AsyncIterator[Document] 的形式返回。

可以观察到,这种方法作为一个 async_generator 工作。它是一种特殊类型的异步迭代器,能够按需生成值,而不需要一次性将所有值存储在内存中。

loader.alazy_load()
docs = loader.alazy_load()
async for doc in docs:
    print(doc.metadata)
    break  # Used to limit the output length

load_and_split()

  • 加载文档,并使用 TextSplitter 自动拆分为多个文本块,最终以 list[Document] 的形式返回。
from langchain_text_splitters import RecursiveCharacterTextSplitter

# Set up the TextSplitter
text_splitter = RecursiveCharacterTextSplitter(chunk_size=128, chunk_overlap=0)

# Split Documents into chunks
docs = loader.load_and_split(text_splitter=text_splitter)

print(len(docs))
docs[0:3]
1430





[Document(metadata={'source': './data/01-document-loader-sample.pdf', 'page': 0}, page_content='October 2016 \n \n \n \n \n \n \n \n \n \nTHE NATIONAL  \nARTIFICIAL INTELLIGENCE \nRESEARCH AND DEVELOPMENT \nSTRATEGIC PLAN'),
 Document(metadata={'source': './data/01-document-loader-sample.pdf', 'page': 0}, page_content='National Science and Technology Council \n \nNetworking and Information Technology \nResearch and Development Subcommittee'),
 Document(metadata={'source': './data/01-document-loader-sample.pdf', 'page': 1}, page_content='ii')]

PDF Loader

PyPDF 是最广泛使用的 Python 库之一,用于 PDF 处理。

在这里,我们使用 pypdf 将 PDF 加载为文档数组,每个文档包含一个 page 页码,并包含页面内容和元数据。

LangChain 的 PyPDFLoader 集成了 PyPDF,将 PDF 文档解析为 LangChain 的 Document 对象。

from langchain_community.document_loaders import PyPDFLoader

# Initialize the PDF loader
FILE_PATH = "./data/01-document-loader-sample.pdf"
loader = PyPDFLoader(FILE_PATH)

# Load data into Document objects
docs = loader.load()

# Print the contents of the document
print(docs[10].page_content[:300])
NATIONAL ARTIFICIAL INTELLIGENCE RESEARCH AND DEVELOPMENT STRATEGIC PLAN 
 
 3 
Executive Summary 
Artificial intelligence (AI) is a transformative technology that holds promise for tremendous societal and 
economic benefit. AI has the potential to revolutionize how we live, work, learn, discover, a

PyPDF(OCR)

有些 PDF 包含扫描文档或图片中的文本图像。你也可以使用 rapidocr-onnxruntime 包从图像中提取文本。

loader = PyPDFLoader(FILE_PATH, extract_images=True)
docs = loader.load()

PyPDF Directory

从目录中导入所有 PDF 文档。

from langchain_community.document_loaders import PyPDFDirectoryLoader

# directory path
loader = PyPDFDirectoryLoader("./data/")

# load documents
docs = loader.load()

# print the number of documents
print(len(docs))

96

PyMuPDF

PyMuPDF 经过速度优化,并提供关于 PDF 及其页面的详细元数据。它每页返回一个文档

LangChain 的 PyMuPDFLoader 集成了 PyMuPDF,可将 PDF 文档解析为 LangChain 的 Document 对象。

from langchain_community.document_loaders import PyMuPDFLoader

# create an instance of the PyMuPDF loader
FILE_PATH = "./data/01-document-loader-sample.pdf"
loader = PyMuPDFLoader(FILE_PATH)

# load the document
docs = loader.load()

# print the contents of the document
print(len(docs))
48


/data02/hyzhang10/miniconda3/envs/xp-nlp/lib/python3.12/site-packages/langchain_community/document_loaders/parsers/pdf.py:322: UserWarning: Warning: Empty content on page 4 of document ./data/01-document-loader-sample.pdf
  warnings.warn(

WebBaseLoader

WebBaseLoader 是 LangChain 中一个专门用于处理基于网页内容的文档加载器。

它利用 BeautifulSoup4 库有效地解析网页,并通过 SoupStrainer 和其他 bs4 参数提供可自定义的解析选项。

import bs4
from langchain_community.document_loaders import WebBaseLoader

# Load news article content using WebBaseLoader
loader = WebBaseLoader(
   web_paths=(
	"https://blog.csdn.net/wait_for_taht_day5/article/details/50570827",
	"https://blog.csdn.net/teethfairy/article/details/7287307"
	),
   encoding='utf-8'
)

# Load and process the documents
docs = loader.load()
print(f"Number of documents: {len(docs)}")

import re
print(re.sub(r'\n+', '\n', docs[0].page_content)[:100])
Number of documents: 2
 
【Python】Hello World 输入输出_python你好世界输入,输出英文-CSDN博客
【Python】Hello World 输入输出
最新推荐文章于 2024-12-04 08:5

CSV Loader

from langchain_community.document_loaders.csv_loader import CSVLoader

# Create CSVLoader instance
loader = CSVLoader(file_path="./data/titanic.csv")

# Load documents
docs = loader.load()

print(docs[0])
page_content='PassengerId: 1
Survived: 0
Pclass: 3
Name: Braund, Mr. Owen Harris
Sex: male
Age: 22
SibSp: 1
Parch: 0
Ticket: A/5 21171
Fare: 7.25
Cabin: 
Embarked: S' metadata={'source': './data/titanic.csv', 'row': 0}
docs[0].page_content
'PassengerId: 1\nSurvived: 0\nPclass: 3\nName: Braund, Mr. Owen Harris\nSex: male\nAge: 22\nSibSp: 1\nParch: 0\nTicket: A/5 21171\nFare: 7.25\nCabin: \nEmbarked: S'

它会读取 header 然后把每行数据重新组织

原始数据

PassengerId,Survived,Pclass,Name,Sex,Age,SibSp,Parch,Ticket,Fare,Cabin,Embarked 
1,0,3,"Braund, Mr. Owen Harris",male,22,1,0,A/5 21171,7.25,,S

PassengerId: 1\nSurvived: 0\nPclass: 3\nName: Braund, Mr. Owen Harris\nSex: male\nAge: 22\nSibSp: 1\nParch: 0\nTicket: A/5 21171\nFare: 7.25\nCabin: \nEmbarked: S

自定义 CSV 解析和加载

CSVLoader 接受一个 csv_args 关键字参数,用于定制传递给 Python 的 csv.DictReader 的参数。这使得你可以处理各种 CSV 格式,如自定义分隔符、引号字符或特定的换行符处理。

有关支持的 csv_args 及如何根据你的特定需求定制解析的更多信息,请参见 Python 的 csv 模块 文档。

loader = CSVLoader(
    file_path="./data/titanic.csv",
    csv_args={
        "delimiter": ",",
        "quotechar": '"',
        "fieldnames": [
            "Passenger ID",
            "Survival (1: Survived, 0: Died)",
            "Passenger Class",
            "Name",
            "Sex",
            "Age",
            "Number of Siblings/Spouses Aboard",
            "Number of Parents/Children Aboard",
            "Ticket Number",
            "Fare",
            "Cabin",
            "Port of Embarkation",
        ],
    },
)

docs = loader.load()

print(docs[1].page_content)
Passenger ID: 1
Survival (1: Survived, 0: Died): 0
Passenger Class: 3
Name: Braund, Mr. Owen Harris
Sex: male
Age: 22
Number of Siblings/Spouses Aboard: 1
Number of Parents/Children Aboard: 0
Ticket Number: A/5 21171
Fare: 7.25
Cabin: 
Port of Embarkation: S
loader = CSVLoader(
    file_path="./data/titanic.csv",
    csv_args={
        "delimiter": ",",
        "quotechar": '"',
        "fieldnames": [
            "Passenger ID",
            "Survival (1: Survived, 0: Died)",
            "Passenger Class",
            "Name",
            "Sex",
            "Age",
        ],
    },
)

docs = loader.load()

print(docs[1].page_content)
Passenger ID: 1
Survival (1: Survived, 0: Died): 0
Passenger Class: 3
Name: Braund, Mr. Owen Harris
Sex: male
Age: 22
None: 1,0,A/5 21171,7.25,,S

这些参数其实没啥好解释的, fieldnames 不是用于选择列的, 而是重新命名的, 如果部分列没命名, 那会分到 None 列

你应该使用 source_column 参数来指定每一行生成文档的来源。否则,file_path 将作为所有从 CSV 文件创建的文档的来源。

当在一个用于基于源信息回答问题的链中使用从 CSV 文件加载的文档时,这一点尤其有用。

loader = CSVLoader(
    file_path="./data/titanic.csv",
    source_column="PassengerId",  # Specify the source column
)

docs = loader.load()  

print(docs[1])
page_content='PassengerId: 2
Survived: 1
Pclass: 1
Name: Cumings, Mrs. John Bradley (Florence Briggs Thayer)
Sex: female
Age: 38
SibSp: 1
Parch: 0
Ticket: PC 17599
Fare: 71.2833
Cabin: C85
Embarked: C' metadata={'source': '2', 'row': 1}

注意 metadata.source 变成了对应的 PassengerId

DataFrameLoader

Pandas 是一个开源的数据分析和处理工具,专为 Python 编程语言设计。该库在数据科学、机器学习以及多个领域中广泛应用,用于处理各种数据。

LangChain 的 DataFrameLoader 是一个强大的工具,旨在无缝地将 Pandas DataFrame 集成到 LangChain 工作流中。

from langchain_community.document_loaders import DataFrameLoader
import pandas as pd

df = pd.read_csv("./data/titanic.csv")
# df = pd.read_excel("./data/titanic.xlsx")

print(df.head(n=5))
# The Name column of the DataFrame is specified to be used as the content of each document.
loader = DataFrameLoader(df, page_content_column="Name")

docs = loader.load()

print(docs[0].page_content)

   PassengerId  Survived  Pclass  \
0            1         0       3   
1            2         1       1   
2            3         1       3   
3            4         1       1   
4            5         0       3   

                                                Name     Sex   Age  SibSp  \
0                            Braund, Mr. Owen Harris    male  22.0      1   
1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   
2                             Heikkinen, Miss. Laina  female  26.0      0   
3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   
4                           Allen, Mr. William Henry    male  35.0      0   

   Parch            Ticket     Fare Cabin Embarked  
0      0         A/5 21171   7.2500   NaN        S  
1      0          PC 17599  71.2833   C85        C  
2      0  STON/O2. 3101282   7.9250   NaN        S  
3      0            113803  53.1000  C123        S  
4      0            373450   8.0500   NaN        S  
Braund, Mr. Owen Harris

可通过 page_content_column 来指定哪些 dataframe 的列被读取. csv 和 excel 文件都可以用 DataFrameLoader 加载

Docx2txtLoader

  • 采用轻量级的 Python 模块 docx2txt 进行文本提取。
  • 快速简单地从 .docx 文件中提取文本。
  • 适用于高效且直接的文本处理任务。
from langchain_community.document_loaders import Docx2txtLoader

# Initialize the document loader
loader = Docx2txtLoader("data/sample-word-document_eng.docx")

# Load the document
docs = loader.load()

# Print the metadata of the document
print(f"Document Metadata: {docs[0].metadata}\n")

# Note: The entire docx file is converted into a single document.
# It needs to be split into smaller parts using a text splitter.
print('-'*5)
print(docs[0].page_content[:100])
Document Metadata: {'source': 'data/sample-word-document_eng.docx'}

-----
Semantic Search



Definition: Semantic search is a search methodology that goes beyond simple keywo

不像 PDF Loader 会默认根据页切分文档, Docx2txtLoader 会把一个文件读取为一个 Document

TXT Loader

from langchain_community.document_loaders import TextLoader

# Create a text loader
loader = TextLoader("data/appendix-keywords.txt", encoding="utf-8")

# Load the document
docs = loader.load()
print(f"Number of documents: {len(docs)}\n")
print("[Metadata]\n")
print(docs[0].metadata)
print("\n========= [Preview - First 500 Characters] =========\n")
print(docs[0].page_content[:500])
Number of documents: 1

[Metadata]

{'source': 'data/appendix-keywords.txt'}

========= [Preview - First 500 Characters] =========

Semantic Search

Definition: Semantic search is a search method that goes beyond simple keyword matching by understanding the meaning of the user’s query to return relevant results.
Example: If a user searches for “planets in the solar system,” the system might return information about related planets such as “Jupiter” or “Mars.”
Related Keywords: Natural Language Processing, Search Algorithms, Data Mining

Embedding

Definition: Embedding is the process of converting textual data, such as words

JSONLoader

from langchain_community.document_loaders import JSONLoader

# Create JSONLoader
loader = JSONLoader(
    file_path="data/people.json",
    jq_schema=".people[]",  # Access each item in the people array
    text_content=False,
)

# Example: extract only contact_details
# loader = JSONLoader(
#     file_path="data/people.json",
#     jq_schema=".people[].contact_details",
#     text_content=False,
# )

# Or extract only hobbies from personal_preferences
# loader = JSONLoader(
#     file_path="data/people.json",
#     jq_schema=".people[].personal_preferences.hobbies",
#     text_content=False,
# )

# Load documents
docs = loader.load()
docs
[Document(metadata={'source': '/data02/hyzhang10/pengxia2/LangChain-tutorial/data/people.json', 'seq_num': 1}, page_content='{"name": {"first": "Alice", "last": "Johnson"}, "age": 28, "contact": {"email": "alice.johnson@example.com", "phone": "+1-555-0123", "social_media": {"twitter": "@alice_j", "linkedin": "linkedin.com/in/alicejohnson"}}, "address": {"street": "123 Maple St", "city": "Springfield", "state": "IL", "zip": "62704", "country": "USA"}, "personal_preferences": {"hobbies": ["Reading", "Hiking", "Cooking"], "favorite_food": "Italian", "music_genre": "Jazz", "travel_destinations": ["Japan", "Italy", "Canada"]}, "interesting_fact": "Alice has traveled to over 15 countries and speaks 3 languages."}'),
 Document(metadata={'source': '/data02/hyzhang10/pengxia2/LangChain-tutorial/data/people.json', 'seq_num': 2}, page_content='{"name": {"first": "Bob", "last": "Smith"}, "age": 34, "contact": {"email": "bob.smith@example.com", "phone": "+1-555-0456", "social_media": {"twitter": "@bobsmith34", "linkedin": "linkedin.com/in/bobsmith"}}, "address": {"street": "456 Oak Ave", "city": "Metropolis", "state": "NY", "zip": "10001", "country": "USA"}, "personal_preferences": {"hobbies": ["Photography", "Cycling", "Video Games"], "favorite_food": "Mexican", "music_genre": "Rock", "travel_destinations": ["Brazil", "Australia", "Germany"]}, "interesting_fact": "Bob is an avid gamer and has competed in several national tournaments."}'),
 Document(metadata={'source': '/data02/hyzhang10/pengxia2/LangChain-tutorial/data/people.json', 'seq_num': 3}, page_content='{"name": {"first": "Charlie", "last": "Davis"}, "age": 45, "contact": {"email": "charlie.davis@example.com", "phone": "+1-555-0789", "social_media": {"twitter": "@charliedavis45", "linkedin": "linkedin.com/in/charliedavis"}}, "address": {"street": "789 Pine Rd", "city": "Gotham", "state": "NJ", "zip": "07001", "country": "USA"}, "personal_preferences": {"hobbies": ["Gardening", "Fishing", "Woodworking"], "favorite_food": "Barbecue", "music_genre": "Country", "travel_destinations": ["Canada", "New Zealand", "Norway"]}, "interesting_fact": "Charlie has a small farm where he raises chickens and grows organic vegetables."}'),
 Document(metadata={'source': '/data02/hyzhang10/pengxia2/LangChain-tutorial/data/people.json', 'seq_num': 4}, page_content='{"name": {"first": "Dana", "last": "Lee"}, "age": 22, "contact": {"email": "dana.lee@example.com", "phone": "+1-555-0111", "social_media": {"twitter": "@danalee22", "linkedin": "linkedin.com/in/danalee"}}, "address": {"street": "234 Birch Blvd", "city": "Star City", "state": "CA", "zip": "90001", "country": "USA"}, "personal_preferences": {"hobbies": ["Dancing", "Sketching", "Traveling"], "favorite_food": "Thai", "music_genre": "Pop", "travel_destinations": ["Thailand", "France", "Spain"]}, "interesting_fact": "Dana is a dance instructor and has won several local competitions."}'),
 Document(metadata={'source': '/data02/hyzhang10/pengxia2/LangChain-tutorial/data/people.json', 'seq_num': 5}, page_content='{"name": {"first": "Ethan", "last": "Garcia"}, "age": 31, "contact": {"email": "ethan.garcia@example.com", "phone": "+1-555-0999", "social_media": {"twitter": "@ethangarcia31", "linkedin": "linkedin.com/in/ethangarcia"}}, "address": {"street": "345 Cedar St", "city": "Central City", "state": "TX", "zip": "75001", "country": "USA"}, "personal_preferences": {"hobbies": ["Running", "Travel Blogging", "Cooking"], "favorite_food": "Indian", "music_genre": "Hip-Hop", "travel_destinations": ["India", "Italy", "Mexico"]}, "interesting_fact": "Ethan runs a popular travel blog where he shares his adventures and culinary experiences."}')]

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SQLAlchemy-2.0中模型定义和alembic的数据库迁移工具

SQLAlchemy-2.0中模型定义和alembic的数据库迁移工具 一、SQLAIchemy的介绍二、数据库引擎1、支持的数据库1.1、sqlite数据库1.2、MySQL数据库1.3、数据库引擎的参数 三、定义模型类1、定义模型2、engine负责数据库迁移 四、alembic数据库迁移⼯具1、安装alembic2、初始化alemb…

C# OpenCV机器视觉:图像风格迁移

在一个充满奇思妙想的创意工作室里,小李正像只热锅上的蚂蚁,为客户的项目挠破了脑袋,急需寻找灵感的火花。他望着眼前那幅平淡无奇的风景图像,心想:“这玩意儿也太普通啦,就像一杯白开水,怎么能…

语言月赛 202311【基因】题解(AC)

》》》点我查看「视频」详解》》》 [语言月赛 202311] 基因 题目描述 有一个长度为 n n n 的字符串 S S S。其只包含有大写字母。 小 A 将 S S S 进行翻转后,得到另一个字符串 S ′ S S′。两个字符串 S S S 与 S ′ S S′ 对应配对。例如说,对…

Spring @PropertySource:让你的应用配置更加模块化和可维护

PropertySource注解在Spring中的作用,就像是给Spring应用配了一个“外部配置箱”。 想象一下,你在开发一个Spring应用时,有很多配置信息需要设置,比如数据库的连接信息、应用的某些功能开关等。如果这些信息都硬编码在代码中&…

Deep Sleep 96小时:一场没有硝烟的科技保卫战

2025年1月28日凌晨3点,当大多数人还沉浸在梦乡时,一场没有硝烟的战争悄然打响。代号“Deep Sleep”的服务器突遭海量数据洪流冲击,警报声响彻机房,一场针对中国关键信息基础设施的网络攻击来势汹汹! 面对美国发起的这场…

快速搭建GPU环境 | docker、k8s中使用gpu

目录 一、裸机部署安装 GPU Driver安装 CUDA Toolkit测试 二、Docker 环境安装 nvidia-container-toolkit配置使用该 runtime 三、 k8s 环境安装 device-plugin安装 GPU 监控 一、裸机部署 裸机中要使用上 GPU 需要安装以下组件: GPU DriverCUDA Toolkit 二者的关…

npm中央仓库

1、官网地址 npm | Home 2、搜索依赖包

2025年软考考试时间及考试科目如何安排?附考试注意事项!

一、考试时间 2025年软考举行两次考试,分别安排在上半年和下半年。根据最新公布的信息,2025年软考考试的具体时间安排如下: 上半年考试时间:5月24日至5月27日 下半年考试时间:11月8日至11月11日 考生需要在规定的时间内…

4.PPT:日月潭景点介绍【18】

目录 NO1、2、3、4​ NO5、6、7、8 ​ ​NO9、10、11、12 ​ 表居中或者水平/垂直居中单元格内容居中或者水平/垂直居中 NO1、2、3、4 新建一个空白演示文稿,命名为“PPT.pptx”(“.pptx”为扩展名)新建幻灯片 开始→版式“PPT_素材.doc…

HTML排版标签、语义化标签、块级和行内元素详解

目录 前言 一、HTML中的排版标签 1. 文本相关标签 1.1 标题标签 ~ 1.2 段落标签 1.3 强调和加粗 1.4 换行标签 1.5 水平线标签 二、HTML中的语义化标签 2.1 语义化标签概述 2.2 常见的语义化标签 示例(核心代码部分): 三、HTM…

机器学习中的关键概念:通过SKlearn的MNIST实验深入理解

欢迎来到我的主页:【Echo-Nie】 本篇文章收录于专栏【机器学习】 1 sklearn相关介绍 Scikit-learn 是一个广泛使用的开源机器学习库,提供了简单而高效的数据挖掘和数据分析工具。它建立在 NumPy、SciPy 和 matplotlib 等科学计算库之上,支持…

用NeuralProphet预测股价:AI金融新利器(附源码)

作者:老余捞鱼 原创不易,转载请标明出处及原作者。 写在前面的话:我用NeuralProphet模型预测了股票价格,发现其通过结合时间序列分析和神经网络算法,确实能提供比传统Last Value方法更精准的预测。经过一系列超参数调优…

深度学习-103-RAG技术之通过分块技术提升RAG的效果

文章目录 1 RAG中的分块技术1.1 RAG是什么1.2 分块chunking是什么1.3 分块的重要性1.4 分块的技巧2 固定字符大小分块2.1 固定字符大小分块的优缺点2.2 自定义分块代码2.3 LangChain的CharacterTextSplitter3 递归字符文本分割3.1 递归字符文本分割的优缺点3.2 LangChain的Recu…

【B站保姆级视频教程:Jetson配置YOLOv11环境(六)PyTorchTorchvision安装】

Jetson配置YOLOv11环境(6)PyTorch&Torchvision安装 文章目录 1. 安装PyTorch1.1安装依赖项1.2 下载torch wheel 安装包1.3 安装 2. 安装torchvisiion2.1 安装依赖2.2 编译安装torchvision2.2.1 Torchvisiion版本选择2.2.2 下载torchvisiion到Downloa…

Java进阶14 TCP日志枚举

Java进阶14 TCP&日志&枚举 一、网络编程TCP Java对基于TCP协议得网络提供了良好的封装,使用Socket对象来代表两端的通信端口,并通过Socket产生IO流来进行网络通信。 1、TCP协议发数据 1.1 构造方法 方法 说明 Socket(InetAddress address…

[LVGL] 在VC_MFC中移植LVGL

前言: 0. 在MFC中开发LVGL的优点是可以用多个Window界面做辅助扩展 1.本文基于VC2022-MFC单文档框架移植lvgl8 2. gitee上下载lvgl8.3 源码,并将其文件夹改名为lvgllvgl: LVGL 是一个开源图形库,提供您创建具有易于使用的图形元素、漂亮的…

Crewai框架配置回调函数

官方文档里只指提了一句 不过不太难,在crew.py文件里配置一下就行了,下面是一个demo,这个函数会在research_task任务执行完触发(配置LLM这里请看我这篇博客) from crewai import Crew, Process, Agent, Taskfrom src.…

拧紧“安全阀”,AORO-P300 Ultra防爆平板畅通新型工业化通信“大动脉”

在油气管道泄漏的浓烟中,在矿道坍塌的密闭空间里,在洪水肆虐的救援现场,传统通讯设备频频失效的困境已成为历史。AORO-P300 Ultra防爆平板集5G通讯、红外感知、应急照明等实用功能于一体,以军工级防护与全场景智能应用&#xff0c…

基于docker搭建Kafka集群,使用KRaft方式搭建,摒弃Zookeeper

KAFKA基于docker使用KRaft进行集群搭建 环境:已成功搭建kafka服务 可点击链接跳转至安装kafka-3.8.0版本 并启用SASL认证 教程 使用基于Zookeeper方式搭建集群教程 kafka-3.8.0版本 并启用SASL认证 教程 搭建kafka-ui可视化工具 192.168.2.91 192.168.2.92 192…

CAD导入与解析,助力工业数据可视化高效呈现

背景 在企业的日常设计与管理中,CAD图纸早已成为不可或缺的重要资产,多年来知识积累的载体,凝聚了大量的心血与智慧。然而,CAD图纸往往只作为静态文件保存,应用场景较为有限。在数字经济时代,如何让CAD图纸…