Browse Source

feat: 更新文档

master
yuanjs@qutke.com 2 months ago
parent
commit
5964c1a43c
  1. 447
      README.md
  2. BIN
      img/0-2288864.png
  3. BIN
      img/0.png
  4. BIN
      img/1-1073680.png
  5. BIN
      img/1-1579900.png
  6. BIN
      img/1-1859494.png
  7. BIN
      img/1-2537508.png
  8. BIN
      img/1-2540349.png
  9. BIN
      img/1-2885071.png
  10. BIN
      img/1-2901569.png
  11. BIN
      img/1.png
  12. BIN
      img/2-1580890.png
  13. BIN
      img/2-2287117.png
  14. BIN
      img/2-2540359.png
  15. BIN
      img/2-2902256.png
  16. BIN
      img/2.png
  17. BIN
      img/3-2540810.png
  18. BIN
      img/3-2907855.png
  19. BIN
      img/4.png
  20. BIN
      img/collection-explained.png
  21. BIN
      img/export_4232z.png
  22. BIN
      img/export_a9yct.png
  23. BIN
      img/export_j1u9v.png
  24. BIN
      img/export_qtyb85.png
  25. BIN
      img/image-20250301140503525.png
  26. BIN
      img/image-20250301140529990.png
  27. BIN
      img/image-20250301140650448.png
  28. BIN
      img/image-20250301141529448.png
  29. BIN
      img/image-20250301152117731.png
  30. BIN
      img/image-20250313142026018.png
  31. BIN
      img/image-20250313151603856.png
  32. BIN
      img/image-20250313151657094.png
  33. BIN
      img/image-20250313151724171.png
  34. BIN
      img/image-20250313151918579.png
  35. BIN
      img/image-20250313161943645.png
  36. BIN
      img/image-20250313162742811.png
  37. BIN
      img/image-20250313162827278.png
  38. BIN
      img/image-20250313164754696.png
  39. BIN
      img/image-20250313170520819.png
  40. BIN
      img/image-20250313170904153.png
  41. BIN
      img/image-20250313210027704.png
  42. BIN
      img/image-20250313212722723.png
  43. BIN
      img/image-20250313215608473.png
  44. BIN
      img/image-20250314122237372.png
  45. BIN
      img/image-20250315152627015.png
  46. BIN
      img/image-20250318151846918.png
  47. BIN
      img/image-20250318155633751.png
  48. BIN
      img/image-20250318190605311.png
  49. BIN
      img/image-20250318201255473.png
  50. BIN
      img/milvus-adopters.png

447
README.md

