
txtai集成语义搜索、LLM 编排与语言模型工作流的 All-in-One AI 框架实战指南【免费下载链接】txtai All-in-one AI framework for semantic search, LLM orchestration and language model workflows项目地址: https://gitcode.com/GitHub_Trending/tx/txtaitxtai 是一个开源的一站式AI 框架将语义搜索semantic search、大语言模型编排LLM orchestration与语言模型工作流language model workflows整合在同一套 API 与配置体系中。本指南基于仓库 README.md 及配套文档与源码带你理解 txtai 的核心设计——以 embeddings 数据库为底座快速构建语义搜索应用、RAG 问答、自主 Agent 与多模型流水线并掌握从 pip 安装、YAML 配置到生产部署的完整链路。一、核心架构一切从 embeddings 数据库开始txtai 的关键组件是一个embeddings 数据库它是三类存储的统一体见 README.md 的定位描述向量索引Vector Indexes包括稠密向量dense如 Sentence Transformers 类模型与稀疏向量sparse如 BM25、SIF用于相似度检索图网络Graph Networks用于主题建模、数据连通性分析与网络分析关系数据库Relational Databases用于存储文档内容、元数据并支持 SQL 过滤。这一底座既可以直接支撑向量搜索也可以作为大语言模型LLM应用的知识源——语义搜索结果被当作上下文喂给 LLM就构成了 RAG再叠加工具调用能力就升级为自主 Agent。在源码层面顶层入口 src/python/txtai/init.py 暴露了五个核心类Embeddings、Application、Agent、LLM/RAG/Textractor与Workflow与 README 的功能地图一一对应顶层 API对应能力txtai.Embeddings语义搜索、向量索引与查询txtai.Application配置驱动的应用YAML APItxtai.Agent自主 Agent连接工具求解复杂问题txtai.LLM/txtai.RAG大模型生成与检索增强生成txtai.Workflow语言模型工作流 / 语义流水线二、为什么选择 txtai面对每天涌现的向量数据库与 LLM 框架txtai 的差异化优势体现在见 README.md 的 Why txtai? 一节几分钟即可跑通通过 pip 或 Docker 安装几行代码即可建立索引并完成语义搜索# Get started in a couple lines import txtai embeddings txtai.Embeddings() embeddings.index([Correct, Not what we hoped]) embeddings.search(positive, 1) # [(0, 0.29862046241760254)]内置 Web API以你熟悉的编程语言开发应用。先写一个app.yml配置文件# app.yml embeddings: path: sentence-transformers/all-MiniLM-L6-v2再启动服务并发起查询CONFIGapp.yml uvicorn txtai.api:app curl -X GET http://localhost:8000/search?querypositive本地运行数据无需上传到远程服务满足数据安全与离线需求模型跨度大从微模型micromodels一路支持到大型语言模型LLMs低占用按需安装额外依赖、按需扩容示例丰富仓库 examples 目录提供了超过 70 个示例 Notebook 与可运行脚本覆盖全部功能。三、核心使用场景一语义搜索语义搜索是 txtai 最基础也最成熟的能力。传统搜索依赖关键词匹配而语义搜索理解自然语言能返回语义相同但关键词不同的结果。README 中给出了场景总览而 docs/embeddings/index.md 提供了完整的构建与检索示例。3.1 构建索引from txtai import Embeddings # 指定向量模型不指定时使用默认的 all-MiniLM-L6-v2 embeddings Embeddings(pathsentence-transformers/nli-mpnet-base-v2) data [ US tops 5 million confirmed virus cases, Canadas last fully intact ice shelf has suddenly collapsed, forming a Manhattan-sized iceberg, Beijing mobilises invasion craft along coast as Taiwan tensions escalate, The National Park Service warns against sacrificing slower friends in a bear attack, Maine man wins $1M from $25 lottery ticket, Make huge profits without work, earn up to $100,000 a day ] embeddings.index(data)index方法接受可迭代对象支持三种元素格式见 docs/embeddings/index.md 的 Index 一节格式说明(id, data, tags)默认格式id唯一记录 IDdata为待索引数据文本、字典或对象tags为可选的标签字符串(id, data)同上但不含 tagsdata仅单个元素系统自动生成唯一 ID此时 upsert/delete 需先搜索定位 ID当data为字典时文本通过text键传入、二进制对象通过object键传入若要存储元数据需开启 content存储二进制对象需开启objects。输入既可以是列表也可以是生成器生成器能让超大数据集在任意时刻只有部分数据驻留内存。3.2 语义检索for query in (feel good story, climate change, public health story, war, wildlife, asia, lucky, dishonest junk): uid embeddings.search(query, 1)[0][0] print(f{query:20} {data[uid]})search(query, limit)的返回格式取决于是否存储 content未存储 content返回(id, score)列表存储 content返回{**查询列}字典列表。同时支持自然语言查询与 SQL 查询详见 docs/embeddings/query.md。3.3 资源管理上下文管理器Embeddings 数据库是上下文管理器块结束时自动释放资源见 docs/embeddings/index.md 的 Resource management 一节# 创建新数据库、索引并保存 with Embeddings() as embeddings: embeddings.index(rows) embeddings.save(path) # 加载已保存的数据库并搜索 with Embeddings().load(path) as embeddings: embeddings.search(query)尽管不调用close也能依赖垃圾回收但尽早释放数据库连接等共享资源仍是推荐做法。3.4 入门示例README 推荐的语义搜索入门 Notebook 如下均位于 examples 目录Notebook说明01_Introducing_txtai.ipynbtxtai 功能全景概览13_Similarity_search_with_images.ipynb将图像与文本嵌入同一空间进行检索34_Build_a_QA_database.ipynb用语义搜索做问题匹配QA 数据库38_Introducing_the_Semantic_Graph.ipynb探索主题、数据连通性并做网络分析四、核心使用场景二LLM 编排LLM 编排覆盖自主 Agent、RAG检索增强生成、与你的数据对话以及各类与 LLM 交互的流水线。这是 txtai 当前迭代最活跃的方向。4.1 Agents自主求解复杂问题Agent 能自动创建工作流来回答多层面的用户请求它迭代式地提示模型、调用工具最终得出答案见 docs/agent/index.md。txtai Agent 构建在 smolagents 框架之上支持 txtai 支持的全部 LLMHugging Face、llama.cpp、以及通过 LiteLLM 接入的 OpenAI / Claude / AWS Bedrock同时支持agents.md与skill.md提示规范。一个基础 Agent 示例来自 docs/agent/index.mdfrom datetime import datetime from txtai import Agent wikipedia { name: wikipedia, description: Searches a Wikipedia database, provider: huggingface-hub, container: neuml/txtai-wikipedia } arxiv { name: arxiv, description: Searches a database of scientific papers, provider: huggingface-hub, container: neuml/txtai-arxiv } def today() - str: Gets the current date and time Returns: current date and time return datetime.today().isoformat() agent Agent( modelQwen/Qwen3-4B-Instruct-2507, tools[today, wikipedia, arxiv, websearch], max_steps10, )上述 Agent 拥有两个 embeddings 数据库Wikipedia、ArXiv与 Web 搜索工具由模型自行决定调用哪个工具。比如查询Which city has the highest population, Boston or New York?时它会先分头检索两座城市的人口再综合回答。可运行的 agent_quickstart.py 展示了完整链路定义 embeddings 数据库工具可用provider: huggingface-hubcontainer: neuml/txtai-wikipedia引用云端数据库、把任意 Python 函数如返回当前时间的today()注册为工具、组合默认工具websearch/webview最后传入 LLM 模型名创建 Agent 并提问。Agentic RAG是 Agent 与 RAG 的结合标准 RAG 只做一次向量检索Agentic RAG 则经历多轮迭代、可跨多个数据库得出结论。例如让 Agent 充当研究员搜索网站、论文与 Wikipedia 后以 Markdown 输出带引用的报告researcher Youre an expert researcher looking to write a paper on {topic}. Search for websites, scientific papers and Wikipedia related to the topic. Write a report with summaries and references (with hyperlinks). Write the text as Markdown. agent(researcher.format(topicalien life))Agent Teams多智能体协作Agent 本身也可以作为工具从而构建智能体团队。每个子 Agent 拥有各自的推理引擎整体决策更具层次性——例如用websearcher、wikiman、researcher三个专职 Agent 组成团队由主 Agent 统一调度完整代码见 docs/agent/index.md 的 Agent Teams 一节。相关入门与进阶示例Notebook / 脚本说明agent_quickstart.pyAgent 快速上手脚本69_Granting_autonomy_to_agents.ipynb让 Agent 自主迭代求解83_TxtAI_got_skills.ipynb集成 skill.md 技能文件84_Agent_Tools.ipynbtxtai Agent 工具包详解71_Analyzing_LinkedIn_Company_Posts_with_Graphs_and_Agents.ipynb图 Agent 分析社交媒体互动4.2 RAG用知识库约束 LLM 输出RAG 通过把知识库内容作为上下文注入提示词显著降低 LLM 幻觉风险常用于与你的数据对话。可运行的 rag_quickstart.py 展示了从本地文件到 RAG 问答的完整流程from txtai import Embeddings, RAG from txtai.pipeline import Textractor # Step 1: 收集本地目录文件 path data files [os.path.join(path, f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))] # Step 2: 文本抽取与分块此处为基于章节的分块 textractor Textractor(backenddocling, sectionsTrue) chunks [] for f in files: for chunk in textractor(f): chunks.append((f, chunk)) # Step 3: 构建 embeddings 数据库contentTrue 存储原文 embeddings Embeddings(contentTrue, pathQwen/Qwen3-Embedding-0.6B, maxlength2048) embeddings.index(chunks) # Step 4: 创建 RAG 流水线embeddings 数据库 LLM template Answer the following question using the provided context. Question: {question} Context: {context} rag RAG( embeddings, Qwen/Qwen3-0.6B, systemYou are a friendly assistant, templatetemplate, outputflatten, ) question Summarize the main advancements made by BERT print(rag(question, maxlength2048, stripthinkTrue))安装依赖时使用pip install txtai[pipeline-data]即可覆盖 Textractor 所需组件。RAG 进阶示例Notebook说明rag_quickstart.pyRAG 快速上手脚本52_Build_RAG_pipelines_with_txtai.ipynbRAG 完整指南含引用citation生成79_RAG_is_more_than_Vector_Search.ipynb通过 Web、SQL 等来源获取上下文77_GraphRAG_with_Wikipedia_and_GPT_OSS.ipynb图搜索驱动的深度 RAG65_Speech_to_Speech_RAG.ipynb语音到语音的完整 RAG 工作流4.3 LLM 流水线LLM 之外LLM流水线还集成了 llama.cpp 与通过 LiteLLM 接入的托管 API 模型。一个 LLM 即可提示完成总结、翻译、分类等众多任务而RAG流水线则把 embeddings 数据库与 LLM 组合为检索增强生成单元相关实现位于 src/python/txtai/pipeline/llm 目录。五、核心使用场景三语言模型工作流语言模型工作流也称语义工作流把多个语言模型连接起来构建智能应用详见 docs/workflow/index.md。虽然 LLM 很强大但抽取式问答、自动摘要、语音合成、转写、翻译等任务往往有更小、更快、更专业的模型。工作流正是编排这些模型的方式。Workflow 接收一个可调用对象并返回元素以流式、批处理方式运行非常适合喂给对批大小敏感的 Transformer 流水线。5.1 最简工作流workflow Workflow([Task(lambda x: [y * 2 for y in x])]) list(workflow([1, 2, 3]))由于工作流以生成器运行必须消费输出才能触发执行有以下三种消费方式# 小数据集输出可全部放入内存 list(workflow(elements)) # 大数据集逐条处理 for output in workflow(elements): function(output) # 大数据集丢弃输出只求执行 for _ in workflow(elements): pass5.2 完整 Python 示例音频转写 → 翻译 → 索引来自 docs/workflow/index.md 的示例把一批音频文件转写成文本、翻译成法语并建立索引from txtai import Embeddings from txtai.pipeline import Transcription, Translation from txtai.workflow import FileTask, Task, Workflow embeddings Embeddings({ path: sentence-transformers/paraphrase-MiniLM-L3-v2, content: True }) transcribe Transcription() translate Translation() tasks [ FileTask(transcribe, r\.wav$), Task(lambda x: translate(x, fr)) ] data [ US_tops_5_million.wav, Canadas_last_fully.wav, Beijing_mobilises.wav, The_National_Park.wav, Maine_man_wins_1_mil.wav, Make_huge_profits.wav ] workflow Workflow(tasks) embeddings.index((uid, text, None) for uid, text in enumerate(workflow(data))) embeddings.search(wildlife, 1)5.3 YAML 配置驱动的工作流工作流同样可以用 YAML 声明式定义同上一节场景writable: true embeddings: path: sentence-transformers/paraphrase-MiniLM-L3-v2 content: true # 转写音频为文本 transcription: # 语言间翻译 translation: workflow: index: tasks: - action: transcription select: \\.wav$ task: file - action: translation args: [fr] - action: indexfrom txtai import Application app Application(workflow.yml) list(app.workflow(index, [ US_tops_5_million.wav, Canadas_last_fully.wav, Beijing_mobilises.wav, The_National_Park.wav, Maine_man_wins_1_mil.wav, Make_huge_profits.wav ])) app.search(wildlife)5.4 LLM 工作流示例工作流可以串联多个 LLM 提示任务也可以把 LLM 与任意 txtai 流水线/任务混排见 docs/workflow/index.md 的 LLM workflow examplellm: path: openai/gpt-oss-20b workflow: llm: tasks: - task: template template: | Extract keywords for the following text. {text} action: llm - task: template template: | Translate the following text into French. {text} action: llmfrom txtai import Application app Application(workflow.yml) list(app.workflow(llm, [ txtai is an open-source platform for semantic search and workflows powered by language models. ]))可运行的 workflow_quickstart.py 同时演示了两条路线一条用Textractordocling 后端抓取网页 →Summary摘要 →Translation翻译成法语的纯流水线路线另一条用同一个 Textractor LLM(Qwen/Qwen3-4B-Instruct-2507)以提示词模板完成摘要与翻译任务。工作流入门示例Notebook说明workflow_quickstart.py工作流快速上手脚本14_Run_pipeline_workflows.ipynb简单而强大的数据处理工作流09_Building_abstractive_text_summaries.ipynb抽象式文本摘要11_Transcribe_audio_to_text.ipynb音频转文本12_Translate_text_between_languages.ipynb机器翻译与语言检测六、Pipelines 与 Workflow Tasks 全景工作流的积木是各类 Pipeline详见 docs/pipeline/index.md。所有 Pipeline 都只需实现一个__call__方法既可用 Python 实例化也可在 YAML 配置中以小写名称声明由 Workflow 或 API 驱动执行。完整清单如下Audio音频AudioMixer、AudioStream、Microphone、TextToAudio、TextToSpeech、TranscriptionData Processing数据处理FileToHTML、HTMLToMarkdown、Segmentation、Tabular、Text extractionTextractor、Tokenizer、URLRetrieveImage图像Caption、Image Hash、ObjectsText文本Entity、Labeling、LLM、RAG、Reranker、Similarity、Summary、TranslationTraining训练HF ONNX、ML ONNX、Trainer所有 Pipeline 未指定模型时均加载默认模型默认设计为通过 Transformers 库在本地运行LLM与RAG额外支持 llama.cpp 与 LiteLLM 托管 API。对应实现位于 src/python/txtai/pipeline 目录各子目录audio/data/image/llm/text/train与上述类别一一对应。七、安装与部署7.1 基础安装pip install txtai要求Python 3.10官方建议使用虚拟环境venv。完整安装说明见 docs/install.md。7.2 可选依赖extras按需安装增量依赖避免一次装全详见 docs/install.md 的 Optional dependencies 一节Extra用途命令all全部依赖pip install txtai[all]ann额外 ANN 后端pip install txtai[ann]apiWeb API 服务pip install txtai[api]cloud对接云端算力pip install txtai[cloud]console命令行索引查询控制台pip install txtai[console]database额外内容存储选项pip install txtai[database]graph主题建模、数据连通性、网络分析pip install txtai[graph]model额外非标准模型pip install txtai[model]pipeline全部流水线默认安装已含大部分常用pip install txtai[pipeline]scoring额外评分方法pip install txtai[scoring]vectors额外向量方法pip install txtai[vectors]workflow全部工作流任务默认安装已含大部分常用pip install txtai[workflow]pipeline还可细分为pipeline-audio、pipeline-data、pipeline-image、pipeline-llm、pipeline-text、pipeline-train。多个 extra 可组合pip install txtai[pipeline,workflow]7.3 环境特定前置条件LinuxAudioStream/Microphone 流水线需要 PortAudio 系统库Transcription 需要 SoundFile 系统库LiteRT LLM 流水线需要 libegl1、libgles2、libvulkan1macOS旧版 Faiss 运行时依赖libompbrew install libomp音频流水线需brew install portaudioWindows可选依赖需要 C Build Tools。7.4 CPU-only 安装默认安装会引入带 GPU 支持的 PyTorch。纯 CPU 环境可按如下方式安装 CPU 版 PyTorchpip install txtai torch[version]cpu \ -f https://download.pytorch.org/whl/torch其中[version]为 PyTorch 版本号如 2.4.1。7.5 其他安装方式源码安装获取最新未发布特性pip install githttps://github.com/neuml/txtai追加#eggtxtai[extra名]可安装对应 extrasCondaconda-forge 社区维护conda install -c conda-forge txtai最小化安装零依赖轻量包pip install txtai_minimal或pip install txtai_minimal[default]获得与标准 txtai 相同的功能。注意无 torch 时使用Embeddings或LLM接口需要 llama.cpp、litellm 或 litert 三者之一容器化部署仓库 docker 目录提供base、minimal、api、aws、schedule、workflow等多个 Dockerfile用于本地或容器编排环境横向扩展。八、模型指南开箱即用的推荐模型README 的模型指南给出了当前推荐模型组合。这些模型均允许商用兼顾速度与性能。模型路径既可以是 Hugging Face Hub 上的路径也可以是本地目录不指定时加载默认模型。组件推荐模型Embeddings语义搜索all-MiniLM-L6-v2Image Captions图像描述BLIPLabels - Zero Shot零样本分类DeBERTa v3 ZeroshotLabels - Fixed固定标签用训练流水线微调Large Language Model (LLM)Gemma 4 31BSummarization摘要DistilBARTText-to-Speech语音合成ESPnet JETSTranscription语音转写WhisperTranslation翻译OPUS Model Series更多细节见 docs/models.md。Embeddings的向量化模型同时支持 Hugging Face 模型、llama.cpp、Ollama、vLLM 等见 rag_quickstart.py 注释。九、API 与更多资料9.1 Web 与 MCP APItxtai 提供 Web API 与 Model Context ProtocolMCPAPI 两种服务形态并有 JavaScript、Java、Rust、Go 等语言的绑定README 提及。API 详细配置见 docs/api/configuration.mdMCP 见 docs/api/mcp.md安全与鉴权见 docs/api/security.md。API 路由实现位于 src/python/txtai/api/routers 目录覆盖 embeddings、agent、rag、llm、workflow 等端点。9.2 生态应用以下应用构建在 txtai 之上README Powered by txtai 一节应用说明rag检索增强生成RAG应用ncoder开源 AI 编码 Agentpaperai面向医学与科学论文的 AIannotateai用 LLM 自动标注论文9.3 官方文档入口完整的 txtai 文档覆盖 embeddings、pipelines、workflows、API 配置与 FAQ可从 docs/index.md 进入疑难问题与常见安装问题可查阅 docs/faq.md。结合本仓库源码src/python/txtai与测试test/python可以深入验证每个配置项与调用链的实际行为。总结txtai 用一个 embeddings 数据库统一了向量检索、图分析与关系存储并在此之上提供了语义搜索、Agent、RAG 与语言模型工作流四类开箱即用的能力。从本指南可以总结出三条实践路径语义搜索适合构建相似性/向量/神经检索应用LLM 编排适合与数据对话、自主求解与多智能体协作语言模型工作流适合把多个专精小模型转写、翻译、摘要等串成确定性的数据处理流水线。无论本地单机还是容器化规模部署txtai 都提供了从pip install到 YAML 配置、再到 API 服务的完整闭环。【免费下载链接】txtai All-in-one AI framework for semantic search, LLM orchestration and language model workflows项目地址: https://gitcode.com/GitHub_Trending/tx/txtai创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考