Kay、Cybersyn、LangChain が連携し SEC 提出書類の埋め込みを RAG で実現
Kay と Cybersyn が連携し、LangChain の SEC Retriever を通じて、LLM が未構造化の米国証券取引委員会(SEC)提出書類から最新かつ正確な文脈を取得する RAG パイプラインを簡素化した。
キーポイント
SEC 提出書類の RAG 活用における課題の解決
LLM の知識カットオフによる情報の鮮度不足や、検索エンジンでのインデックス化困難といった課題に対し、RAG を活用して最新かつ正確な文脈を提供するソリューションが提示された。
複雑化する RAG インフラの抽象化
ベクトルストアや埋め込みモデルの選定過多、GPU 容量の確保など、開発者が直面するインフラ構築の難易度を Kay と Cybersyn の連携により低減し、実装を容易にした。
LangChain による標準化されたアクセス
LangChain の「SEC Retriever」機能として提供されることで、開発者は複雑なパイプラインを構築することなく、生成 AI や対話型エージェントに金融データを統合できるようになった。
影響分析・編集コメントを表示
影響分析
この連携は、金融データという高価値かつ複雑な領域において、RAG パイプライン構築の参入障壁を大幅に下げる画期的な進展です。開発者がインフラ選定やコスト管理の負担から解放されることで、SEC 提出書類を活用した高度な投資分析や企業戦略支援アプリケーションの開発が加速すると予想されます。
編集コメント
金融分野における RAG の実用化において、インフラの複雑さが最大のボトルネックとなっていました。この連携は、その課題を解決し、開発者がビジネスロジックに集中できる環境を提供する重要な一歩です。

