Skip to Content

Astra Vector Store

AstraVector クラスは、Apache Cassandra 上に構築されたクラウドネイティブでサーバーレスのデータベースである DataStax Astra DB を使用したベクター検索を提供します。 エンタープライズグレードのスケーラビリティと高可用性を備えたベクター検索機能を提供します。

コンストラクタオプション

token:

string
Astra DB API トークン

endpoint:

string
Astra DB API エンドポイント

keyspace?:

string
オプションのキースペース名

メソッド

createIndex()

indexName:

string
作成するインデックスの名前

dimension:

number
ベクトルの次元(埋め込みモデルに一致する必要があります)

metric?:

'cosine' | 'euclidean' | 'dotproduct'
= cosine
類似性検索のための距離メトリック(dotproductの場合はdot_productにマップされます)

upsert()

indexName:

string
アップサートするインデックスの名前

vectors:

number[][]
埋め込みベクトルの配列

metadata?:

Record<string, any>[]
各ベクトルのメタデータ

ids?:

string[]
オプションのベクトルID(提供されない場合は自動生成されます)

query()

indexName:

string
クエリを実行するインデックスの名前

queryVector:

number[]
類似ベクトルを見つけるためのクエリベクトル

topK?:

number
= 10
返す結果の数

filter?:

Record<string, any>
クエリのメタデータフィルター

includeVector?:

boolean
= false
結果にベクトルを含めるかどうか

listIndexes()

文字列としてインデックス名の配列を返します。

describeIndex()

indexName:

string
説明するインデックスの名前

返される内容:

interface IndexStats { dimension: number; count: number; metric: "cosine" | "euclidean" | "dotproduct"; }

deleteIndex()

indexName:

string
削除するインデックスの名前

updateIndexById()

indexName:

string
ベクトルを含むインデックスの名前

id:

string
更新するベクトルのID

update:

object
ベクトルおよび/またはメタデータの変更を含む更新オブジェクト
number[]
Record<string, any>

deleteIndexById()

indexName:

string
ベクトルを含むインデックスの名前

id:

string
削除するベクトルのID

レスポンスタイプ

クエリ結果はこの形式で返されます:

interface QueryResult { id: string; score: number; metadata: Record<string, any>; vector?: number[]; // Only included if includeVector is true }

エラーハンドリング

ストアはキャッチ可能な型付きエラーをスローします:

try { await store.query({ indexName: "index_name", queryVector: queryVector, }); } catch (error) { if (error instanceof VectorStoreError) { console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc console.log(error.details); // 追加のエラーコンテキスト } }

環境変数

必要な環境変数:

  • ASTRA_DB_TOKEN: あなたのAstra DB APIトークン
  • ASTRA_DB_ENDPOINT: あなたのAstra DB APIエンドポイント

関連