@ -6037,8 +6037,6 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 矛盾内容 * 矛盾内容
* 例:同一段回答中前后逻辑冲突(如先说“地球是平的”,后又说“地球绕太阳公转”) * 例:同一段回答中前后逻辑冲突(如先说“地球是平的”,后又说“地球绕太阳公转”)
<img src="/img/image-20250310151927722.png" alt="image-20250310151927722" style="zoom:50%;" />
* 幻觉产生的根本原因 * 幻觉产生的根本原因
* **训练数据的局限性** * **训练数据的局限性**
@ -6274,8 +6272,6 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* **为啥检索到词条后,还可以用调整输出内容,更加友好?** * **为啥检索到词条后,还可以用调整输出内容,更加友好?**
* **什么是嵌入大模型?和前面学的LLM大模型有啥区别?** * **什么是嵌入大模型?和前面学的LLM大模型有啥区别?**
<img src="/img/image-20250314124004485.png" alt="image-20250314124004485" style="zoom:50%;" />
### RAG 检索增强生成之Loader实战 ### RAG 检索增强生成之Loader实战
#### RAG系统链路和数据加载Loaders技术 #### RAG系统链路和数据加载Loaders技术
@ -7496,8 +7492,6 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* **LLM大模型的RAG原理:用户输入自然语言query,找到最相关的文档** * **LLM大模型的RAG原理:用户输入自然语言query,找到最相关的文档**
* 这些场景的共同点:需要量化两个事物的相似程度,向量空间中的"方向感" * 这些场景的共同点:需要量化两个事物的相似程度,向量空间中的"方向感"
<img src="/img/image-20250313170154488.png" alt="image-20250313170154488" style="zoom:30%;" />
* 什么是余弦相似度? * 什么是余弦相似度?
* 基础定义:余弦相似度(Cosine Similarity)用于衡量两个向量在方向上的相似程度,忽略其绝对长度 * 基础定义:余弦相似度(Cosine Similarity)用于衡量两个向量在方向上的相似程度,忽略其绝对长度
@ -8911,26 +8905,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| **动态Schema** | 允许灵活字段(需Milvus 2.3+) | 日志类多变数据 | | **动态Schema** | 允许灵活字段(需Milvus 2.3+) | 日志类多变数据 |
#### Milvus索引操作和最佳实践避坑指南
#### 第2集 Milvus索引操作和最佳实践避坑指南
**简介: Milvus索引操作和最佳实践避坑指南**
* 为什么需要索引? * 为什么需要索引?
@ -8952,7 +8927,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 创建索引 * 创建索引
``` ```python
# 导入MilvusClient和DataType模块,用于连接Milvus服务器并操作数据类型 # 导入MilvusClient和DataType模块,用于连接Milvus服务器并操作数据类型
from pymilvus import MilvusClient, DataType from pymilvus import MilvusClient, DataType
@ -9012,7 +8987,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 查看索引信息 * 查看索引信息
``` ```python
#列出索引名称 #列出索引名称
res = client.list_indexes( res = client.list_indexes(
collection_name="customized_setup" collection_name="customized_setup"
@ -9032,7 +9007,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 删除前需确保无查询正在使用该索引 * 删除前需确保无查询正在使用该索引
* 删除后需重新创建索引才能进行有效查询 * 删除后需重新创建索引才能进行有效查询
``` ```python
#如果不再需要索引,可以直接将其删除。 #如果不再需要索引,可以直接将其删除。
client.drop_index( client.drop_index(
collection_name="customized_setup", collection_name="customized_setup",
@ -9071,27 +9046,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| "主键冲突" | 插入前检查ID唯一性,或使用自动生成ID | | "主键冲突" | 插入前检查ID唯一性,或使用自动生成ID |
| "向量维度错误" | 校验dim参数与数据实际维度 | | "向量维度错误" | 校验dim参数与数据实际维度 |
#### Milvus向量数据库的DML操作实战
#### 第3集 Milvus向量数据库的DML操作实战
**简介: Milvus向量数据库的DML操作实战**
* 核心DML操作实战 * 核心DML操作实战
@ -9100,7 +9055,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* `auto_id=True`时无需手动指定主键 * `auto_id=True`时无需手动指定主键
* 动态字段(`enable_dynamic_field=True`)允许灵活扩展非预定义字段 * 动态字段(`enable_dynamic_field=True`)允许灵活扩展非预定义字段
``` ```python
# 导入MilvusClient和DataType模块,用于连接Milvus服务器并操作数据类型 # 导入MilvusClient和DataType模块,用于连接Milvus服务器并操作数据类型
from pymilvus import MilvusClient, DataType from pymilvus import MilvusClient, DataType
@ -9133,7 +9088,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 插入数据(Insert)支持单条或批量插入【可视化工具那边需要加载,包括查询等都是需要加载状态才可以操作】 * 插入数据(Insert)支持单条或批量插入【可视化工具那边需要加载,包括查询等都是需要加载状态才可以操作】
``` ```python
data = [ data = [
{"id": 1, "vector": [0.1]*128, "text": "Sample text 1"}, {"id": 1, "vector": [0.1]*128, "text": "Sample text 1"},
{"id": 2, "vector": [0.2]*128, "text": "Sample text 2"} {"id": 2, "vector": [0.2]*128, "text": "Sample text 2"}
@ -9149,7 +9104,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 删除数据(Delete)通过主键或条件表达式删除 * 删除数据(Delete)通过主键或条件表达式删除
``` ```python
# 按主键删除 # 按主键删除
client.delete( client.delete(
collection_name="my_collection", collection_name="my_collection",
@ -9165,7 +9120,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 更新数据(Update)Milvus不支持直接更新,需通过“删除+插入”实现: * 更新数据(Update)Milvus不支持直接更新,需通过“删除+插入”实现:
``` ```python
# 删除旧数据 # 删除旧数据
client.delete(collection_name="my_collection", ids=[3]) client.delete(collection_name="my_collection", ids=[3])
@ -9177,28 +9132,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### Milvus向量Search查询综合案例实战
#### 第4集 Milvus向量Search查询综合案例实战《上》
**简介: Milvus向量Search查询综合案例实战**
* 需求说明 * 需求说明
@ -9211,7 +9145,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 核心参数说明 * 核心参数说明
``` ```python
results = client 或 collection.search( results = client 或 collection.search(
data=[[0.12, 0.23, ..., 0.88]], # 查询向量(必须) data=[[0.12, 0.23, ..., 0.88]], # 查询向量(必须)
anns_field="vector", # 要搜索的向量字段名(必须) anns_field="vector", # 要搜索的向量字段名(必须)
@ -9235,7 +9169,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 准备数据 * 准备数据
``` ```python
from pymilvus import ( from pymilvus import (
connections,MilvusClient, connections,MilvusClient,
FieldSchema, CollectionSchema, DataType, FieldSchema, CollectionSchema, DataType,
@ -9295,7 +9229,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 创建索引 * 创建索引
``` ```python
# 准备索引参数,为"vector"字段创建索引 # 准备索引参数,为"vector"字段创建索引
index_params = MilvusClient.prepare_index_params() index_params = MilvusClient.prepare_index_params()
@ -9318,7 +9252,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 执行查询【执行查询前需要加载才可以使用】 * 执行查询【执行查询前需要加载才可以使用】
``` ```python
client.load_collection(collection_name="book") # 加载集合到内存 client.load_collection(collection_name="book") # 加载集合到内存
# 生成查询向量 # 生成查询向量
query_vector = [random.random() for _ in range(4)] query_vector = [random.random() for _ in range(4)]
@ -9343,24 +9277,6 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
print("-" * 30) print("-" * 30)
``` ```
#### 第5集 Milvus向量Search查询综合案例实战《下》
**简介: Milvus向量Search查询综合案例实战**
* 向量数据库完整工作流程示意图 * 向量数据库完整工作流程示意图
``` ```
@ -9379,7 +9295,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 测试是否有 output_fields 字段,返回结果的差异 * 测试是否有 output_fields 字段,返回结果的差异
``` ```python
# 案例1:基础向量查询 # 案例1:基础向量查询
basic_res = client.search( basic_res = client.search(
collection_name="book", collection_name="book",
@ -9406,7 +9322,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 集合状态 * 集合状态
``` ```python
# 验证集合状态 # 验证集合状态
print(client.describe_collection("book")) print(client.describe_collection("book"))
@ -9426,30 +9342,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| 错误处理 | 异常类捕获 | 统一错误码系统 | | 错误处理 | 异常类捕获 | 统一错误码系统 |
| 动态字段支持 | 需要额外配置 | 参数开启即可 | | 动态字段支持 | 需要额外配置 | 参数开启即可 |
### MMR搜索和LangChain整合Milvus实战
#### 相似度Similarity和MMR最大边界相关搜索
![logo](D:/小滴课堂AI/AI智能化云盘/笔记/img/image-20230918114907133-5008948.png) **愿景:"IT路上的持续充电平台,让技术不再难学"**
**更多高级课程请访问 xdclass.net**
### 第四十一章 MMR搜索和LangChain整合Milvus实战
#### 第1集 相似度Similarity和MMR最大边界相关搜索
**简介: 相似度Similarity和MMR最大边界相关搜索**
* 搜索的行业应用案例:电商推荐系统(明白两个差异) * 搜索的行业应用案例:电商推荐系统(明白两个差异)
@ -9465,13 +9360,11 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
"用户浏览历史多样 → 推荐跨品类商品" "用户浏览历史多样 → 推荐跨品类商品"
``` ```
* 基础相似度搜索(Similarity Search) * 基础相似度搜索(Similarity Search)
* **原理**:通过向量空间中的距离计算(余弦相似度/L2距离等)找出最接近目标向量的结果 * **原理**:通过向量空间中的距离计算(余弦相似度/L2距离等)找出最接近目标向量的结果
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/1-2540349.png" alt="1" style="zoom:50%;" /> <img src="/img/1-2540349.png" alt="1" style="zoom:50%;" />
* 核心特点 * 核心特点
@ -9481,7 +9374,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 参数配置模板,方法 `vector_store.similarity_search( )` * 参数配置模板,方法 `vector_store.similarity_search( )`
``` ```python
vector_store.as_retriever( vector_store.as_retriever(
search_type="similarity", search_type="similarity",
search_kwargs={ search_kwargs={
@ -9513,7 +9406,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 设计初衷是解决传统相似性搜索(如余弦相似度)可能导致的“信息冗余”问题,在需要覆盖多角度信息或推荐多样化内容的场景中效果显著 * 设计初衷是解决传统相似性搜索(如余弦相似度)可能导致的“信息冗余”问题,在需要覆盖多角度信息或推荐多样化内容的场景中效果显著
* **原理**:在相似度和多样性之间进行权衡,避免结果冗余 * **原理**:在相似度和多样性之间进行权衡,避免结果冗余
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/2-2540359.png" alt="2" style="zoom:50%;" /> <img src="/img/2-2540359.png" alt="2" style="zoom:50%;" />
* 算法原理图解 * 算法原理图解
@ -9531,7 +9424,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 参数配置模板, 方法 `vector_store.max_marginal_relevance_search( )` * 参数配置模板, 方法 `vector_store.max_marginal_relevance_search( )`
``` ```python
mmr_retriever = vector_store.as_retriever( mmr_retriever = vector_store.as_retriever(
search_type="mmr", search_type="mmr",
search_kwargs={ search_kwargs={
@ -9573,25 +9466,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 企业推荐系统架构示例 * 企业推荐系统架构示例
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/3-2540810.png" alt="3" style="zoom:50%;" /> <img src="/img/3-2540810.png" alt="3" style="zoom:50%;" />
#### 新版LangChain向量数据库VectorStore设计
#### 第2集 新版LangChain向量数据库VectorStore设计
**简介: 新版LangChain向量数据库VectorStore设计**
* LangChain 向量存储体系架构 * LangChain 向量存储体系架构
@ -9619,7 +9496,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
from langchain_core.vectorstores import VectorStore from langchain_core.vectorstores import VectorStore
``` ```
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/1-2537508.png" alt="1" style="zoom:50%;" /> <img src="/img/1-2537508.png" alt="1" style="zoom:50%;" />
* VectorStore 核心方法详解 * VectorStore 核心方法详解
@ -9636,7 +9513,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 初始化方法 * 初始化方法
``` ```python
@classmethod @classmethod
def from_documents( def from_documents(
cls, cls,
@ -9683,7 +9560,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 相似性搜索方法 * 相似性搜索方法
``` ```python
def similarity_search( def similarity_search(
self, self,
query: str, query: str,
@ -9702,7 +9579,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 最大边界相关算法(MMR) * 最大边界相关算法(MMR)
``` ```python
def max_marginal_relevance_search( def max_marginal_relevance_search(
self, self,
query: str, query: str,
@ -9730,27 +9607,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 场景:知识库冷启动 * 场景:知识库冷启动
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/export_j1u9v.png" alt="export_j1u9v" style="zoom:50%;" /> <img src="/img/export_j1u9v.png" alt="export_j1u9v" style="zoom:50%;" />
#### LangChain整合Milvus新增和删除实战
#### 第3集 LangChain整合Milvus新增和删除实战
**简介: LangChain整合Milvus新增和删除实战**
* 需求 * 需求
@ -9763,7 +9622,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 准备数据 * 准备数据
``` ```python
from langchain_community.embeddings import DashScopeEmbeddings from langchain_community.embeddings import DashScopeEmbeddings
#from langchain.vectorstores import Milvus #from langchain.vectorstores import Milvus
from langchain_milvus import Milvus from langchain_milvus import Milvus
@ -9829,7 +9688,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 插入 * 插入
``` ```python
ids = [ str(i+1) for i in range(len(documents))] ids = [ str(i+1) for i in range(len(documents))]
print(ids) print(ids)
result = vector_store.add_documents(documents=documents, ids=ids) result = vector_store.add_documents(documents=documents, ids=ids)
@ -9838,25 +9697,14 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 删除 * 删除
``` ```python
result = vector_store.delete(ids=["1"]) result = vector_store.delete(ids=["1"])
print(result) print(result)
#(insert count: 0, delete count: 1, upsert count: 0, timestamp: 456798840753225732, success count: 0, err count: 0 #(insert count: 0, delete count: 1, upsert count: 0, timestamp: 456798840753225732, success count: 0, err count: 0
``` ```
#### LangChain实战MMR和相似性搜索实战
#### 第4集 LangChain实战MMR和相似性搜索实战
**简介: LangChain实战MMR和相似性搜索实战**
* 需求 * 需求
@ -9867,7 +9715,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 准备数据【**执行多次有多条重复记录,向量数据库不会去重,方便测试MMR**】 * 准备数据【**执行多次有多条重复记录,向量数据库不会去重,方便测试MMR**】
``` ```python
from langchain_community.embeddings import DashScopeEmbeddings from langchain_community.embeddings import DashScopeEmbeddings
#from langchain.vectorstores import Milvus #from langchain.vectorstores import Milvus
from langchain_milvus import Milvus from langchain_milvus import Milvus
@ -9907,7 +9755,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 相似性搜索(向量数据库插入多个重复数据,看是否会返回一样的) * 相似性搜索(向量数据库插入多个重复数据,看是否会返回一样的)
``` ```python
# 相似性搜索 # 相似性搜索
query = "如何进行数据库集成?" query = "如何进行数据库集成?"
results = vector_store.similarity_search(query, k=2) results = vector_store.similarity_search(query, k=2)
@ -9926,7 +9774,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* MMR搜索(跨类搭配,向量数据库插入多个重复数据,看是否会返回一样的) * MMR搜索(跨类搭配,向量数据库插入多个重复数据,看是否会返回一样的)
``` ```python
# MMR推荐(跨类搭配) # MMR推荐(跨类搭配)
diverse_results = vector_store.max_marginal_relevance_search( diverse_results = vector_store.max_marginal_relevance_search(
query="如何进行数据库集成", query="如何进行数据库集成",
@ -9944,31 +9792,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
### Retrievers检索器+RAG文档助手项目实战
#### LangChain检索器Retrievers案例实战
![logo](D:/小滴课堂AI/AI智能化云盘/笔记/img/image-20230918114907133-5008948.png) **愿景:"IT路上的持续充电平台,让技术不再难学"**
**更多高级课程请访问 xdclass.net**
### 第四十二章 Retrievers检索器+RAG文档助手项目实战
#### 第1集 LangChain检索器Retrievers案例实战
**简介: LangChain检索器Retrievers案例实战**
* 什么是`Retriever` * 什么是`Retriever`
@ -9980,7 +9806,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* **RAG中的角色**:作为检索增强生成(RAG)流程的“数据入口”,为生成模型提供精准上下文 * **RAG中的角色**:作为检索增强生成(RAG)流程的“数据入口”,为生成模型提供精准上下文
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/data_connection-95ff2033a8faa5f3ba41376c0f6dd32a.jpg" alt="data_connection_diagram" style="zoom:50%;" /> <img src="./img/data_connection-95ff2033a8faa5f3ba41376c0f6dd32a.jpg" alt="data_connection_diagram" style="zoom:50%;" />
* 有多个实现:VectorStoreRetriever、MultiQueryRetriever、SelfQueryRetriever等 * 有多个实现:VectorStoreRetriever、MultiQueryRetriever、SelfQueryRetriever等
@ -10004,7 +9830,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 基础使用参考案例 * 基础使用参考案例
``` ```python
#将文档嵌入为向量,通过相似度计算(如余弦相似度)检索 #将文档嵌入为向量,通过相似度计算(如余弦相似度)检索
from langchain_community.vectorstores import FAISS from langchain_community.vectorstores import FAISS
retriever = FAISS.from_documents(docs, embeddings).as_retriever( retriever = FAISS.from_documents(docs, embeddings).as_retriever(
@ -10019,7 +9845,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 源码 * 源码
``` ```python
def as_retriever(self, **kwargs: Any) -> VectorStoreRetriever: def as_retriever(self, **kwargs: Any) -> VectorStoreRetriever:
tags = kwargs.pop("tags", None) or [] + self._get_retriever_tags() tags = kwargs.pop("tags", None) or [] + self._get_retriever_tags()
return VectorStoreRetriever(vectorstore=self, tags=tags, **kwargs) return VectorStoreRetriever(vectorstore=self, tags=tags, **kwargs)
@ -10038,7 +9864,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| `"mmr"` | 多样性结果优化 | `max_marginal_relevance_search()` | | `"mmr"` | 多样性结果优化 | `max_marginal_relevance_search()` |
| `"similarity_score_threshold"` | 阈值过滤检索 | `search()` + `score_threshold` | | `"similarity_score_threshold"` | 阈值过滤检索 | `search()` + `score_threshold` |
``` ```python
# MMR 检索配置示例 # MMR 检索配置示例
mmr_retriever = vector_store.as_retriever( mmr_retriever = vector_store.as_retriever(
search_type="mmr", search_type="mmr",
@ -10062,7 +9888,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 默认是similarity search * 默认是similarity search
```` ````python
from langchain_community.embeddings import DashScopeEmbeddings from langchain_community.embeddings import DashScopeEmbeddings
from langchain_milvus import Milvus from langchain_milvus import Milvus
from langchain_core.documents import Document from langchain_core.documents import Document
@ -10115,27 +9941,10 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### 大厂面试题-如何提升大模型召回率和实战
#### 第2集 大厂面试题-如何提升大模型召回率和实战
**简介: 大厂面试题-如何提升大模型召回率和案例实战**
* **LLM大模型开发高频面试题:如何提升大模型召回率和准确率?** * **LLM大模型开发高频面试题:如何提升大模型召回率和准确率?**
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/image-20250325144937629.png" alt="image-20250325144937629" style="zoom:50%;" />
* 需求背景 * 需求背景
* 当原始查询不够明确时,或者当文档库中的内容使用不同的术语表达同一概念时 * 当原始查询不够明确时,或者当文档库中的内容使用不同的术语表达同一概念时
@ -10152,11 +9961,11 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* **查询扩展技术**:通过LLM生成N个相关查询(如改写、扩展、翻译),合并结果去重,生成多个变体查询 * **查询扩展技术**:通过LLM生成N个相关查询(如改写、扩展、翻译),合并结果去重,生成多个变体查询
* **双重增强效果**:提升召回率(+25%↑)和准确率(+18%↑)的平衡 * **双重增强效果**:提升召回率(+25%↑)和准确率(+18%↑)的平衡
![1](D:/小滴课堂AI/AI智能化云盘/笔记/img/1-2885071.png) ![1](./img/1-2885071.png)
* 用法 * 用法
``` ```python
retriever = MultiQueryRetriever.from_llm( retriever = MultiQueryRetriever.from_llm(
retriever=base_retriever, retriever=base_retriever,
llm=ChatOpenAI() llm=ChatOpenAI()
@ -10172,7 +9981,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 案例实战 * 案例实战
``` ```python
from langchain_community.embeddings import DashScopeEmbeddings from langchain_community.embeddings import DashScopeEmbeddings
#from langchain.vectorstores import Milvus #from langchain.vectorstores import Milvus
from langchain_milvus import Milvus from langchain_milvus import Milvus
@ -10249,20 +10058,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### RAG综合项目实战-AI文档问答助手
#### 第3集 RAG综合项目实战-AI文档问答助手《上》
**简介: RAG综合项目实战-AI文档问答助手《上》**
* **需求:在线文档的问答助手,方便查找相关手册和接口API** * **需求:在线文档的问答助手,方便查找相关手册和接口API**
@ -10299,7 +10095,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 编码实战 * 编码实战
``` ```python
from langchain_community.document_loaders import WebBaseLoader from langchain_community.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_milvus import Milvus from langchain_milvus import Milvus
@ -10373,22 +10169,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### 第4集 RAG综合项目实战-AI文档问答助手《下》
**简介: RAG综合项目实战-AI文档问答助手《下》**
* 编码测试实战 * 编码测试实战
``` ```python
# 定义PromptTemplate,用于构建输入给LLM的prompt。 # 定义PromptTemplate,用于构建输入给LLM的prompt。
template = """你是AI文档助手,使用以下上下文来回答最后的问题。 template = """你是AI文档助手,使用以下上下文来回答最后的问题。
如果你不知道答案,就说你不知道,不要试图编造答案。 如果你不知道答案,就说你不知道,不要试图编造答案。
@ -10424,7 +10207,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 大家的疑惑点(下一章讲解) * 大家的疑惑点(下一章讲解)
``` ```python
# 构建Retrieval-Augmented Generation链。 # 构建Retrieval-Augmented Generation链。
rag_chain = ( rag_chain = (
{"context": retriever, "question": RunnablePassthrough()} {"context": retriever, "question": RunnablePassthrough()}
@ -10442,30 +10225,9 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* `retriever`完成检索后,会自动把结果赋值给`context`。 * `retriever`完成检索后,会自动把结果赋值给`context`。
* 检索结果`context`和用户输入`question`一并传给提示模板`prompt_template`。 * 检索结果`context`和用户输入`question`一并传给提示模板`prompt_template`。
### 解析和多实现类案例实战
#### LangChain核心之Runnable接口底层实现
![logo](D:/小滴课堂AI/AI智能化云盘/笔记/img/image-20230918114907133-5008948.png) **愿景:"IT路上的持续充电平台,让技术不再难学"**
**更多高级课程请访问 xdclass.net**
### 第四十三章 Runnable深度解析和多实现类案例实战
#### 第1集 LangChain核心之Runnable接口底层实现
**简介: LangChain核心之Runnable接口底层实现**
* 什么是`Runnable`接口 * 什么是`Runnable`接口
@ -10494,7 +10256,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 执行 LCEL链调用的方法(invoke/stream/batch),链中的每个组件也调用对应的方法,将输出作为下一个组件的输入 * 执行 LCEL链调用的方法(invoke/stream/batch),链中的每个组件也调用对应的方法,将输出作为下一个组件的输入
``` ```python
#RunnableSequence.invoke 的源码解读 #RunnableSequence.invoke 的源码解读
def invoke( def invoke(
@ -10543,7 +10305,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* Runnable接口定义了以下核心方法,支持多种执行模式 * Runnable接口定义了以下核心方法,支持多种执行模式
``` ```python
class Runnable(Generic[Input, Output]): class Runnable(Generic[Input, Output]):
#处理单个输入,返回输出。 #处理单个输入,返回输出。
def invoke(self, input: Input) -> Output: ... def invoke(self, input: Input) -> Output: ...
@ -10571,23 +10333,13 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| `RunnableParallel` | 并行执行 | 多任务独立处理 | | `RunnableParallel` | 并行执行 | 多任务独立处理 |
| `RunnablePassthrough` | 数据透传 | 保留原始输入 | | `RunnablePassthrough` | 数据透传 | 保留原始输入 |
#### RunnablePassthrough介绍和透传参数实战
#### 第2集 RunnablePassthrough介绍和透传参数实战
**简介: RunnablePassthrough介绍和透传参数实战**
* `RunnablePassthrough` * `RunnablePassthrough`
* 核心功能:用于在链中直接传递输入数据,不进行任何修改,或通过 `.assign()` 扩展上下文字段 * 核心功能:用于在链中直接传递输入数据,不进行任何修改,或通过 `.assign()` 扩展上下文字段
![2](D:/小滴课堂AI/AI智能化云盘/笔记/img/2-2902256.png) ![2](./img/2-2902256.png)
* 应用场景: * 应用场景:
@ -10596,7 +10348,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 基础用法 * 基础用法
``` ```python
from langchain_core.runnables import RunnablePassthrough from langchain_core.runnables import RunnablePassthrough
# 直接传递输入 # 直接传递输入
@ -10608,7 +10360,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 案例一 * 案例一
``` ```python
# 使用 assign() 添加新字段 # 使用 assign() 添加新字段
from langchain_core.runnables import RunnablePassthrough from langchain_core.runnables import RunnablePassthrough
@ -10627,7 +10379,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 案例二(伪代码) * 案例二(伪代码)
``` ```python
# 构建包含原始问题和处理上下文的链 # 构建包含原始问题和处理上下文的链
chain = ( chain = (
RunnablePassthrough.assign( RunnablePassthrough.assign(
@ -10651,7 +10403,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 检索结果`context`和用户输入`question`一并传给提示模板`prompt_template`。 * 检索结果`context`和用户输入`question`一并传给提示模板`prompt_template`。
* **输出**:模型根据检索到的上下文生成答案 * **输出**:模型根据检索到的上下文生成答案
``` ```python
from langchain_community.embeddings import DashScopeEmbeddings from langchain_community.embeddings import DashScopeEmbeddings
from langchain_milvus import Milvus from langchain_milvus import Milvus
from langchain_core.documents import Document from langchain_core.documents import Document
@ -10705,14 +10457,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### AI智能推荐实战之RunnableParallel并行链
#### 第3集 AI智能推荐实战之RunnableParallel并行链
**简介: AI智能推荐实战之RunnableParallel并行链**
* `RunnableParallel` 介绍 * `RunnableParallel` 介绍
@ -10728,7 +10473,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 在 LCEL 链上,会将字典隐形转换为`RunnableParallel` * 在 LCEL 链上,会将字典隐形转换为`RunnableParallel`
``` ```python
multi_retrieval_chain = ( multi_retrieval_chain = (
RunnableParallel({ RunnableParallel({
"context1": retriever1, #数据源一 "context1": retriever1, #数据源一
@ -10759,11 +10504,11 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
| **并行执行** | 所有子Runnable同时运行 | 3个任务耗时2秒(而非累加) | | **并行执行** | 所有子Runnable同时运行 | 3个任务耗时2秒(而非累加) |
| **类型安全** | 强制校验输入输出类型 | 自动检测字典字段类型 | | **类型安全** | 强制校验输入输出类型 | 自动检测字典字段类型 |
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/1-2901569.png" alt="1" style="zoom:50%;" /> <img src="./img/1-2901569.png" alt="1" style="zoom:50%;" />
* API 与用法, 构造函数所有子链接收相同的输入 * API 与用法, 构造函数所有子链接收相同的输入
``` ```python
from langchain_core.runnables import RunnableParallel from langchain_core.runnables import RunnableParallel
runnable = RunnableParallel( runnable = RunnableParallel(
@ -10794,7 +10539,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 多模型对比系统 * 多模型对比系统
``` ```python
model_comparison = RunnableParallel({ model_comparison = RunnableParallel({
"gpt4": gpt4_chain, "gpt4": gpt4_chain,
"claude": claude_chain, "claude": claude_chain,
@ -10804,7 +10549,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 智能文档处理系统 * 智能文档处理系统
``` ```python
document_analyzer = RunnableParallel({ document_analyzer = RunnableParallel({
"summary": summary_chain, # 摘要生成 "summary": summary_chain, # 摘要生成
"toc": toc_generator, # 目录提取 "toc": toc_generator, # 目录提取
@ -10821,7 +10566,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 场景:并行生成景点与书籍推荐 * 场景:并行生成景点与书籍推荐
``` ```python
from langchain_core.runnables import RunnableParallel from langchain_core.runnables import RunnableParallel
from langchain_core.prompts import ChatPromptTemplate from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
@ -10866,16 +10611,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### RunnableLambda介绍和包装链式函数实战
#### 第4集 RunnableLambda介绍和包装链式函数实战
**简介: RunnableLambda介绍和包装链式函数实战**
* `RunnableLambda` * `RunnableLambda`
@ -10908,7 +10644,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* API 与用法 * API 与用法
``` ```python
from langchain_core.runnables import RunnableLambda from langchain_core.runnables import RunnableLambda
def log_input(x): def log_input(x):
@ -10922,7 +10658,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 基础文本处理链 * 基础文本处理链
``` ```python
from langchain_core.runnables import RunnableLambda from langchain_core.runnables import RunnableLambda
text_clean_chain = ( text_clean_chain = (
@ -10937,7 +10673,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 打印中间结果并过滤敏感词(在链中插入自定义处理逻辑) * 打印中间结果并过滤敏感词(在链中插入自定义处理逻辑)
``` ```python
from langchain_core.runnables import RunnableLambda from langchain_core.runnables import RunnableLambda
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
def filter_content(text: str) -> str: def filter_content(text: str) -> str:
@ -10962,22 +10698,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
``` ```
#### 智能客服路由实战之RunnableBranch条件分支
#### 第5集 智能客服路由实战之RunnableBranch条件分支
**简介: 智能客服路由实战之RunnableBranch条件分支**
* `RunnableBranch` * `RunnableBranch`
@ -10985,7 +10706,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* API 与用法 * API 与用法
``` ```python
from langchain_core.runnables import RunnableBranch from langchain_core.runnables import RunnableBranch
#条件函数:接收输入,返回布尔值。 #条件函数:接收输入,返回布尔值。
@ -11007,7 +10728,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
""" """
``` ```
<img src="D:/小滴课堂AI/AI智能化云盘/笔记/img/3-2907855.png" alt="3" style="zoom:50%;" /> <img src="./img/3-2907855.png" alt="3" style="zoom:50%;" />
* 适合场景: * 适合场景:
@ -11028,7 +10749,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 智能路由系统(根据输入类型路由处理方式) * 智能路由系统(根据输入类型路由处理方式)
``` ```python
# 定义分类函数 # 定义分类函数
def detect_topic(input_text): def detect_topic(input_text):
if "天气" in input_text: if "天气" in input_text:
@ -11063,7 +10784,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 导入依赖 * 导入依赖
``` ```python
from langchain_core.runnables import RunnableBranch, RunnableLambda from langchain_core.runnables import RunnableBranch, RunnableLambda
from langchain_core.prompts import ChatPromptTemplate from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI
@ -11072,7 +10793,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 定义模型 * 定义模型
``` ```python
#定义模型 #定义模型
model = ChatOpenAI( model = ChatOpenAI(
model_name = "qwen-plus", model_name = "qwen-plus",
@ -11084,7 +10805,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 定义子链 * 定义子链
``` ```python
# 技术支持链 # 技术支持链
tech_prompt = ChatPromptTemplate.from_template( tech_prompt = ChatPromptTemplate.from_template(
"你是一名技术支持专家,请回答以下技术问题:{input}" "你是一名技术支持专家,请回答以下技术问题:{input}"
@ -11106,7 +10827,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 定义路由条件函数 * 定义路由条件函数
``` ```python
def is_tech_question(input: dict) -> bool: def is_tech_question(input: dict) -> bool:
# 获取 "input" 键对应的值 # 获取 "input" 键对应的值
input_value = input.get("input", "") input_value = input.get("input", "")
@ -11122,7 +10843,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 构建 RunnableBranch * 构建 RunnableBranch
``` ```python
branch = RunnableBranch( branch = RunnableBranch(
(is_tech_question, tech_chain), # 技术问题 → tech_chain (is_tech_question, tech_chain), # 技术问题 → tech_chain
(is_billing_question, billing_chain), # 账单问题 → billing_chain (is_billing_question, billing_chain), # 账单问题 → billing_chain
@ -11134,7 +10855,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
* 测试案例 * 测试案例
``` ```python
# 测试技术问题 # 测试技术问题
tech_response = full_chain.invoke("我的账号登录失败,提示技术故障") tech_response = full_chain.invoke("我的账号登录失败,提示技术故障")
print("技术问题响应:", tech_response) print("技术问题响应:", tech_response)
@ -11169,7 +10890,7 @@ public JsonData list(@RequestParam(value = "parent_id")Long parentId){
- 添加日志中间件(通过 `RunnableLambda`)记录路由决策过程 - 添加日志中间件(通过 `RunnableLambda`)记录路由决策过程
``` ```python
def log_decision(input_data): def log_decision(input_data):
print(f"路由检查输入:{input_data}") print(f"路由检查输入:{input_data}")
return input_data return input_data

BIN
img/0-2288864.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

BIN
img/0.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

BIN
img/1-1073680.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
img/1-1579900.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
img/1-1859494.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

BIN
img/1-2537508.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
img/1-2540349.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
img/1-2885071.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
img/1-2901569.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

BIN
img/1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
img/2-1580890.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB

BIN
img/2-2287117.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
img/2-2540359.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
img/2-2902256.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

BIN
img/2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

BIN
img/3-2540810.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

BIN
img/3-2907855.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

BIN
img/4.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
img/collection-explained.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB

BIN
img/export_4232z.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
img/export_a9yct.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 KiB

BIN
img/export_j1u9v.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
img/export_qtyb85.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

BIN
img/image-20250301140503525.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
img/image-20250301140529990.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

BIN
img/image-20250301140650448.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
img/image-20250301141529448.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

BIN
img/image-20250301152117731.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

BIN
img/image-20250313142026018.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
img/image-20250313151603856.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
img/image-20250313151657094.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

BIN
img/image-20250313151724171.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
img/image-20250313151918579.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

BIN
img/image-20250313161943645.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
img/image-20250313162742811.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

BIN
img/image-20250313162827278.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
img/image-20250313164754696.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

BIN
img/image-20250313170520819.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
img/image-20250313170904153.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
img/image-20250313210027704.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

BIN
img/image-20250313212722723.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB

BIN
img/image-20250313215608473.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 KiB

BIN
img/image-20250314122237372.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 KiB

BIN
img/image-20250315152627015.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
img/image-20250318151846918.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
img/image-20250318155633751.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 KiB

BIN
img/image-20250318190605311.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 765 KiB

BIN
img/image-20250318201255473.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

BIN
img/milvus-adopters.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Loading…
Cancel
Save