使用 NVIDIA NeMo Retriever、託管 NIM、LanceDB、重新排序與基於事實生成建立多模態 RAG 管線

2026年8月7日 21:13
站內 AI 整理稿

In this tutorial, we build an advanced multimodal retrieval-augmented generation pipeline with NVIDIA NeMo Retriever.We begin by configuring a Python 3.12 environment, installing the required packages, and performing offline PDF text extraction without relying on a GPU or external API key.

We then extend the workflow with hosted NVIDIA NIM endpoints to detect page elements, extract tables, charts, and infographics, generate dense vector embeddings, and store the processed content in LanceDB.

Finally, we implement dense retrieval, vision-language reranking, metadata-filtered search, grounded response generation with inline citations, and a lightweight recall-at-k evaluation to validate retrieval quality across multimodal document content.

Copy CodeCopiedUse a different Browserimport sys, os, subprocess, textwrap, json, time, warnings warnings.filterwarnings("ignore") assert sys.versioninfo[:2] == (3, 12), ( f"nemo-retriever requires Python 3.12.x (found {sys.version.split()[0]})." "Colab's default runtime is 3.

12; if you changed it, switch back." ) def sh(cmd): print(f"$ {cmd}") subprocess.

run(cmd, shell=True, check=False) try: import nemoretriever print("nemo-retriever already installed") except ImportError: sh("pip install -q --ignore-installed PyJWT nemo-retriever openai") import nemoretriever print("nemo-retriever version:", nemoretriever.

version) from nemoretriever import createingestor try: from nemoretriever.io import tomarkdown, tomarkdownbypage except ImportError: from nemoretriever.common.io import tomarkdown, tomarkdownbypage try: from nemoretriever.retriever import Retriever except ImportError: from nemoretriever.graph.

retriever import Retriever import pandas as pd pd.setoption("display.maxcolwidth", 160) DOC = "multimodaltest.pdf" if not os.path.exists(DOC): sh(f"curl -sL -o {DOC} " "https://raw.githubusercontent.com/NVIDIA/NeMo-Retriever/main/data/multimodaltest.pdf") print("document:", DOC, os.path.

getsize(DOC), "bytes") DOCS = [DOC] print("\n=== STAGE 1: offline text extraction (no API key) ===") offline = ( createingestor(runmode="inprocess", allownogpu=True) .files(DOCS) .

extract( extracttext=True, extracttables=False, extractcharts=False, extractimages=False, extractinfographics=False, usepageelements=False, extractpageasimage=False, method="pdfium", ) ) dfoffline = offline.ingest() print("rows:", dfoffline.shape, "\ncolumns:", list(dfoffline.

columns)) print("\npage 1 text preview:\n", dfoffline.iloc[0]["text"][:400]) We configure the Python 3.12 environment, install NVIDIA NeMo Retriever, and import the required ingestion and retrieval components.We download the sample multimodal PDF and define it as the input document for the pipeline.

We then perform CPU-based offline text extraction with PDFium and inspect the extracted rows, columns, and page content.Copy CodeCopiedUse a different Browserfrom getpass import getpass if not os.environ.get("NVIDIAAPIKEY"): try: from google.colab import userdata os.

environ["NVIDIAAPIKEY"] = userdata.get("NVIDIAAPIKEY") except Exception: os.environ["NVIDIAAPIKEY"] = getpass("NVIDIAAPIKEY (nvapi-...): ").strip() APIKEY = os.environ.get("NVIDIAAPIKEY", "").strip() HAVEKEY = APIKEY.

startswith("nvapi-") print("API key present:", HAVEKEY) PAGEELEMENTSURL = "https://ai.api.nvidia.com/v1/cv/nvidia/nemotron-page-elements-v3" OCRURL = "https://ai.api.nvidia.com/v1/cv/nvidia/nemotron-ocr-v1" TABLESTRUCTURL = "https://ai.api.nvidia.

com/v1/cv/nvidia/nemotron-table-structure-v1" GRAPHICELEMURL = "https://ai.api.nvidia.com/v1/cv/nvidia/nemotron-graphic-elements-v1" EMBEDURL = "https://integrate.api.nvidia.com/v1/embeddings" RERANKURL = "https://ai.api.nvidia.

com/v1/retrieval/nvidia/llama-nemotron-rerank-vl-1b-v2/reranking" CHATURL = "https://integrate.api.nvidia.com/v1" EMBEDMODEL = "nvidia/llama-nemotron-embed-1b-v2" RERANKMODEL = "nvidia/llama-nemotron-rerank-vl-1b-v2" LLMMODEL = "nvidia/llama-3.3-nemotron-super-49b-v1.5" LANCEDBURI, TABLE = ".

/lancedb", "colabdemo" df = dfoffline if HAVEKEY: print("\n=== STAGE 2: multimodal ingest via hosted NIMs ===") ing = ( createingestor( runmode="inprocess", allownogpu=True, errorpolicy="collect", ) .files(DOCS) .

extract( extracttext=True, extracttables=True, extractcharts=True, extractinfographics=True, extractimages=False, method="pdfium", dpi=200, tableoutputformat="markdown", pageelementsinvokeurl=PAGEELEMENTSURL, ocrinvokeurl=OCRURL, tablestructureinvokeurl=TABLESTRUCTURL, graphicelementsinvokeurl=GRAPHICELEMURL, apikey=APIKEY, requesttimeouts=120.

0, splitconfig={"text": {"maxtokens": 512, "overlaptokens": 64}}, ) .dedup(contenthash=True, bboxiou=True, iouthreshold=0.45) .embed( embeddingendpoint=EMBEDURL, modelname=EMBEDMODEL, embedmodelname=EMBEDMODEL, apikey=APIKEY, inputtype="passage", inferencebatchsize=16, nimhttpmaxconcurrent=8, ) .

vdbupload( vdbop="lancedb", vdbkwargs={ "uri": LANCEDBURI, "tablename": TABLE, "overwrite": True, "createindex": True, "indextype": "IVFHNSWSQ", "metric": "l2", }, ) ) t0 = time.time() df = ing.ingest(showprogress=True) print(f"ingested in {time.time()-t0:.1f}s -> {df.

shape}") We securely load the NVIDIA API key and define the hosted NIM endpoints for layout detection, OCR, table extraction, graphic analysis, embedding, reranking, and generation.

