メインコンテンツまでスキップ
バージョン: V1.3.0

get_collection - コレクションの取得

get_collection()は、指定されたコレクションを取得するために使用されます。

備考

このインターフェースは、Client接続を使用している場合にのみ利用できます。Clientの詳細については、Clientを参照してください。

前提条件​

  • pyseekdbがインストール済みであること。pyseekdbのインストールに関する詳細は、クイックスタートを参照してください。

  • データベースに接続されていること。接続操作の詳細については、Clientを参照してください。

  • 取得したCollectionが存在すること。Collectionが存在しない場合、エラーメッセージが表示されます。

リクエストパラメータ​

client.get_collection(name,configuration = configuration,embedding_function = embedding_function)
パラメータ値の種類必須説明値の例
namestring必須取得するコレクション名を指定します。my_collection
Schemavector_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_functionEmbeddingFunctionオプション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}")

レスポンスパラメータ​

パラメータ戻り値の型必須説明戻り値の例
namestring必須検索するコレクション名を指定します。my_collection
dimensionintオプション384
embedding_functionEmbeddingFunctionオプションDefaultEmbeddingFunction(model_name='all-MiniLM-L6-v2')
distancestringオプションcosine
metadatadictオプション予約フィールド、現在データなし

レスポンス例​

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:{}

関連操作​