getCollection - コレクションを取得する
getCollection()は、指定されたコレクションを取得するために使用されます。
備考
このインターフェースは、SeekdbClient接続を使用する場合にのみ利用できます。SeekdbClientの詳細については、SeekdbClientを参照してください。
前提条件
-
seekdb-jsがインストール済みであること。seekdb-jsのインストール手順の詳細については、クイックスタートを参照してください。
-
サーバーモードのseekdbを使用している場合は、seekdbサーバーモードがインストールされていることを確認してください。seekdbサーバーモードのインストール手順の詳細については、パッケージ管理ツールによるseekdbのデプロイを参照してください。
-
データベースに接続されていること。接続操作の詳細については、SeekdbClientを参照してください。
-
取得するコレクションが存在すること。コレクションが存在しない場合は、エラーが表示されます。
リクエストパラメータ
getCollection(options: GetCollectionOptions)
| パラメータ | 値の種類 | 必須 | 説明 | 値の例 |
|---|---|---|---|---|
name | string | 必須 | 取得するコレクションの名前を指定します。 | my_collection |
embeddingFunction | EmbeddingFunction | null | オプション | 埋め込み関数。nullを指定すると、埋め込み関数は使用されません | DefaultEmbeddingFunction() |
備考
embeddingFunction (EmbeddingFunction、オプション): このコレクション用のベクトル関数
- 指定しない場合、
createCollectionで使用したembeddingfunctionをデフォルトで使用します。 - nullに設定すると、コレクションはベクトル関数を使用しません。
- ドキュメント/テキストは指定されているもののベクトルが指定されていない場合、ここで設定されたベクトル関数が、このコレクションのすべての操作(add, upsert, update, query, hybridSearch)に適用されます。
リクエスト例
import { SeekdbClient } from "seekdb";
// 1. Connect
// 埋め込みモード - データベース管理 (seekdb Embedded)
// const client = new SeekdbClient({
// path: "./seekdb.db",
// database: "test",
// });
// リモートサーバーモード - データベース管理 (seekdb Server)
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
// デフォルトの埋め込み関数を使用してコレクションを取得する
const collection = await client.getCollection({
name: 'my_collection'
});
// 埋め込み関数を使用しない
const collection2 = await client.getCollection({
name: 'my_collection',
embeddingFunction: null
});
戻り値パラメータ
| パラメータ | 戻り値の型 | 必須 | 説明 | 実行例 |
|---|---|---|---|---|
name | string | 必須 | 検索するコレクション名を指定します。 | my_collection |
dimension | int | オプション | 384 | |
embeddingFunction | EmbeddingFunction | オプション | DefaultEmbeddingFunction { name: 'default-embed', pipe: null, modelName: 'Xenova/all-MiniLM-L6-v2', revision: undefined, dtype: undefined, cacheDir: undefined, localFilesOnly: undefined, progressCallback: undefined } | |
distance | string | オプション | cosine | |
metadata | dict | オプション | 予約フィールド、現在データなし | undefined |
戻り値の例
Collection {
name: 'my_collection',
dimension: 384,
distance: 'cosine',
embeddingFunction: DefaultEmbeddingFunction {
name: 'default-embed',
pipe: null,
modelName: 'Xenova/all-MiniLM-L6-v2',
revision: undefined,
dtype: undefined,
cacheDir: undefined,
localFilesOnly: undefined,
progressCallback: undefined
},
metadata: undefined
}
Collection {
name: 'my_collection',
dimension: 384,
distance: 'cosine',
embeddingFunction: undefined,
metadata: undefined
}