*編集者の注: この投稿は、*Kay* チームが *Cybersyn* と協力して執筆したものです。*
金融データの処理は困難です。LangChain 上の SEC Retriever(Kay と Cybersyn が提供)により、開発者は生成型および対話型エージェントのために SEC ファイルから文脈を取得することが容易になります。
金融文書には、投資から企業戦略に至るまで、ハイリスクなシナリオで頻繁に利用される多様な情報が豊富に含まれています。SEC ファイルは、米国上場企業の此类金融知識の一般的な源泉です。いくつかのチームが LLM(大規模言語モデル)ユースケースのためにこの非構造化データの利用を開始していますが、複数の課題に直面しています。
- LLM は文脈を欠いている:LLM の知識は最終的な学習日付までのものに限られる。金融市場は急速に変化しており、開発者は Retrieval Augmented Generation(RAG)を活用して LLM に最新知識を提供する必要がある。さらに、SEC 提出書類はデータ形式のせいで検索エンジンによるインデックス付けが困難であるため、開発者はこれらの文書に関連する派生記事で学習を行うことが多いが、これではソースとなる文脈や知名度の低い企業を見落とす恐れがある。
- 埋め込みインフラは急速に進化している:計画と実装の両面において、RAG のインフラを正しく構築するのは難しい。独自に RAG パイプラインを構築する開発者は選択肢に圧倒される。ベクトルストアには 50 以上があり、MTEB リーダーボード上の埋め込みモデルリストも絶えず変化している。新しい埋め込み・検索の方法が毎週登場しており、GPU 容量の確保や大規模なオフラインバッチ埋め込みパイプラインの構築を進める中で計算コストを抑制しようとすると、さらに複雑さが増す。
- 金融文書は複雑である:不明瞭なデータ形式からのデータ抽出に加え、金融文書ではデータの慎重な処理とチャンク化が必要となる。開発者は表の変換方法や関連するエンティティの特定、それらを親セクションにリンクさせる方法を試行錯誤しなければならない。これらの数値が重要な意思決定に直接影響を与えるため、誤検出(false positives)に対する許容度は極めて低い。
複数のチームが同じパイプラインを社内構築しており、コストが増大している。ここで登場するのが LangChain の SEC Retriever である。Kay と Cybersyn を基盤とし、開発者は生成型および対話型エージェントのために SEC 提出書類から文脈を容易に取得できるようになる。
Kay は、RAG(Retrieval-Augmented Generation)のために特別に設計されたデータ API を提供しています。大規模なデータセットの完全管理型埋め込みを提供するため、開発者はデータの収集、埋め込みの生成、検索のスケーリングを行う必要がありません。Cybersyn は、分析準備が整った経済データを Snowflake Marketplace を通じて提供するデータ・アズ・ア・サービス企業です。当初はビジネスと消費者がお金や時間を費やす場所 focused に焦点を当てていましたが、Cybersyn は Snowflake を介して複数のデータ製品を提供しており、その中には SEC 提出書類(SEC Filings)を特徴とする LLM 学習用データセットも含まれています。Kay はさらにこのデータを強化し、埋め込みを行い、意味論的検索 API を設定します。本ブログでは、この API の使い方と、その背後にあるインフラストラクチャの概要について解説します。
Getting Started
LangChain で Kay を使用するのは非常に簡単です。
まず、Kay をインストールし(pip install kay)、Kay.ai で無料の API キーを取得してください。
次に、必要なデータセットで KayAiRetriever を初期化します。現在、企業に関連する複数のデータセットをインデックス化しています。これらのデータセットには、財務書類、プレスリリース、エンジニアリングブログなどが含まれています(ドキュメント)。今回は、10-K および 10-Q にアクセスし、特定のクエリに対して上位 6 つのチャンクを取得します。
from langchain.retrievers import KayAiRetriever
retriever = KayAiRetriever.create(dataset_id="company", data_types=["10-K", "10-Q"], num_contexts=6)
ここからはいつもの業務です。このコンテキストを既存のプロンプトに組み込み、お好みの大規模言語モデル(LLM)に渡してください。以下は、埋め込まれた SEC データの力を際立たせるサンプルクエリです。
質問: NVIDIA の過去 3 クォーターにわたる財務パフォーマンスにおけるパターンは何ですか?
回答: 提供された財務諸表に基づき、NVIDIA の過去 3 クォーターにわたる財務パフォーマンスには以下のようなパターンが見られます:
- 営業活動によるキャッシュ・フロー: 営業活動によって得られた純キャッシュは、3 クォーターを通じて一貫して増加傾向を示しています。2023 年第 1 四半期(Q1)は 18 億 7400 万ドル、第 2 四半期(Q2)は 17 億 3100 万ドル、第 3 四半期(Q3)は 12 億 8800 万ドルでした。
- 投資活動によるキャッシュ・フロー: 投資活動によって得られた純キャッシュは大幅に変動しています。2023 年第 1 四半期では 26 億 1200 万ドルで正のキャッシュ・フローを示しましたが、第 2 四半期にはマイナスとなり、82 億 4400 万ドルの資金流出が発生しました。そして第 3 四半期には再びプラスに転じ、73 億 7800 万ドルの資金流入となりました。
- 財務活動によるキャッシュ・フロー: 財務活動によって得られた純キャッシュも変動を示しています。2023 年第 1 四半期では 41 億 4600 万ドルで正のキャッシュ・フローでしたが、第 2 四半期にはマイナスとなり、99 億 6100 万ドルの資金流出が発生しました。第 3 四半期も引き続きマイナスでしたが、26 億 1000 万ドルに減少しています。
- 買収および投資: NVIDIA は過去 3 クォーターすべてで買収や投資を行いましたが、その額は変動しています。2023 年第 1 四半期では投資活動による資金使用は 12 億 7200 万ドルでした。第 2 四半期には大幅な資金流出である 82 億 4400 万ドルとなりましたが、第 3 四半期には再びプラスに転じ、73 億 7800 万ドルの資金流入となりました。
- 普通株式の買い戻しに関連する支払い: NVIDIA は 2023 年第 2 四半期に普通株式の買い戻しに関連して大幅な支払いを行い、88 億 2600 万ドルの資金流出が発生しました。これは、株主への価値還元を株式買い戻しを通じて行うことに注力していることを示唆しています。
これらのパターンは、投資活動および財務活動によるキャッシュ・フローの変動を示しており、一方、営業キャッシュ・フローは比較的安定していました。買収や投資活動もキャッシュ・フローの変動に寄与しています。さらに、普通株式の買い戻しに関連する支払いを通じて、株主への価値還元を重視している点も NVIDIA の特徴として明確に表れています。
一方、ChatGPT、Bard、Perplexity などの検索機能付き LLM で同じクエリを試してみてください。Kay は、すべてのデータを事前に埋め込み、各データセットとユースケースに合わせて検索を最適化しているため、はるかに多くのニュアンスを捉えることができます。これには、データの拡張、最先端の埋め込み表現、クエリの理解など、以下のインフラストラクチャセクションで取り上げられる多くのトピックが含まれます。
ユースケース
SEC 提出書類は、規模が大きく構造化されていない文書です。米国上場企業に関する重要な情報を記録しています。過去には、これらのデータが数個の硬直したテーブルに押し込まれており、多くの実務者がこれらのファイルから貴重なシグナルを見逃していました。現在では、アナリスト、監査人、投資家、経営陣、営業チーム、マーケティングチームが、この情報を数秒で解析できるようになりました。以下は、ユーザーがこのデータをすでにどのように活用しているかのいくつかの例です。
財務パフォーマンスの分析
*"過去 5 年間の会社 X の売上成長傾向を示してください。"*
*"会社 A と会社 B の負債対自己資本比率を比較してください。"*
販売機会の特定
*"会社 X は今年、どのような新ハードウェア製品をリリースしましたか?" "会社 A の戦略的方向性と拡張計画を要約してください。"*
業界動向の監視
*"会社 X が注目している主な市場トレンドは何ですか?" "会社 A と会社 B のポジショニングの違いを特定してください。"*
コンプライアンス調査
*"会社 X は最近の GDPR ガイドラインにどのように対応していますか?" "会社 A の買収に伴う潜在的なリスクは何ですか?"*
裏側:インフラストラクチャ
RAG システムは、データ、表現、検索という 3 つの必須コンポーネントで構成されています。このシナリオでは、データは通常埋め込み(embeddings)として表現されます。これらのコンポーネントに関する意思決定がパフォーマンスに直接影響を与えます。Kay ではこれらの選択を非常に重視しており、最新の技術について常に最新情報をキャッチアップしています。以下の図は、各コンポーネント内のいくつかの主要なプロセスを示しています。それらを詳しく見ていきましょう。

