llmware有两个主要组件:•RAG Pipeline- 用于将知识源连接到生成式 AI 模型的整个生命周期的集成组件;和
•50+ 小型专用模型,针对企业流程自动化中的关键任务进行了微调,包括基于事实的问答、分类、总结和提取。
•Model Catalog
•RAG Optimized Models
•Agents
•SLIM Models
•Embedding Models
•Library
•Query
•Data Stores
•Prompt with Sources
•Vector Databases
•Agent Inference Server
•GGUF
通过这些组件可以实现我们 RAG 应用中的所有功能。下面简单介绍一下。
通过轻松查找以相同的方式访问所有模型,而不管底层实现如何。
•目录中的 150+ 型号,包括 50+RAG 优化模型
•18 个用于 Agent 用例的 SLIM函数调用小语言模型
•完全支持 GGUF、HuggingFace、Sentence Transformers 和基于 API 的主要模型
•易于扩展以添加自定义模型
fromllmware.modelsimportModelCatalog
fromllmware.promptsimportPrompt
#allmodelsaccessedthroughtheModelCatalog
models=ModelCatalog().list_all_models()
#touseanymodelintheModelCatalog-"load_model"methodandpassthemodel_nameparameter
my_model=ModelCatalog().load_model("llmware/bling-phi-3-gguf")
output=my_model.inference("whatisthefutureofAI?",add_context="Hereisthearticletoread")
#tointegratemodelintoaPrompt
prompter=Prompt().load_model("llmware/bling-tiny-llama-v0")
response=prompter.prompt_main("whatisthefutureofAI?",context="InsertSourcesofinformation")1-7B 参数的 RAG 优化模型,专为 RAG 工作流集成而设计,可在本地流畅运行。
•SLIM 系列:针对函数调用和多步骤、多模型代理工作流程进行微调的小型专用模型。
•DRAGON 系列:生产级 RAG 优化的 6-7B 参数模型。
•BLING 系列:基于CPU的小型 RAG 优化、遵循指令的 1B-3B 参数模型。
•行业 BERT 模型:开箱即用的自定义训练句子转换器嵌入模型,针对以下行业进行了微调:保险、合同、资产管理、SEC。
•GGUF 量化:提供许多 SLIM、DRAGON 和 BLING 模型的“gguf”和“工具”版本,并针对 CPU 部署进行了优化。
llmware 旨在使用专为本地和私有部署而设计的小型语言模型实现基于 Agent 和 LLM 的函数调用, 并能够利用开源模型来执行复杂的 RAG 和基于知识的工作流程自动化。
llmware 中的关键元素:
•SLIM 模型- 18 个函数调用小语言模型,针对特定的提取、分类、生成或摘要活动进行了优化,并生成 python 词典和列表作为输出。
•LLMfx 类- 支持各种基于代理的流程。
llmware 在默认 ModelCatalog 中支持 30+ 开箱即用的嵌入模型, 并且可以轻松扩展以从 HuggingFace 或 Sentence Transformers 添加其他流行的开源嵌入模型。
要获取当前支持的嵌入模型的列表,请执行以下操作:
fromllmware.modelsimportModelCatalog
embedding_models=ModelCatalog().list_embedding_models()
fori,modelsinenumerate(embedding_models):
print(f"embeddingmodels:{i}-{models}")支持的热门模型包括:
•Sentence Transformers-all-MiniLM-L6-v2,all-mpnet-base-v2
•Jina AI-jinaai/jina-embeddings-v2-base-en,jinaai/jina-embeddings-v2-small-en
•Nomic-nomic-ai/nomic-embed-text-v1
•Industry BERT-industry-bert-insurance,industry-bert-contracts,industry-bert-asset-management,industry-bert-sec,industry-bert-loans
•OpenAI-text-embedding-ada-002,text-embedding-3-small,text-embedding-3-large
llmware 中的嵌入模型可以直接由 安装,但在大多数情况下, 在创建新嵌入时,嵌入模型的名称将传递给 Library 类中的处理程序。 一旦完成,嵌入模型将作为该库的嵌入记录的一部分捕获到 LibraryCard 上的 Library 元数据中, 因此,通常不需要再次显式使用,例如,
fromllmware.libraryimportLibrary
library=Library().create_new_library("my_library")
#parsesthecontentfromthedocumentsinthefilepath,textchunksandindexesinatextcollectiondatabase
library.add_files(input_folder_path="/local/path/to/my_files",chunk_size=400,max_chunk_size=600,smart_chunking=1)
#createsembeddings-andkeepssynchronizedrecordsofwhichtextchunkshavebeenembeddedtoenableincrementaluse
library.install_new_embedding(embedding_model_name="jinaai/jina-embeddings-v2-small-en",
vector_db="milvus",
batch_size=100)Library 是 LLMWare 中非结构化信息的主要组织结构。 用户可以创建一个包含所有类型不同内容的大型库, 也可以创建多个库,每个库都包含有关特定主题、项目/案例/交易,甚至不同帐户/用户/部门的特定逻辑信息集合。
每个库都由以下组件组成:
1.数据库上的集合- 这是库的核心,通过解析文档创建,然后在文本集合数据库中自动分块和索引。这是检索的基础,也是将用作跟踪可附加到库集合的任意数量的向量嵌入的基础的集合。
2.文件存档- 位于llmware_data路径中,在 帐户 中,每个库都有一个文件夹结构。库的所有基于文件的工件都组织在这些文件夹中,包括库中添加的所有文件的副本(对于基于检索的应用程序非常有用)、从源文档中提取和索引的图像,以及派生的工件,例如 nlp 和知识图谱和数据集。
3.Library Catalog- 每个 Library 都在LibraryCatalog表中注册,并具有唯一的library_card,其中包含 Library 的关键属性和统计信息。
当 Library 对象传递给解析器时,解析器会自动将所有信息路由到 Library 结构中。
该库还提供了方便的方法,可以轻松地在库上安装嵌入,包括跟踪增量进度。
要解析为 Library,有非常有用的便捷方法add_files,它将调用 Parser, 整理和路由所选文件夹路径中的文件,检查重复文件,执行解析,文本分块和插入数据库,并自动更新所有 Library 状态。
库是执行 Query 时使用的主要索引结构。在构造 Query 对象时传递 library 对象, 然后将仅针对该 Library 中的内容执行所有检索(文本、语义和混合)。
检索和查询是混合了文本、语义、混合、元数据和自定义筛选器的查询库。
retrieval.py模块实现该类,这是执行搜索和检索的主要方式。 每个对象在构造时都需要在构造函数中将Library作为必需参数传递。Query对象将针对该 Library 进行操作,并可以访问 Library 的所有特定属性、元数据和方法。
llmware 中的检索利用库抽象作为执行特定查询或检索的主要单元。这提供了拥有多个不同知识库的能力, 这些知识库可能与不同的用例和/或用户、账户和权限保持一致。
#step1-loadapreviouslycreatedlibrary
lib=Library().load_library("my_library")
#step2-createaqueryobject
q=Query(lib)
#step3-runlotsofdifferentqueries(manyotheroptionsintheexamples)
#basictextquery
results1=q.text_query("textquery",result_count=20,exact_mode=False)
#semanticquery
results2=q.semantic_query("semanticquery",result_count=10)数据存储易于扩展的数据库选项 - 可以实现从笔记本电脑到并行集群的集成数据存储。
支持了市面上常见的向量库:
fromllmware.configsimportLLMWareConfig
#tosetthecollectiondatabase-mongo,sqlite,postgres
LLMWareConfig().set_active_db("mongo")
#tosetthevectordatabase(ordeclarewheninstalling)
#--options:milvus,pg_vector(postgres),redis,qdrant,faiss,pinecone,mongoatlas
LLMWareConfig().set_vector_db("milvus")
#forfaststart-noinstallationsrequired
LLMWareConfig().set_active_db("sqlite")
LLMWareConfig().set_vector_db("chromadb")#tryalsofaissandlancedb
#forsinglepostgresdeployment
LLMWareConfig().set_active_db("postgres")
LLMWareConfig().set_vector_db("postgres")Prompt with Sources:将知识检索与 LLM 推理相结合的最简单方法,并提供了几种高级有用的方法, 可以轻松地将检索/查询/解析步骤集成到 Prompt 中,以用作在模型上运行推理的来源。
fromllmware.promptsimportPrompt
#buildapromptandattachamodel
prompter=Prompt().load_model("llmware/bling-tiny-llama-v0")
#add_source_documentmethod:acceptsanysupporteddocumenttype,parsesthefile,andcreatestextchunks
#ifaqueryispassed,thenitwillrunaquickin-memoryfilteringsearchagainstthetextchunks
#thetextchunksarepackagedintosourceswithalloftheaccompanyingmetadatafromthefile,andmade
#availableautomaticallyinbatchestobeusedinprompting-
source=prompter.add_source_document("/folder/to/one/doc/","filename",query="fastquery")
#toruninferencewith'promptwithsources'->sourcewillbeautomaticallyaddedtotheprompt
responses=prompter.prompt_with_source("myquery")
#dependinguponthesizeofthesource(andbatchingrelativetothemodelcontextwindow,theremaybemorethan
#asingleinferencerun,sounpackpotentiallymultipleresponses
fori,responseinenumerate(responses):
print("response:",i,response)在本文中,我们简单介绍了 llmware 的基本概念和功能, 这些功能模块涉及到了我们编写 AI 应用程序的核心模块,后面我们一起看下怎么使用 llmware 来实现人工智能应用。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |