2026年7月2日 周四晚上19:30,报名腾讯会议了解“如何构建自进化的动态知识库(Brain)”(限30人)
免费POC, 零成本试错
FDE知识库

FDE知识库

学习大模型的前沿技术与行业落地应用


收藏

小而精:llmware如何用小型模型构建企业级RAG管道!

发布日期:2024-06-18 08:37:21 浏览次数: 3050
作者:Halo咯咯

微信搜一搜,关注“Halo咯咯”

01
概述
llmware提供了一个统一框架,用于构建基于大型语言模型(LLM)的应用(例如,RAG,代理),这些应用使用小型、专业化的模型,可以私有部署,安全地与企业知识源集成,并以成本效益的方式为任何业务流程进行调整和适应。
llmware有两个主要组成部分:
  • RAG管道 - 集成组件,用于连接知识源到生成性AI模型的全生命周期;以及
  • 50多个小型、专业化模型,为关键的企业流程自动化任务进行了微调,包括基于事实的问题回答、分类、摘要和提取。
通过结合这两个组件,以及集成领先的开源模型和底层技术,llmware提供了一套全面的工具,可以快速构建基于知识的企业级LLM应用。


LLMWare 推出了一系列新的 SLIM(结构化语言指令模型),彻底改变了企业利用人工智能处理复杂工作流程的方式。这些模型经过定制,可生成结构化数据输出,从而实现无缝自动化以及与现有系统的集成。与其他人工智能模型不同,SLIM 被设计为在仅 CPU 的计算机上运行,使硬件资源有限的企业可以使用它们。这些模型的开源性质允许定制并避免昂贵的许可费用,从而实现先进人工智能技术的民主化。 
LLMWare 的 SLIM 解决了常见的人工智能采用障碍,例如多步骤任务协调的需要、清晰的数据输出和数据安全问题。通过提供全面的解决方案,LLMWare 使企业能够释放人工智能的全部潜力,将其后台运营转变为效率中心。
02
特性
使用llmware编写代码基于几个主要概念:
Model Catalog:无论底层实现如何,都可以通过简单的查找以相同的方式访问所有模型。 
Library:大规模摄取、组织和索引知识集合 - 解析、文本块和嵌入。 
Query:使用文本、语义、混合、元数据和自定义过滤器的组合查询库。 
Prompt with Sources:将知识检索与LLM推理结合的最简单方式。
RAG-Optimized Models为RAG工作流集成和本地运行而设计的1-7B参数RAG优化模型。 
Simple-to-Scale Database Options:从笔记本电脑到并行集群的集成数据存储。 
? 具有函数调用和SLIM模型的代理 

from llmware.agents import LLMfx
text = ("Tesla stock fell 8% in premarket trading after reporting fourth-quarter revenue and profit that ""missed analysts’ estimates. The electric vehicle company also warned that vehicle volume growth in ""2024 'may be notably lower' than last year’s growth rate. Automotive revenue, meanwhile, increased ""just 1% from a year earlier, partly because the EVs were selling for less than they had in the past. ""Tesla implemented steep price cuts in the second half of the year around the world. In a Wednesday ""presentation, the company warned investors that it’s 'currently between two major growth waves.'")
# create an agent using LLMfx classagent = LLMfx()
# load text to processagent.load_work(text)
# load 'models' as 'tools' to be used in analysis processagent.load_tool("sentiment")agent.load_tool("extract")agent.load_tool("topics")agent.load_tool("boolean")
# run function calls using different toolsagent.sentiment()agent.topics()agent.extract(params=["company"])agent.extract(params=["automotive revenue growth"])agent.xsum()agent.boolean(params=["is 2024 growth expected to be strong? (explain)"])
# at end of processing, show the report that was automatically aggregated by keyreport = agent.show_report()
# displays a summary of the activity in the processactivity_summary = agent.activity_summary()
# list of the responses gatheredfor i, entries in enumerate(agent.response_list):print("update: response analysis: ", i, entries)
output = {"report": report, "activity_summary": activity_summary, "journal": agent.journal}

? ? 开始编码 - RAG快速入门 ?
# This example illustrates a simple contract analysis# using a RAG-optimized LLM running locally
import osimport refrom llmware.prompts import Prompt, HumanInTheLoopfrom llmware.setup import Setupfrom llmware.configs import LLMWareConfig
def contract_analysis_on_laptop (model_name):
#In this scenario, we will:#-- download a set of sample contract files#-- create a Prompt and load a BLING LLM model#-- parse each contract, extract the relevant passages, and pass questions to a local LLM
#Main loop - Iterate thru each contract:##1.parse the document in memory (convert from PDF file into text chunks with metadata)#2.filter the parsed text chunks with a "topic" (e.g., "governing law") to extract relevant passages#3.package and assemble the text chunks into a model-ready context#4.ask three key questions for each contract to the LLM#5.print to the screen#6.save the results in both json and csv for furthe processing and review.
#Load the llmware sample files
print (f"\n > Loading the llmware sample files...")
sample_files_path = Setup().load_sample_files()contracts_path = os.path.join(sample_files_path,"Agreements")
#Query list - these are the 3 main topics and questions that we would like the LLM to analyze for each contract
query_list = {"executive employment agreement": "What are the name of the two parties?","base salary": "What is the executive's base salary?","vacation": "How many vacation days will the executive receive?"}
#Load the selected model by name that was passed into the function
print (f"\n > Loading model {model_name}...")
prompter = Prompt().load_model(model_name, temperature=0.0, sample=False)
#Main loop
for i, contract in enumerate(os.listdir(contracts_path)):
# excluding Mac file artifact (annoying, but fact of life in demos)if contract != ".DS_Store":
print("\nAnalyzing contract: ", str(i+1), contract)
print("LLM Responses:")
for key, value in query_list.items():
# step 1 + 2 + 3 above - contract is parsed, text-chunked, filtered by topic key,# ... and then packaged into the prompt
source = prompter.add_source_document(contracts_path, contract, query=key)
# step 4 above - calling the LLM with 'source' information already packaged into the prompt
responses = prompter.prompt_with_source(value, prompt_name="default_with_context")
# step 5 above - print out to screen
for r, response in enumerate(responses):print(key, ":", re.sub("[\n]"," ", response["llm_response"]).strip())
# We're done with this contract, clear the source from the promptprompter.clear_source_materials()
# step 6 above - saving the analysis to jsonl and csv
# Save jsonl report to jsonl to /prompt_history folderprint("\nPrompt state saved at: ", os.path.join(LLMWareConfig.get_prompt_path(),prompter.prompt_id))prompter.save_state()
# Save csv report that includes the model, response, prompt, and evidence for human-in-the-loop reviewcsv_output = HumanInTheLoop(prompter).export_current_interaction_to_csv()print("csv output saved at:", csv_output)

if __name__ == "__main__":
# use local cpu model - try the newest - RAG finetune of Phi-3 quantized and packaged in GGUFmodel = "bling-phi-3-gguf"
contract_analysis_on_laptop(model)

03
数据存储选项

快速启动:使用SQLite3和ChromaDB(基于文件)即可开箱即用 - 不需要安装 
from llmware.configs import LLMWareConfig LLMWareConfig().set_active_db("sqlite") LLMWareConfig().set_vector_db("chromadb")

速度 + 规模:使用MongoDB(文本集合)和Milvus(向量数据库) :通过Docker Compose安装 
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose.yamldocker compose up -d

from llmware.configs import LLMWareConfigLLMWareConfig().set_active_db("mongo")LLMWareConfig().set_vector_db("milvus")

Postgres:使用Postgres同时作为文本集合和向量数据库 - 通过Docker Compose安装 
curl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose-pgvector.yamldocker compose up -d

from llmware.configs import LLMWareConfigLLMWareConfig().set_active_db("postgres")LLMWareConfig().set_vector_db("postgres")
混合搭配:LLMWare支持3种文本集合数据库(Mongo, Postgres, SQLite)和10种向量数据库(Milvus, PGVector-Postgres, Neo4j, Redis, Mongo-Atlas, Qdrant, Faiss, LanceDB, ChromaDB和Pinecone)
# scripts to deploy other optionscurl -o docker-compose.yaml https://raw.githubusercontent.com/llmware-ai/llmware/main/docker-compose-redis-stack.yaml





53AI,企业落地大模型首选服务商

产品:场景落地咨询+大模型应用平台+行业解决方案

承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

添加专属顾问

回到顶部

加载中...

扫码咨询

扫码登录
登录即表示您同意《53AI网站服务协议》
服务协议

欢迎您使用【53AI 官方网站】(以下简称“本网站”或“我们”)。本《会员服务协议》(以下简称“本协议”)是您(以下简称“会员”或“用户”)与【深圳市博思协创网络科技有限公司】之间关于注册、登录及使用本网站会员服务所订立的法律协议。