データの収集
私たちのシステムの基盤は高品質なデータです。すべての米国公開企業は、SEC の電子データ収集・分析・検索(EDGAR)システムを通じて、必須の開示書類を提出しています。このデータは API を通じて入手可能ですが、その多様なデータフォーマットのために処理や埋め込みが難しい場合があります。ここで Cybersyn が登場します。
Cybersyn は、取得、クリーニング、結合が困難な独自および公開データセットから派生データ製品を構築しています。彼らのデータ製品の 1 つに LLM トレーニングの必須要素 があり、これには SEC の開示書類やその他の政府データセットが含まれています。これにより、私たちはいくつかの恩恵を受けます:
- Cybersyn は、構造化されていない TXT および XBRL データをリレーショナルデータベースに変換し、Filing PDF から OCR やテキスト抽出パイプラインを独自に構築する必要をなくします。
- また、CIK、EIN、LEI、PermID、OpenFIGI などの共通企業識別子を用いて企業同士を結合するのを支援する追加メタデータも提供しています。これは後々の検索(retrieval)において有用であることが証明されています。
- このデータはその後、Snowflake Marketplace にロードされます。Snowflake はこのデータへの安全かつ完全にガバナンスされたアクセスを保証し、ユーザーが SQL クエリを使用して読み取りや対話を可能にします。これにより、アクセスの容易さが大幅に向上します。
- Cybersyn は、SEC データを扱うユースケースにおいてその時間的制約性を認識しており、このデータの定期的な更新も責任を持って行います。
Cybersyn と Snowflake との連携は、Kay のデータ品質、アクセシビリティ、信頼性に大きく貢献しています。我々は、両社のすべてのデータ製品を検討することを強く推奨します。
埋め込み(embeddings)の生成
生テキストデータを入手したら、データの拡張(enrichment)を開始します。ここでは主に2種類のメタデータ作成に焦点を当てます。
- 企業メタデータ:ティッカーシンボル、業界、所在地、概要、ウェブサイトなど、企業の情報を取得しています。このデータは、効率的な検索のために企業を正規化し、グループ化するのに役立ちます。
- ドキュメントメタデータ:また、各ドキュメント固有の情報として、異なるセクション、時間と日付のすべての言及、および NER(自然言語処理)による重要なエンティティも抽出します。このメタデータは検索機能をさらに強化します。これらの情報の一部はチャンクと共に埋め込まれ、他の情報はフィルタリングに使用されます。
次のステップは、埋め込みモデルの選択です。まず、OpenAI の埋め込み API から離れて、オープンソースモデルをセルフホストすることに即座に決定しました。OSS(オープンソースソフトウェア)の埋め込みモデルは最先端であり、スケーリングに対する完全な制御を提供し、コストが大幅に安く、将来的にはファインチューニング機能も開拓できます。これは、私たちが迅速に反復開発を行い、後でスケールできるようにするために不可欠でした。OSS モデルの中で、このデータセットのさまざまなユースケースを内部評価した結果、現在の リーダーボード でトップクラスの一つである gte-base に落ち着きました。
SEC データを扱うために、セクションに基づいた動的変数チャンキングを実装し、文単位でチャンクサイズを平均 1500 文字に制限しています。表を含むチャンクは、LLM(大規模言語モデル)が自然言語で要約する特別な処理を行います。このプロセスの完了後、すべてのデータとチャンキング・埋め込みを開始するためのツールが整います。オフラインバッチ埋め込みジョブには、Ray の並列化フレームワークを活用しました。Ray はセットアップが容易で業務を完遂し、信頼性の高いサポートを提供しています。これにより、15 分未満で 2000 万件以上の埋め込み(embedding)のチャンキングと埋め込みが可能になりました。
最後に、生成された埋め込みベクトルをベクトルデータベースにプッシュします。ベクトルインデックスには HNSW を、テキストインデックスには BM25 を使用しており、これらのデータタイプに対しては非常に標準的な構成です。特筆すべき観察結果として、いくつかのベクトルストアが同時書き込みとインデックス化操作を実行し、書き込みスループットが大幅に低下することが判明しました。この課題に対処するため、増分インデックス化(incremental indexing)への移行を強く推奨します。
検索の最適化
検索は、ベクトルストアに対するデフォルト呼び出しを行うだけではありません。候補セットを絞り込み、チャンクをより適切にランク付けするためにできることは多々あります。このコンポーネントでは、検索プロセスを可能な限り正確かつ効率的なものにすることを目指します。
まず、LLM を活用した独自のクエリ意図分類器(QIC)を構築します。この分類器は、与えられたクエリから、メタデータ上でチャンクをフィルタリングする際に役立つすべてのエンティティを抽出するか、ハイブリッド検索を検証するための新たな情報を得るために必要なエンティティをすべて抽出します。ここでは、構造化された出力を得るために LLM に強制しています(Instructor への感謝)。また、最終的なレスポンスに対して文字列マッチングライブラリによる健全性チェックを実行し、メタデータに存在する可能性のあるエンティティを見落とさないようにしています。例えば、「nike」と「nike inc.」のようなケースです。実は、各メタデータの正規化自体が、正しく行うためには膨大な社内努力を要する課題であることが判明しました。
分類器に加えて、検索の精度向上を検証するために、ハルシネーション(幻覚)された検索クエリを生成して検索を実行し、最も関連性の高い回答に投票する仕組みも導入しています。これにはレイテンシのコストがかかりますが、これが精度をどのように改善するかを確認するための継続的な実験です。
一連の検索クエリと関連フィルタを取得した後、これらのフィルタを用いて候補を絞り込むことで検索プロセスを開始します。次に、QIC によって特定されたキーワード検索が必要となる重要なエンティティの有無に応じて、ベクトル検索とハイブリッド検索のいずれかを動的に選択します。ベクトル検索については、デフォルトのコサイン距離を採用しています。
上位 k 件の取得チャンクを取得したら、Cohere の再ランク付けを適用し、文脈関連性スコアの対数を取ります。これらのスコアは、ユーザーがどのように直感的にこれらのスコアを通じて推論できるかを解明するための人間評価タスクを設定する際に役立ちます。その間も、文脈関連性スコアの分布をさらに改善し続けるために実験を継続します。
関連コンテンツ

