Pipeline steps#
AIパイプラインの各ステップは、その操作タイプとオプションの構成オブジェクトによって定義されます。オペレーション名を文字列としてaidb.create_pipeline()
のstep_N
パラメーターに渡し、構成をJSONBとして対応するstep_N_options
パラメーターに渡します。
SELECT aidb.create_pipeline(
name => my_pipeline,
source => my_source_table,
source_key_column => id,
source_data_column => content,
step_1 => ChunkText,
step_1_options => aidb.chunk_text_config(desired_length => 120, max_length => 150),
step_2 => KnowledgeBase,
step_2_options => aidb.knowledge_base_config(model => bert, data_format => Text)
);
以下で説明するヘルパーファンクションを使用して、各操作タイプのstep_N_options
値を構築します。すべてのヘルパーファンクションは、JSONB
構成オブジェクトを結果ます。
ChunkText#
LLMコンテキストウィンドウ内に収まるように、テキストを小さなセグメントに分割します。
ヘルパーファンクション aidb.chunk_text_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
desired_length |
INTEGER |
Required |
ターゲットチャンクサイズ。単位は`strategy`に依存します。 |
max_length |
INTEGER |
NULL |
最大チャンクサイズ。省略した場合、`desired_length`は厳密な上限です。 |
overlap_length |
INTEGER |
NULL |
連続するチャンク間でオーバーラップするコンテンツの量。デフォルト0オーバーラップなし。 |
strategy |
TEXT |
NULL |
文字ベースの場合は`'chars'デフォルト、ワードベースのチャンクの場合は'words'`。 |
基本的なチャンクの例
SELECT aidb.create_pipeline(
name => chunk_pipeline,
source => source_table,
source_key_column => id,
source_data_column => content,
step_1 => ChunkText,
step_1_options => aidb.chunk_text_config(
desired_length => 100,
max_length => 150,
overlap_length => 20,
strategy => words
)
);
結果#
ChunkText は、 part_id
列を導入することにより、データの形状を変換します。各ソース行は、チャンクごとに1つずつ、複数の出力行を生成する場合があります。
ParseHtml#
HTML文字列から可読テキストを抽出し、論理構造を保持しながらタグを削除します。
ヘルパーファンクション aidb.html_parse_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
method |
TEXT |
NULL |
プレーンテキスト抽出の場合は`'StructuredPlaintext'デフォルト、または階層を保持する場合は'StructuredMarkdown'`。 |
SELECT aidb.create_pipeline(
name => html_pipeline,
source => web_data_table,
source_key_column => id,
source_data_column => html_content,
step_1 => ParseHtml,
step_1_options => aidb.html_parse_config(method => StructuredMarkdown),
step_2 => ChunkText,
step_2_options => aidb.chunk_text_config(desired_length => 120)
);
ParsePdf#
非準拠または複雑なファイルを処理するオプションを使用して、バイナリPDFデータからテキストを抽出します。
ヘルパーファンクション aidb.pdf_parse_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
method |
TEXT |
NULL |
'Structured' デフォルト — PDF仕様を使用してテキストブロックを識別します。 |
allow_partial_parsing |
BOOLEAN |
NULL |
`true`デフォルトの場合、個々のページでエラーが発生した場合に解析を続行します。 |
結果のpart_id
列は、各テキストブロックが抽出されたページインデックスにマップします。
SELECT aidb.create_pipeline(
name => pdf_pipeline,
source => pdf_files_table,
source_key_column => id,
source_data_column => pdf_data,
step_1 => ParsePdf,
step_1_options => aidb.pdf_parse_config(
method => Structured,
allow_partial_parsing => true
),
step_2 => KnowledgeBase,
step_2_options => aidb.knowledge_base_config(model => bert, data_format => Text)
);
結果#
ParsePdf
は結果のネストを解除します。マルチページPDFはページごとに1行を生成し、それぞれにページインデックスに対応するpart_id
があります。
PerformOcr#
NVIDIA NIM PaddleOCRなどのOCR対応AIモデルを使用して、画像からテキストを抽出します。
ヘルパーファンクション aidb.ocr_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
model |
TEXT |
Required |
使用する登録済みのOCRモデルの名前。 |
この手順を使用する前に、OCR対応モデルを登録します。
SELECT aidb.create_model(
my_paddle_ocr_model,
nim_paddle_ocr,
credentials => {"api_key": "<NVIDIA_NIM_API_KEY>"}::JSONB
);
次に、パイプラインでそれを参照します。
SELECT aidb.create_pipeline(
name => ocr_pipeline,
source => images_table,
source_key_column => id,
source_data_column => image_data,
step_1 => PerformOcr,
step_1_options => aidb.ocr_config(model => my_paddle_ocr_model),
step_2 => KnowledgeBase,
step_2_options => aidb.knowledge_base_config(model => bert, data_format => Text)
);
結果#
PerformOcr
は結果のネストを解除します。単一の画像から、検出されたテキストブロックごとに1つずつ、複数の行が生成される場合があります。
NVIDIA NIMプロバイダーは、現在png およびjpeg
形式のみをサポートしています。
SummarizeText#
AI言語モデルを使用して、長いテキストの一節の簡潔な概要を生成します。
ヘルパーファンクション aidb.summarize_text_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
model |
TEXT |
Required |
要約に使用する登録モデルの名前。 |
chunk_config |
JSONB |
NULL |
要約前に適用されるオプションのチャンク構成`aidb.chunk_text_config()`から 。 |
prompt |
TEXT |
NULL |
概要をガイドするカスタムプロンプト。省略すると標準のプロンプトを使用します。 |
strategy |
TEXT |
NULL |
'append'`デフォルトはチャンクごとのサマリーを連結し、'reduce'`は反復圧縮します。 |
reduction_factor |
INTEGER |
NULL |
`'reduce'`ストラテジーで使用されます。反復ごとにテキストをどの程度積極的に削減するかを制御しますデフォルトは3です。 |
inference_config |
JSONB |
NULL |
オプションの実行時推論設定`aidb.inference_config()`から。 |
SELECT aidb.create_pipeline(
name => summary_pipeline,
source => articles_table,
source_key_column => id,
source_data_column => body,
step_1 => SummarizeText,
step_1_options => aidb.summarize_text_config(
model => my_t5_model,
chunk_config => aidb.chunk_text_config(100, 120, 10, words),
prompt => Summarize the key points concisely,
strategy => reduce,
reduction_factor => 3
),
step_2 => KnowledgeBase,
step_2_options => aidb.knowledge_base_config(model => bert, data_format => Text)
);
ナレッジベース#
処理されたテキストまたは画像データをベクター埋め込みに変換し、検索可能なナレッジベースに保存します。このステップは、その出力が後続のステップで入力として使用できないVECTOR
タイプであるため、常にパイプラインの 最後のステップ
である必要があります。セマンティック検索またはハイブリッド検索を使用したナレッジベースの照会については、
Knowledge bases reference を参照してください。
ヘルパーファンクション aidb.knowledge_base_config()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
model |
TEXT |
Required |
埋め込みモデルの名前。 |
data_format |
aidb.PipelineDataFormat |
Required |
'Text'`または'Image'`。 |
distance_operator |
aidb.DistanceOperator |
NULL |
類似度メトリック L2`デフォルト `Cosine、または`InnerProduct` |
vector_index |
JSONB |
NULL |
`aidb.vector_index_hnsw_config()`などのベクターインデックスヘルパーでビルドされたベクターインデックス構成。 |
SELECT aidb.create_pipeline(
name => kb_pipeline,
source => source_table,
source_key_column => id,
source_data_column => content,
step_1 => KnowledgeBase,
step_1_options => aidb.knowledge_base_config(
model => bert,
data_format => Text,
distance_operator => Cosine,
vector_index => aidb.vector_index_hnsw_config(m => 16, ef_construction => 64)
)
);
複数のパイプラインを同じナレッジベースにリンクするには、代わりにaidb.knowledge_base_config_from_kb(data_format)
を使用します。この手法は、既存のナレッジベースからモデルと距離オペレーター設定を継承します。
宛先テーブル#
KnowledgeBaseステップは、次のスキーマを使用してpipeline_<pipeline_name>
という名前の宛先テーブルを自動的に作成します。
Column |
Type |
Description |
|---|---|---|
id |
BIGSERIAL |
主キー。 |
pipeline_id |
INT |
元のパイプラインへの参照。 |
source_id |
TEXT |
元のソースレコードのID。 |
part_ids |
BIGINT[] |
データがチャンクまたは解析された場合、セグメントを追跡します。 |
value |
VECTOR |
pgvector埋め込み。 |
マルチパイプラインのナレッジベース#
単一のナレッジベースで、複数のパイプラインからエンベディングを集約できます。内部knowledge_base_pipeline
ジャンクションテーブルは、これらのマッピングを管理します。
aidb.retrieve_text()
を介して結果を取得する場合、各行にはpipeline_name
列が含まれるため、各エンベディングを生成したパイプラインを特定できます。
ナレッジベースのビューと統計については、 Knowledge bases reference を参照してください。
完全なエンドツーエンドのワークフローで一緒に使用されるパイプラインステップを確認するには、 Examples を参照してください。