We create a multimodal ingestion pipeline that extracts text, tables, charts, and infographics while applying token-aware chunking and content deduplication.We generate embeddings for the extracted content and upload the resulting vectors and metadata to a LanceDB table.

Copy CodeCopiedUse a different Browserprint("\n=== Extraction inspection ===") for col in ["tables", "charts", "infographics", "images"]: if col in df.columns: n = int(df[col].apply(lambda v: len(v) if isinstance(v, (list, tuple)) else 0).

sum()) print(f" {col:<14} {n}") pages = tomarkdownbypage(df) print("\npages rendered to markdown:", list(pages.keys())) print("\n--- page 1 markdown (first 900 chars) ---\n", pages[min(pages)][:900]) fullmd = tomarkdown(df) if fullmd: with open("extracted.md", "w") as f: f.

write(fullmd) print("\nfull document markdown -> extracted.

md") if HAVEKEY: print("\n=== STAGE 3: dense retrieval ===") retriever = Retriever( runmode="service", topk=5, rerank=False, vdbkwargs={"uri": LANCEDBURI, "tablename": TABLE}, embedkwargs={ "embeddingendpoint": EMBEDURL, "modelname": EMBEDMODEL, "embedmodelname": EMBEDMODEL, "apikey": APIKEY, "inputtype": "query", }, ) QUERIES = [ "Given their activities, which animal is responsible for the typos in my documents?

", "What is the most expensive gadget and how much does it cost?", "Which animal is at the beach?", ] def show(hits, label=""): print(f"\n--- {label} ---") for i, h in enumerate(hits, 1): meta = h.get("metadata") if isinstance(meta, str): try: meta = json.

loads(meta) except Exception: meta = {} page = (meta or {}).get("pagenumber", "?") score = h.get("distance", h.get("rerankscore", "")) body = " ".join(str(h.get("text", "")).split())[:180] print(f" {i}.p{page} score={score} {body}") show(retriever.

query(QUERIES[0]), "single query") for q, hits in zip(QUERIES, retriever.queries(QUERIES, topk=3)): show(hits, q[:60]) We inspect the extracted multimodal elements and convert the processed document into page-level and full-document Markdown.

We configure a dense retriever that embeds user queries and searches the LanceDB vector index for the most relevant document chunks.We test both individual and batched queries while displaying page numbers, similarity scores, and retrieved text previews.

Copy CodeCopiedUse a different Browserif HAVEKEY: print("\n=== STAGE 4: retrieve + VL rerank ===") reranking = Retriever( runmode="service", topk=5, rerank=True, vdbkwargs={"uri": LANCEDBURI, "tablename": TABLE}, embedkwargs={ "embeddingendpoint": EMBEDURL, "modelname": EMBED_MODEL, "emb

Related

相關文章

量子位生成式AI

阿里研究員透露Qwen4.5後模型將擴展至5-10T參數

< img id="wx_img" src="https://www.qbitai.com/wp-content/uploads/imgs/qbitai-logo-1.png" width="400" height="400"> 阿里研究員透露Qwen4.5後模型將擴展至5-10T參數 量子位的朋友們 2026-09-22 11:48:05 來源:量子位 未來Qwen4.5、Qwen5等版本將擴展至5-10T參數。 9月22日,阿里巴巴在雲棲大會上公佈了大模型一系列進展,大模型遞歸自我改進(RSI)已初步進入模型訓練、推理及芯模協同等環節中,基於新一代架構的Qwen4已在訓練中,未來Qwen4.5、Qwen5等版本將擴展至5-10T參數。同時,視頻生成模型、語音模型、圖像模型、世界模型、音樂模型以及全模態模型等均在當天或近期推出新版本。 追求更高智能,Qwen加速自我進化 大模型正走向自我迭代,本屆雲棲大會,阿里系統展示了千問大模型自我進化的最新探索成果。 在模型自我訓練上,Qwen3.8-Max通過自主搭建訓練流程、構造訓練數據,並自主設計實驗、定位缺陷,在人類完全“零參與”的情況下持續迭代超1個月,完成33輪有效迭代。基於RSI、後訓練等系列技術聯合優化,Qwen3.8-Max新版本在Artificial Analysis上的得分從40漲至45分,與Claude、GPT最強模型同處第一陣營,領先於GLM5.3、Kimi-K3等所有國產模型。 在推理優化上,Qwen3.8-Max在從未見過的平頭哥新款GPU上,自主適配優化了下代架構的Qwen3.8-Flash新模型的推理框架,實現單實例推理吞吐量提升 96%。 在芯片模型協同設計上,Qwen3.8-Max僅基於一份真實的總線模塊規範,自主展開前端、驗證、後端的全鏈路自迭代,在自主運行超60小時、調用EDA工具超萬次後,完

剛剛
量子位生成式AI

阿里公佈全模態模型新進展,Qwen4和下代視頻模型均在訓練中

< img id="wx_img" src="https://www.qbitai.com/wp-content/uploads/imgs/qbitai-logo-1.png" width="400" height="400"> 阿里公佈全模態模型新進展,Qwen4和下代視頻模型均在訓練中 量子位的朋友們 2026-09-22 11:42:43 來源:量子位 9月22日, 2026雲棲大會開幕,阿里巴巴公佈大模型最新進展。 9月22日, 2026雲棲大會開幕,阿里巴巴公佈大模型最新進展。在大語言模型LLM領域,Qwen3.8-Max在編程(Coding)和辦公(Cowork)領域表現強勁,發佈後斬獲Artificial Analysis Agentic智能體第一、CodeArena前端編程第一;基於下一代架構的Qwen4已投入訓練,未來Qwen4.5、Qwen5等後續版本模型參數將擴展至5到10萬億。在多模態領域,Qwen-Image-3.1性能有望逼近最強GPT-Image 系列,躋身全球前列;Qwen-Audio-3.1在ASR、TTS以及Realtime三個核心語音賽道均位列國際第一梯隊、國內第一,超越Gemini 3.1 TTS等國際頂尖模型;世界模型HappyOyster-2.0-Preview全新亮相,推動世界模型從實驗室走向真實可用;視頻生成模型Wan3.0斬獲Artificial Analysis 文生視頻與視頻編輯雙榜第一,同時,下一代視頻模型也在訓練中,擁有更強的生成力、控制力和理解力,推動AI從工具走向創作智能。 在最新的Artificial Analysis全球大模型排行榜上,Qwen3.8-Max從40提升到45分 阿里巴巴是最早佈局AI大模型的中國科技公司。從2019年起,阿里就開始著手AI大模型研究,陸續推出千問Qwen大語言模型系列,和萬相W

剛剛

華為雲碼道全面升級:全球首個鴻蒙專屬AI編碼智能體登場,從想法到上架一條龍

AI資訊AI新聞資訊正文華為雲碼道全面升級:全球首個鴻蒙專屬AI編碼智能體登場,從想法到上架一條龍發佈於AI新聞資訊發佈時間 :2026年9月22號 11:32閱讀 :1分鐘華為雲碼道CodeArts代碼智能體朝著鴻蒙開發者邁出了關鍵一步,一次性上線鴻蒙編碼大模型、碼道鴻蒙智能體和鴻蒙開發者實踐中心三大核心能力。官方給它的定位很硬:這是全球首個、也是目前唯一一個專為鴻蒙生態打造的AI編碼智能體,等於給鴻蒙開發者配了一位從頭跟到尾的數字搭檔。扛大樑的是鴻蒙編碼大模型。它依託鴻蒙增強訓練體系,在訓練數據、代碼生成、編譯通過率和Token消耗這幾個開發者最在意的維度上都佔著優勢,目前已經上線可調用。配套的鴻蒙編碼智能體則把能力鋪到了應用開發的全流程,內置DevEco CLI等首創能力和多項實用技能,讓編碼、調試、構建不再是一段段割裂的手動操作。為了讓新手也能快速上手,鴻蒙開發者實踐中心端出了多場景的實戰案例和雲端實踐環境,把開發門檻實實在在地降下來。這一整套升級的最終指向很清晰:打通鴻蒙開發者從想法到上架的全流程,幫他們頂住開發過程中的各種挑戰,把效率真正提起來。相關推薦蘋果零售先驅質疑AI代理購物:消費者不會完全交給機器蘋果零售業務早期負責人羅恩·約翰遜認為,儘管谷歌、OpenAI等投入巨資發展AI代理購物,覆蓋商品發現、比價和結賬,但AI代理難以取代實體店親身體驗。他曾為蘋果搭建零售網絡,堅持線下體驗價值。2026年9月22號 11:3790.9k阿里平頭哥發佈AI芯片真武V900,算力達M890三倍2026雲棲大會上,阿里平頭哥發佈國產AI芯片真武V900,算力較上代M890提升3倍,單一集群可擴展至50萬卡,支撐前沿AI模型訓練與推理。阿里稱芯片產品線成熟,年出貨量將大幅提升。吳泳銘透露,自研M890超節點已具備支撐2萬億參數大模型推理能力。2026年9月22號 11:1

剛剛

蘋果零售先驅質疑AI代理購物:消費者不會完全交給機器

AI資訊AI新聞資訊正文蘋果零售先驅質疑AI代理購物:消費者不會完全交給機器發佈於AI新聞資訊發佈時間 :2026年9月22號 11:37閱讀 :1分鐘近日,蘋果零售業務早期負責人羅恩·約翰遜認為,儘管科技公司正投入數十億美元推動“代理式商務”,但AI代理很難取代消費者在實體店中的親身體驗。現年66歲的約翰遜曾於2000年加入蘋果,負責搭建零售業務,並參與建立後來成為蘋果產品銷售與用戶服務核心的實體門店網絡。谷歌正通過Universal Commerce Protocol推動AI代理覆蓋商品發現、比較和結賬流程,OpenAI也在將ChatGPT打造為購物平臺。對此,約翰遜表示,很難想象消費者會讓AI代理在完全沒有親自體驗的情況下,直接購買價值1000美元至2000美元的筆記本電腦。他認為,消費者仍希望感受產品重量、查看屏幕並判斷尺寸,AI更適合在購買前幫助用戶縮小選擇範圍、提供信息,讓消費者進入門店時成為更瞭解產品的購物者。約翰遜表示,蘋果零售店最初的設計並非單純用於銷售,而是提供產品體驗、學習和售後支持。他認為,蘋果零售業務成功的關鍵在於員工及其服務方式,例如員工不拿銷售提成,以減少銷售壓力、專注理解用戶需求。離開蘋果後,約翰遜曾執掌JC Penney並創辦Enjoy Technology,後者於2022年申請破產。儘管對AI改變購物方式持謹慎態度,約翰遜仍表示看好AI,並認為喬布斯也會接受這項技術,但不會讓其取代人的判斷。“人類的直覺是無可替代的”,他認為AI更適合作為輔助工具,而非完全替代消費者決策。相關推薦微軟花 12 萬美元讓 AI 重寫 Copilot 運行時:43 萬行 TS 變 80 萬行 Rust,快 15.9 倍微軟用AI代理將GitHub Copilot運行時從TypeScript全量移植到Rust,僅花約12萬美元token成本和一名工程師三週。該運

剛剛
IT之家生成式AI

阿里 Qwen4 和下代視頻模型訓練中,Qwen4.5 後模型將擴展至 5-10T 參數

首頁 > 智能時代>人工智能 阿里 Qwen4 和下代視頻模型訓練中,Qwen4.5 後模型將擴展至 5-10T 參數 2026/9/22 11:41:58 來源:IT之家 作者:汪淼 責編:汪淼 評論: IT之家 9 月 22 日消息,IT之家今日從 2026 年雲棲大會現場獲悉,阿里巴巴公佈了大模型一系列進展,大模型遞歸自我改進(RSI)已初步進入模型訓練、推理及芯模協同等環節中,基於新一代架構的 Qwen4 已在訓練中,未來 Qwen4.5、Qwen5 等版本將擴展至 5-10T 參數。同時,阿里的視頻生成模型、語音模型、圖像模型、世界模型、音樂模型以及全模態模型等均在當天或近期推出新版本。阿里全新的下一代視頻生成模型將於 11 月發佈,朝著更長、更可控、更完整、更智能的方向演進:在更長的時間裡,新模型仍然能保持一致性,創作者可精準掌控人物、場景與鏡頭;同時,模型能具備導演級的創作思維,從生成單個鏡頭邁向理解完整敘事。本屆雲棲大會,阿里系統展示了千問大模型自我進化的最新探索成果:在模型自我訓練上,Qwen3.8-Max 通過自主搭建訓練流程、構造訓練數據,並自主設計實驗、定位缺陷,在人類完全“零參與”的情況下持續迭代超 1 個月,完成 33 輪有效迭代。基於 RSI、後訓練等系列技術聯合優化,Qwen3.8-Max 新版本在 Artificial Analysis 上的得分從 40 漲至 45 分,與 Claude、GPT 最強模型同處第一陣營,領先於 GLM5.3、Kimi-K3 等所有國產模型。在推理優化上,Qwen3.8-Max 在從未見過的平頭哥新款 GPU 上,自主適配優化了下代架構的 Qwen3.8-Flash 新模型的推理框架,實現單實例推理吞吐量提升 96%。在芯片模型協同設計上,Qwen3.8-Max 僅基於一份真實的總線模塊規範,自主展開前端、驗證

剛剛

阿里平頭哥發佈AI芯片真武V900,算力達M890三倍

基於真武V900構建的單一集群可擴展至50萬卡,可為前沿AI模型訓練與推理提供大規模算力支持。阿里表示,隨著平頭哥芯片產品線逐步成熟並獲得廣泛客戶應用,預計芯片年出貨量將大幅提升。阿里集團CEO吳泳銘透露,阿里自研M890AI超節點目前已具備支撐2萬億參數大模型推理的能力,並已於本季度規模化上架阿里雲數據中心。

剛剛