--- slug: /get-collection-of-api --- # get_collection - Get a collection The `get_collection()` function is used to retrieve a specified collection. :::info This API is only available when connected using a Client. For more information about the Client, see [Client](../50.client.md). ::: ## Prerequisites * You have installed pyseekdb. For more information about how to install pyseekdb, see [Quick Start](../../10.pyseekdb-sdk/10.pyseekdb-sdk-get-started.md). * You have connected to the database. For more information about how to connect, see [Client](../50.client.md). * The collection you want to retrieve exists. If the collection does not exist, an error will be returned. ## Request parameters ```python 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 retrieve. |my_collection| |`configuration`|HNSWConfiguration|No|The index configuration, which specifies the dimension and distance metric. If not provided, the default value `dimension=384, distance='cosine'` will be used. If set to `None`, the dimension will be calculated from the `embedding_function` value. |HNSWConfiguration(dimension=384, distance='cosine')| |`embedding_function`|EmbeddingFunction|No|The function used to convert text to vectors. If not provided, `DefaultEmbeddingFunction()(384 dimensions)` will be used. If set to `None`, the collection will not contain an embedding function. If an embedding function is provided, it will be calculated based on `configuration.dimension`.|DefaultEmbeddingFunction()| :::info When vectors are not provided for documents/texts, the embedding function set here will be used for all operations on this collection, including add, upsert, update, query, and hybrid_search. ::: ## Request example ```python 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|Type|Required|Description|Example value| |---|---|---|---|---| |`name`|string|Yes|The name of the collection to query. |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, currently no data| {} | ## Response example ```python 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:{} ``` ## References * [Create a collection](100.create-collection-of-api.md) * [Create or query a collection](250.get-or-create-collection-of-api.md) * [Get a list of collections](300.list-collection-of-api.md) * [Count the number of collections](350.count-collection-of-api.md) * [Delete a collection](400.delete-collection-of-api.md)