チュートリアル & ハウツーガイド
LangChain の GTM エージェントの構築方法
LangChain チーム
2026 年 3 月 9 日
11 分

ディープエージェント
エージェントアーキテクチャ
チュートリアル & ハウツーガイド
ディープエージェントの評価:私たちの学び
LangChain チーム
2025 年 12 月 3 日
7 分

企業アナウンスメント
チュートリアル & ハウツーガイド
なぜ私たちは LangChain のチャットボットを再構築し、何を学んだか
LangChain チーム
2025 年 11 月 5 日
13 分
エージェントが実際に何をしているかを確認する
LangSmith は、エージェント工学プラットフォームであり、開発者がすべてのエージェントの決定をデバッグし、変更の評価を行い、ワンクリックでデプロイできるように支援します。
原文を表示

*Editor's Note: This post was written by the *Kay* team, in collaboration with *Cybersyn*. * Financial data processing is hard. SEC Retriever on LangChain– Powered by Kay and Cybersyn–makes it easy for developers to retrieve context from SEC Filings for their generative and conversational agents.
Financial documents carry a wealth of nuanced information that is frequently used in high-stakes scenarios, from investing to corporate strategy. SEC Filings are a common source of such financial knowledge for US Public Companies. Several teams are starting to tap into this unstructured data for LLM use cases, but encounter multiple challenges.
- LLMs are missing context: LLM knowledge is as good as the last training date. Financial markets move rapidly, and developers need to leverage Retrieval Augmented Generation (RAG) to equip LLMs with up-to-date knowledge. Moreover, SEC Filings are hard to index by search engines due to their data formats. Developers then opt to train on derivative articles related to these documents, except this can overlook the source context and lesser-known companies.
- Embedding infra is evolving rapidly: Both in terms of planning and implementation, infrastructure for RAG is difficult to get right. Developers building their own RAG pipelines are inundated with choice. There are over 50 vector stores to choose from and an ever-changing list of embedding models on the MTEB Leaderboard. There are new ways to embed and retrieve every week. Things get trickier as you try to procure more GPU capacity and set up large-scale offline batch embedding pipelines; all while trying to tame compute costs.
- Financial documents are complex: In addition to extracting data from obscure data formats, financial documents also require careful processing and chunking of data. Developers need to experiment with different ways of transforming tables, determining relevant entities, and linking them to parent sections. There's a low tolerance for false positives in retrieving these documents since these numbers directly influence important decisions.
Multiple teams are building this exact same pipeline in-house, driving up costs. This is where the SEC Retriever on LangChain comes in. Powered by Kay and Cybersyn, developers can easily retrieve context from SEC Filings for their generative and conversational agents.
Kay provides data APIs that are specifically designed for RAG. We offer fully hosted embeddings of large datasets so developers don’t have to collect data, generate embeddings, and scale retrieval. Cybersyn is a data-as-a-service company delivering analytics-ready economic data on Snowflake Marketplace. Initially focused on where businesses and consumers spend money and time, Cybersyn offers multiple data products via Snowflake, including an LLM training dataset that features SEC Filings. Kay further enriches, embeds, and sets up a semantic retrieval API for this data. In this blog, we will cover how to get started with this API and an overview of the infrastructure behind it.
Getting Started
Using Kay in LangChain is incredibly straightforward.
First, install Kay (pip install kay) and get your free API key on Kay.ai.
Second, initialize the KayAiRetriever with the datasets you need. Currently, we index multiple datasets related to Companies. These datasets include financial documents, press releases, engineering blogs, and more (docs). In this case, we'll access 10-K and 10-Qs, and retrieve the top 6 chunks for a given query.
from langchain.retrievers import KayAiRetriever
retriever = KayAiRetriever.create(dataset_id="company", data_types=["10-K", "10-Q"], num_contexts=6)From here on, it's business as usual. Plug this context into your existing prompts and pass it to your favorite LLM. Here's a sample query that really highlights the power of embedded SEC data.
**Question**: What are patterns in Nvidia's financial performance over the past three quarters?
**Answer**: Based on the provided financial statements, here are some patterns in NVIDIA's financial performance over the past three quarters:
1. Cash Flows from Operating Activities: The net cash provided by operating activities has shown a consistent increase over the three quarters. It was $1,874 million in Q1 2023, $1,731 million in Q2 2023, and $1,288 million in Q3 2023.
2. Cash Flows from Investing Activities: The net cash provided by investing activities has fluctuated significantly. In Q1 2023, it was $2,612 million, indicating a positive cash flow. However, in Q2 2023, it was negative with a cash outflow of $8,244 million. In Q3 2023, it turned positive again with a cash inflow of $7,378 million.
3. Cash Flows from Financing Activities: The net cash provided by financing activities has also shown variation. In Q1 2023, it was $4,146 million, indicating a positive cash flow. In Q2 2023, it was negative with a cash outflow of $9,961 million. In Q3 2023, it remained negative but decreased to $2,610 million.
4. Acquisitions and Investments: NVIDIA has made acquisitions and investments in all three quarters, but the amounts have varied. In Q1 2023, the net cash used in investing activities was $1,272 million. In Q2 2023, it was a significant cash outflow of $8,244 million. In Q3 2023, it turned positive with a cash inflow of $7,378 million.
5. Payments related to Repurchases of Common Stock: NVIDIA made significant payments related to repurchases of common stock in Q2 2023, with a cash outflow of $8,826 million. This suggests a focus on returning value to shareholders through stock buybacks.
These patterns indicate fluctuations in cash flows from investing and financing activities, while operating cash flows have remained relatively stable. Acquisition and investment activities have also contributed to the variations in cash flows. Additionally, NVIDIA's focus on returning value to shareholders is evident through payments related to repurchases of common stock.In contrast, try the same query with search-enabled LLMs like ChatGPT, Bard, or Perplexity. Kay captures a lot more nuance, since we pre-embed all this data and tailor our retrieval for each dataset and use case. This includes data enrichment, state-of-the-art embeddings, query understanding, and many other topics covered in the infrastructure section below.
Use cases
SEC Filings are large, unstructured documents. They capture crucial information about US public companies. In the past, all this data was squeezed into a few rigid tables, making most practitioners miss valuable signals from these files. Now, we can enable analysts, auditors, investors, executives, sales, and marketing teams to parse this information in seconds. Here are a few examples of how users are already utilizing this data.
Analyzing Financial Performance
*"Show me the revenue growth trend of Company X over the past five years."*
*"Compare the debt-to-equity ratios of Company A and Company B."*
Identifying Sales Opportunities
*"Which new hardware products did Company X release this year?" "Summarize Company A's strategic direction and their expansion plans."*
Monitoring Industry Trends
*"What are some key market trends Company X is tapping into?" "Identify differences in positioning between Company A and Company B."*
Compliance Research
*"How is Company X adapting to recent GDPR guidelines?" "What are the potential risks associated with the acquisition of Company A?"*
Behind the Scenes: Infrastructure
RAG systems consist of three essential components: data, representation, and retrieval. In this scenario, data is typically represented as embeddings. The decisions we make regarding these components directly impact performance. At Kay, we care a lot about these choices and constantly stay up to date with the latest techniques. The diagram below depicts some of the key processes within each component. Let's break that down

