# SQLServer_VectorStore

> **Class** in `langchain_sqlserver`

📖 [View in docs](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore)

SQL Server Vector Store.

This class provides a vector store interface for adding texts and performing
    similarity searches on the texts in SQL Server.

## Signature

```python
SQLServer_VectorStore(
    self,
    *,
    connection: Optional[Connection] = None,
    connection_string: str,
    db_schema: Optional[str] = None,
    distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
    embedding_function: Embeddings,
    embedding_length: int,
    relevance_score_fn: Optional[Callable[[float], float]] = None,
    table_name: str = DEFAULT_TABLE_NAME,
    batch_size: int = DEFAULT_BATCH_SIZE,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `connection` | `Optional[Connection]` | No | Optional SQLServer connection. (default: `None`) |
| `connection_string` | `str` | Yes | SQLServer connection string. If the connection string does not contain a username & password or `TrustedConnection=yes`, Entra ID authentication is used. SQL Server ODBC connection string can be retrieved from the `Connection strings` pane of the database in Azure portal. Sample connection string format: - "Driver=<drivername>;Server=<servername>;Database=<dbname>; Uid=<username>;Pwd=<password>;TrustServerCertificate=no;" - "mssql+pyodbc://username:password@servername/dbname?other_params" |
| `db_schema` | `Optional[str]` | No | The schema in which the vector store will be created. This schema must exist and the user must have permissions to the schema. (default: `None`) |
| `distance_strategy` | `DistanceStrategy` | No | The distance strategy to use for comparing embeddings. Default value is COSINE. Available options are: - COSINE - DOT - EUCLIDEAN (default: `DEFAULT_DISTANCE_STRATEGY`) |
| `embedding_function` | `Embeddings` | Yes | Any embedding function implementing `langchain.embeddings.base.Embeddings` interface. |
| `embedding_length` | `int` | Yes | The length (dimension) of the vectors to be stored in the table. Note that only vectors of same size can be added to the vector store. |
| `relevance_score_fn` | `Optional[Callable[[float], float]]` | No | Relevance score funtion to be used. Optional param, defaults to None. (default: `None`) |
| `table_name` | `str` | No | The name of the table to use for storing embeddings. Default value is `sqlserver_vectorstore`. (default: `DEFAULT_TABLE_NAME`) |
| `batch_size` | `int` | No | Number of documents/texts to be inserted at once to Db, max 419. (default: `DEFAULT_BATCH_SIZE`) |

## Extends

- `VectorStore`

## Constructors

```python
__init__(
    self,
    *,
    connection: Optional[Connection] = None,
    connection_string: str,
    db_schema: Optional[str] = None,
    distance_strategy: DistanceStrategy = DEFAULT_DISTANCE_STRATEGY,
    embedding_function: Embeddings,
    embedding_length: int,
    relevance_score_fn: Optional[Callable[[float], float]] = None,
    table_name: str = DEFAULT_TABLE_NAME,
    batch_size: int = DEFAULT_BATCH_SIZE,
) -> None
```

| Name | Type |
|------|------|
| `connection` | `Optional[Connection]` |
| `connection_string` | `str` |
| `db_schema` | `Optional[str]` |
| `distance_strategy` | `DistanceStrategy` |
| `embedding_function` | `Embeddings` |
| `embedding_length` | `int` |
| `relevance_score_fn` | `Optional[Callable[[float], float]]` |
| `table_name` | `str` |
| `batch_size` | `int` |


## Properties

- `connection_string`
- `embedding_function`
- `schema`
- `override_relevance_score_fn`
- `table_name`
- `embeddings`
- `distance_strategy`
- `batch_size`

## Methods

- [`from_texts()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/from_texts)
- [`from_documents()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/from_documents)
- [`get_by_ids()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/get_by_ids)
- [`max_marginal_relevance_search()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/max_marginal_relevance_search)
- [`max_marginal_relevance_search_by_vector()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/max_marginal_relevance_search_by_vector)
- [`similarity_search()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/similarity_search)
- [`similarity_search_by_vector()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/similarity_search_by_vector)
- [`similarity_search_with_score()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/similarity_search_with_score)
- [`similarity_search_by_vector_with_score()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/similarity_search_by_vector_with_score)
- [`add_texts()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/add_texts)
- [`drop()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/drop)
- [`delete()`](https://reference.langchain.com/python/langchain-sqlserver/vectorstores/SQLServer_VectorStore/delete)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/a9ced94f3d1df3e39903b3650bd1b7ed9399f339/./libs/sqlserver/langchain_sqlserver/vectorstores.py#L172)