get_collection - コレクションの取得
get_collection()は、指定されたコレクションを取得するために使用されます。
備考
このインターフェースは、Client接続を使用している場合にのみ利用できます。Clientの詳細については、Clientを参照してください。
前提条件
-
pyseekdbがインストール済みであること。pyseekdbのインストールに関する詳細は、クイックスタートを参照してください。
-
データベースに接続されていること。接続操作の詳細については、Clientを参照してください。
-
取得したCollectionが存在すること。Collectionが存在しない場合、エラーメッセージが表示されます。
リクエストパラメータ
client.get_collection(name,configuration = configuration,embedding_function = embedding_function)
| パラメータ | 値の種類 | 必須 | 説明 | 値の例 |
|---|---|---|---|---|
name | string | 必須 | 取得するコレクション名を指定します。 | my_collection |
Schema | vector_index | sparse_vector_index | fulltext_index | オプション | 次元と距離尺度を持つインデックスの設定です。指定しない場合、デフォルトで HNSW 密着インデックスと IK 分かち書き文字列解析器を使用した全文インデックスが使用されます。 | schema = Schema(vector_index=VectorIndexConfig(hnsw=HNSWConfiguration(dimension=384, distance="cosine") ),sparse_vector_index=SparseVectorIndexConfig(embedding_function=BM25EmbeddingFunction(), source_key="#document"), fulltext_index=FulltextIndexConfig(analyzer='ik', properties={'ik_mode':'max_words'})) |
embedding_function | EmbeddingFunction | オプション | convertをベクトルに変換する関数です。指定しない場合、DefaultEmbeddingFunction()()(384次元)が使用されます。None に設定した場合、コレクションに埋め込み機能は含まれません。埋め込み機能を提供する場合、configuration.dimension に基づいて自動的に計算されます。 | DefaultEmbeddingFunction() |
備考
documents/textsにvectorsが指定されていない場合、ここで設定されたembedding functionが、add、upsert、update、query、hybrid_searchを含む、このcollectionに対するすべての操作で使用されます。
リクエスト例
import pyseekdb
# Create a client
client = pyseekdb.Client()
# Get an existing collection (uses default embedding function if collection doesn't have one)
collection = client.get_collection("my_collection")
print(f"Database: {collection.name}, dimension: {collection.dimension}, embedding_function:{collection.embedding_function}, distance:{collection.distance}, metadata:{collection.metadata}")
# Get collection with specific embedding function
ef = UserDefinedEmbeddingFunction() // define your own Embedding function, See section.6
collection = client.get_collection("my_collection", embedding_function=ef)
print(f"Database: {collection.name}, dimension: {collection.dimension}, embedding_function:{collection.embedding_function}, distance:{collection.distance}, metadata:{collection.metadata}")
# Get collection without embedding function
collection = client.get_collection("my_collection", embedding_function=None)
# Check if collection exists
if client.has_collection("my_collection"):
collection = client.get_collection("my_collection")
print(f"Database: {collection.name}, dimension: {collection.dimension}, embedding_function:{collection.embedding_function}, distance:{collection.distance}, metadata:{collection.metadata}")
レスポンスパラメータ
| パラメータ | 戻り値の型 | 必須 | 説明 | 戻り値の例 |
|---|---|---|---|---|
name | string | 必須 | 検索するコレクション名を指定します。 | my_collection |
dimension | int | オプション | 384 | |
embedding_function | EmbeddingFunction | オプション | DefaultEmbeddingFunction(model_name='all-MiniLM-L6-v2') | |
distance | string | オプション | cosine | |
metadata | dict | オプション | 予約フィールド、現在データなし |
レスポンス例
Database: my_collection, dimension: 384, embedding_function:DefaultEmbeddingFunction(model_name='all-MiniLM-L6-v2'), distance:cosine, metadata:{}
Database: my_collection1, dimension: 384, embedding_function:DefaultEmbeddingFunction(model_name='all-MiniLM-L6-v2'), distance:cosine, metadata:{}