在您注册或登录前,请务必审慎阅读、充分理解各条款内容,特别是免除或限制责任的条款、知识产权条款、争议解决条款等。此类条款将以加粗形式提示您注意。 当您通过微信公众号授权、手机验证码验证或其他方式成功登录本网站时,即视为您已完全理解并同意接受本协议的全部内容。

一、 定义

本网站:指由【深圳市博思协创网络科技有限公司】运营的,域名为【53ai.com】的网站及相关移动端页面。

会员服务:指本网站向注册会员提供的知识库文章查阅、内容检索及其他相关增值服务。

知识库内容:指本网站发布的包括但不限于文字、图表、数据、研究报告、行业分析等数字化内容资源。

二、 账号注册与登录

登录方式:本网站支持以下登录方式,您可根据实际情况选择:

微信公众号授权登录:您同意将您的微信OpenID信息授权给本网站,用于创建或关联会员账号。

手机验证码登录:您需提供真实有效的手机号码,并通过短信验证码完成身份验证与登录/注册。

账号安全:您的账号仅限您本人使用,禁止赠与、借用、租用、转让或售卖。因您保管不善导致的账号被盗、密码泄露等损失,由您自行承担。

实名认证:根据相关法律法规要求,我们可能要求您在特定功能下完成实名认证。如您拒绝提供,可能无法使用部分或全部服务。

未成年人保护:若您未满18周岁,请在法定监护人的陪同下阅读本协议,并在征得监护人同意后使用本服务。

三、 服务内容与规范

知识库查阅权限:会员登录后,有权按照其会员等级对应的权限范围,在线浏览、检索本网站知识库中的相关文章及内容。

服务变更:我们有权根据业务发展需要,调整、变更或终止部分服务内容,并将以网站公告、公众号消息等方式提前通知。

禁止行为:您在使用服务时不得实施以下行为:

利用技术手段批量爬取、下载、转存知识库内容;

将知识库内容用于商业目的或未经授权地向第三方传播;

干扰本网站正常运行或侵犯其他用户合法权益;

发布违法违规信息或从事违反公序良俗的活动。

四、 知识产权声明

权利归属:本网站知识库中的排版设计、软件代码等内容的知识产权均归【公司全称】或原权利人所有,受《中华人民共和国著作权法》等法律保护。

有限许可:本网站授予会员一项非独占、不可转让、不可转授权的普通许可,仅限于个人学习、研究之目的在线查阅知识库内容。

侵权追责:未经书面许可,任何单位或个人不得以任何形式复制、转载、摘编、镜像、汇编或以其他方式使用上述内容。一经发现,我们保留追究其法律责任的权利。

五、 个人信息保护

我们重视对您个人信息的保护。关于我们如何收集、使用、存储和保护您的个人信息,请单独阅读 《隐私政策》。

您通过微信公众号授权或手机号验证所提供的信息,我们将严格按照《个人信息保护法》的规定处理,仅用于身份识别、服务提供及安全验证等必要用途。

您可以随时通过网站设置或联系客服行使查阅、更正、删除个人信息及撤回授权同意的权利。

六、 免责声明

内容准确性:知识库内容仅供参考,不构成专业建议。我们不对其完整性、准确性、时效性作任何明示或暗示的保证,您应自行判断并承担使用风险。

不可抗力:因自然灾害、政策法规变化、网络故障、第三方平台接口异常(如微信接口维护、运营商短信通道故障)等不可抗力导致的服务中断或延迟,我们不承担违约责任。

第三方链接:本网站可能包含指向第三方网站的链接,该等网站的内容和服务不受我们控制,请您自行甄别风险。

七、 违约责任

如您违反本协议约定,我们有权视情节采取警告、限制功能、暂停服务、注销账号等措施,并保留要求赔偿损失的权利。

如因您的违约行为导致我们遭受行政处罚、第三方索赔或商誉损失,您应承担全部赔偿责任(包括但不限于罚款、赔偿金、律师费、公证费等)。

八、 法律适用与争议解决

本协议的订立、执行和解释均适用中华人民共和国大陆地区法律。

因本协议产生的或与本协议有关的任何争议,双方应友好协商解决;协商不成的,任何一方均可向【公司所在地】有管辖权的人民法院提起诉讼。

九、 其他

本协议构成双方就本服务达成的完整协议,取代此前任何口头或书面约定。

本协议任一条款被认定为无效或不可执行的,不影响其他条款的效力。

我们对本协议享有最终解释权,并在法律允许的范围内保留随时修改的权利。修改后的协议一经公布即生效,继续使用服务即视为同意修订内容。


已查阅