get_collection - Get a collection
get_collection() is used to get the specified collection.
info
This API is only available when you are connected using Client. For more information about Client, see Client.
Prerequisites
-
You have installed pyseekdb. For more information about how to install pyseekdb, see Quick Start.
-
You have connected to the database. For more information about how to connect, see Client.
-
The collection you want to get exists. If the collection does not exist, an error is reported.
Request parameters
client.get_collection(name,configuration = configuration,embedding_function = embedding_function)
| Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|
name | string | Yes | The name of the collection to get. | my_collection |
Schema | vector_index | sparse_vector_index | fulltext_index | No | Index configuration that specifies vector dimensions and distance metrics. If omitted, the default is an HNSW dense index and a full-text index that uses the IK tokenizer. | 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 | No | Function used to convert input into vectors. If omitted, DefaultEmbeddingFunction() is used (384 dimensions). If set to None, the collection has no embedding capability. If an embedding function is provided, the dimension is determined automatically according to configuration.dimension. | DefaultEmbeddingFunction() |
info
When documents or texts are supplied without vectors, the embedding function set here is used for all operations on this collection, including add, upsert, update, query, and hybrid_search.
Request example
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}")
Response parameters
| Parameter | Return type | Required | Description | Example value |
|---|---|---|---|---|
name | string | Yes | The name of the collection. | my_collection |
dimension | int | No | 384 | |
embedding_function | EmbeddingFunction | No | DefaultEmbeddingFunction(model_name='all-MiniLM-L6-v2') | |
distance | string | No | cosine | |
metadata | dict | No | Reserved field; no data yet. |
Response example
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:{}