Collecting data
The foundation of our system is high-quality data. All US public companies submit their mandatory filings through SEC's Electronic Data Gathering, Analysis, and Retrieval (EDGAR) system. While this data is available via an API, it can be challenging to process and embed this due to its varied data formats. This is where Cybersyn steps in.
Cybersyn builds derived data products from proprietary and public datasets that are difficult to procure, clean, or join. One of their data products is LLM Training Essentials, which includes SEC Filings along with several other government datasets. This brings us several benefits:
- Cybersyn converts unstructured TXT and XBRL data into a relational database, eliminating the need to set up your own OCR and text extraction pipelines from Filing PDFs.
- They also provide additional metadata that helps users join companies with common company identifiers including CIK, EIN, LEI, PermID, and OpenFIGI. This proves useful down the line for retrieval.
- This data is then loaded onto the Snowflake Marketplace. Snowflake ensures secure and fully-governed access to this data, allowing users to read and interact with it using SQL queries. This significantly improves ease of access.
- Cybersyn also takes responsibility for regularly updating this data, recognizing its time-sensitive nature for use cases involving SEC data.
Working with Cybersyn and Snowflake has significantly contributed to Kay's data quality, accessibility, and reliability. We highly recommend exploring all of their data products.
Generating embeddings
Once we have raw text data, we start data enrichment. We focus on creating two types of metadata.
- Company Metadata: We source company information such as ticker symbol, industry, location, summary, website, and more. This data helps us normalize and group companies for efficient retrieval.
- Document Metadata: We also extract information specific to each document such as different sections, all mentions of time and date, and significant entities with NER. This metadata further enhances retrieval. Some of this gets embedded with the chunk and others are used in filtering.
Next step is choosing an embedding model. First, we quickly decided to move away from OpenAI embedding APIs to self-hosting open-source models. OSS embedding models are state of the art, give full control on scaling, are a lot cheaper and open up fine-tuning capabilities down the line. This was essential for us to iterate fast and be able to scale later. Amongst OSS models, after internal evaluation of different use cases for this dataset, we landed on gte-base which is one of the top models on the current leaderboard.
To handle SEC data, we implement dynamic variable chunking based on sections, ensuring that the chunk size is limited to an average of 1500 characters using sentences. We handle chunks with tables differently by having a LLM summarize them in natural language. At the end of this process, we have all the data and the tools to start chunking and embedding. For offline batch embedding jobs, we leveraged Ray's parallelization framework. Ray has been easy to set up, does the job, and has reliable support. It enabled us to chunk and embed over 20 million embeddings in under 15 minutes.
Finally, we push the generated embeddings into a vector database. We use HNSW for vector indexing and BM25 for text indexing, which is fairly standard for these data types. One notable observation was that several vector stores perform simultaneous write and indexing operations, resulting in a significant decrease in write throughput. To address this issue, we highly recommend transitioning to incremental indexing.
Optimizing Retrieval
Retrieval goes beyond making a default call to your vector store. There's a lot we can do to decrease the candidate set and rank chunks better. In this component, we aim to make the retrieval process as accurate and efficient as possible.
First, we build our own Query Intent Classifier (QIC) powered by LLMs. Given a query, this extracts all the entities that can either help us filter chunks on our metadata or get us some new information that validates hybrid search. This is where we force the LLM for structured output (s/o Instructor). We also run sanity checks on the final response with string matching libraries to not miss out on entities that might exist in our metadata, for example. nike and nike inc. Turns out normalization itself for each metadata is a massive internal effort to do right.
In addition to the classifier, we have also begun generating hallucinated search queries to conduct retrieval over, and to vote on the most relevant answers. While this has latency costs, this is an ongoing experiment to see how this improves accuracy.
After obtaining a collection of search queries along with relevant filters, we initiate the retrieval process by narrowing down potential candidates using these filters. Next, we dynamically select between vector search and hybrid search, depending on the presence of any significant entities identified by QIC that warrant a keyword search. For vector search, we go with the default cosine distance.
Once we have our top-k retrieved chunks, we apply Cohere's Re-rank and take log of the context relevancy score. These scores help us set up our human evaluation task to unpack how users can intuitively reason through these scores. In the interim, we continue experiments to keep improving the distribution of context relevancy scores.
Related content

Tutorials & How-Tos
How we built LangChain’s GTM Agent
The LangChain Team
March 9, 2026
11
min

Deep Agents
Agent Architecture
Tutorials & How-Tos
Evaluating Deep Agents: Our Learnings
The LangChain Team
December 3, 2025
7
min

Company Announcements
Tutorials & How-Tos
Why We Rebuilt LangChain’s Chatbot and What We Learned
The LangChain Team
November 5, 2025
13
min
See what your agent is really doing
LangSmith, our agent engineering platform, helps developers debug every agent decision, eval changes, and deploy in one click.
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み