> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Vector Search

## Overview

*Kinetica's* vector search capability is enabled through its use as a vector
store database.  Once a table has been created with `vector` type and a set of
embeddings have been loaded into the table, a variety of K-nearest neighbor
searches can be performed on the data set.

Details on the `vector` type and its usage are found below.  For more complete
walkthroughs of the functionality in Jupyter notebook form, see:

* [Vector Dataframe I/O Demo](https://github.com/kineticadb/examples/blob/master/python_dev_guide/python_vector_io.ipynb)
* [Vector Similarity Search Demo](https://github.com/kineticadb/examples/blob/master/python_dev_guide/python_vector_search.ipynb)

<a id="vector-type" />

## Vector Type

The `vector` [data type](/content/concepts/types#types-chart) has been added to
facilitate managing embeddings and issuing vector search queries.  The
`vector` type is effectively an array of `float` types and can be used as
shown in the following examples.

### Create Table

A `vector` column can optionally be configured to normalize the vector data
inserted into it, giving each vector a magnitude (L2 norm) of *1*.  This can
improve the performance of some vector operations with minimal overhead.

#### Vector Column without Normalization

<CodeGroup>
  ```sql SQL theme={null}
  CREATE OR REPLACE TABLE example.vs
  (
  	name VARCHAR(16) NOT NULL,
  	embedding VECTOR(3) NOT NULL
  )
  ```

  ```python Python (native API) theme={null}
  table_name = 'example.vs'
  columns = [
      ['name', 'string', 'char16'],
      ['embedding', 'bytes', 'vector(3)']
  ]

  gpudb.GPUdbTable(columns, table_name, db = kinetica)
  ```

  ```python Python (from DataFrame) theme={null}
  table_name = 'example.vs'
  vs = gpudb.GPUdbTable.from_df(df, kinetica, table_name, clear_table = True)
  ```
</CodeGroup>

#### Vector Column with Normalization

<CodeGroup>
  ```sql SQL theme={null}
  CREATE OR REPLACE TABLE example.vs_norm
  (
  	name VARCHAR(16) NOT NULL,
  	embedding VECTOR(3, NORMALIZE) NOT NULL
  )
  ```

  ```python Python (native API) theme={null}
  table_name = 'example.vs_norm'
  columns = [
      ['name', 'string', 'char16'],
      ['embedding', 'bytes', 'vector(3)', 'normalize']
  ]

  vs = gpudb.GPUdbTable(columns, table_name, db = kinetica)
  ```

  ```python Python (from DataFrame) theme={null}
  table_name = 'example.vs_norm'

  vs = gpudb.GPUdbTable.from_df(
          df, kinetica, table_name, clear_table = True,
          column_types = { 'embedding': [ 'vector(3)', 'normalize' ] }
  )
  ```
</CodeGroup>

### Insert Data

<CodeGroup>
  ```sql SQL theme={null}
  INSERT INTO example.vs
  VALUES
  	('fun','[-0.23764,0.43119,-0.72154]'),
  	('play','[-0.73571,0.19937,-0.89408]'),
  	('food','[0.47222,-0.44545,-0.51833]'),
  	('money','[0.59784,-0.057026,0.97746]'),
  	('work','[0.51359,0.19695,-0.51944]')
  ```

  ```python Python (as strings) theme={null}
  embs = [
      ['fun', '[-0.23764,0.43119,-0.72154]'],
      ['play', '[-0.73571,0.19937,-0.89408]'],
      ['food', '[0.47222,-0.44545,-0.51833]'],
      ['money', '[0.59784,-0.057026,0.97746]'],
      ['work', '[0.51359,0.19695,-0.51944]']
  ]

  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  vs.insert_records(embs)
  ```

  ```python Python (as native types) theme={null}
  embs = [
      ['fun', [-0.23764,0.43119,-0.72154]],
      ['play', [-0.73571,0.19937,-0.89408]],
      ['food', [0.47222,-0.44545,-0.51833]],
      ['money', [0.59784,-0.057026,0.97746]],
      ['work', [0.51359,0.19695,-0.51944]]
  ]

  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  vs.insert_records(embs)
  ```

  ```python Python (as DataFrame) theme={null}
  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  vs.insert_df(df, batch_size = 10000)
  ```
</CodeGroup>

### Retrieve Data

<CodeGroup>
  ```sql SQL theme={null}
  SELECT name, embedding
  FROM example.vs
  ```

  ```python Python (w/o native type conversions) theme={null}
  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  records = vs.get_records()

  dim = 3

  print('%-16s %s' % ('Name', 'Embedding'))
  for record in records:
      print('%-16s %s' % (record[0], list(struct.unpack('%df'%dim, record[1]))))
  ```

  ```python Python (w/ native type conversions) theme={null}
  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica, convert_special_types_on_retrieval = True)

  records = vs.get_records(encoding = 'json')

  print('%-16s %s' % ('Name', 'Embedding'))
  for record in records:
      print('%-16s %s' % (record["name"], record["embedding"]))
  ```

  ```python Python (as DataFrame) theme={null}
  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  df = vs.to_df()

  print(df)
  ```
</CodeGroup>

<a id="vector-index" />

## Vector Indexes

There are two types of indexes available to improve the performance of vector
searches:

* [CAGRA index](/content/vector_search#vector-index-cagra)
* [HNSW index](/content/vector_search#vector-index-hnsw)

<a id="vector-index-cagra" />

### CAGRA Vector Index

The performance of some vector searches can be improved with the application of
a [CAGRA index](/content/concepts/indexes#cagra-index), which must be manually refreshed to
account for updates to the data in the corresponding table.

This can be applied, in SQL, during table creation, via
[CREATE TABLE](/content/sql/ddl#sql-create-table), as well as afterwards, as below:

<CodeGroup>
  ```sql SQL theme={null}
  ALTER TABLE example.employee
  ADD CAGRA INDEX (profile)
  ```

  ```python Python theme={null}
  retobj = kinetica.alter_table(
      table_name = "example.employee",
      action = "create_index",
      value = "profile",
      options = {
              "index_type": "cagra"
      }
  )
  ```
</CodeGroup>

<a id="vector-index-hnsw" />

### HNSW Vector Index

The performance of some vector searches can be improved with the application of
an [HNSW index](/content/concepts/indexes#hnsw-index), which is automatically updated as the
data in the corresponding table changes.

This can be applied, in SQL, during table creation, via
[CREATE TABLE](/content/sql/ddl#sql-create-table), as well as afterwards, as below:

<CodeGroup>
  ```sql SQL theme={null}
  ALTER TABLE example.employee
  ADD HNSW INDEX (profile)
  ```

  ```python Python theme={null}
  retobj = kinetica.alter_table(
      table_name = "example.employee",
      action = "create_index",
      value = "profile",
      options = {
              "index_type": "hnsw"
      }
  )
  ```
</CodeGroup>

<a id="vector-func" />

## Vector Functions & Operators

<a id="vector-func-column" />

### Vector Column Functions

<AccordionGroup>
  <Accordion title="L1_NORM(v)" id="l1_norm-v" defaultOpen>
    Calculates the sum of the absolute values of the given vector's values
  </Accordion>

  <Accordion title="L2_NORM(v)" id="l2_norm-v" defaultOpen>
    Calculates the square root of the sum of squares of the given vector's values
  </Accordion>

  <Accordion title="LINF_NORM(v)" id="linf_norm-v" defaultOpen>
    Returns the maximum of the given vector's values
  </Accordion>

  <Accordion title="LP_NORM(v, p)" id="lp_norm-v-p" defaultOpen>
    Calculates the Lp-space norm of the given vector in the space `p`
  </Accordion>

  <Accordion title="NTH(v, n)" id="nth-v-n" defaultOpen>
    Returns the given vector's value at 0-based index `n`
  </Accordion>

  <Accordion title="SIZE(v)" id="size-v" defaultOpen>
    Returns the given vector's number of values
  </Accordion>
</AccordionGroup>

<a id="vector-func-search" />

### Vector Search Functions

A number of K-nearest neighbor functions have been implemented to support vector
searches.  For examples, see [Vector Function Examples](/content/vector_search#vector-ex-func).

<AccordionGroup>
  <Accordion title="COSINE_DISTANCE(v1, v2)" id="cosine_distance-v1-v2" defaultOpen>
    *1* minus the *cosine similarity* (equality of angle) of the given vectors
  </Accordion>

  <Accordion title="DOT_PRODUCT(v1, v2)" id="dot_product-v1-v2" defaultOpen>
    Calculates the sum of products of the given vectors' values
  </Accordion>

  <Accordion title="EUCLIDEAN_DISTANCE(v1, v2)" id="euclidean_distance-v1-v2" defaultOpen>
    Alias for `L2_DISTANCE`
  </Accordion>

  <Accordion title="L1_DISTANCE(v1, v2)" id="l1_distance-v1-v2" defaultOpen>
    Calculates the L1-space (taxicab) distance between the given vectors
  </Accordion>

  <Accordion title="L2_DISTANCE(v1, v2)" id="l2_distance-v1-v2" defaultOpen>
    Calculates the L2-space (Euclidean) distance between the given vectors
  </Accordion>

  <Accordion title="L2_SQUAREDDISTANCE(v1, v2)" id="l2_squareddistance-v1-v2" defaultOpen>
    Calculates the sum of squares of distances between the given vectors' values
  </Accordion>

  <Accordion title="L2_DISTSQ(v1, v2)" id="l2_distsq-v1-v2" defaultOpen>
    Alias for `L2_SQUAREDDISTANCE`
  </Accordion>

  <Accordion title="LINF_DISTANCE(v1, v2)" id="linf_distance-v1-v2" defaultOpen>
    Calculates the maximum of the distances between pairs of values in the given vectors
  </Accordion>

  <Accordion title="LP_DISTANCE(v1, v2, p)" id="lp_distance-v1-v2-p" defaultOpen>
    Calculates the Lp-space distance between the given vectors in the space `p`
  </Accordion>
</AccordionGroup>

<a id="vector-oper" />

### Vector Search Operators

These operators can be used as shorthand to apply vector functions to individual
`vector` column values.  For examples, see [Vector Operator Examples](/content/vector_search#vector-ex-oper).

<Info>
  These operators are only available in SQL or in the native API via
  [/execute/sql](/content/api/rest/execute_sql_rest).
</Info>

| Operator    | Equivalent Function       |
| ----------- | ------------------------- |
| `v1 <-> v2` | `L2_DISTANCE(v1, v2)`     |
| `v1 <=> v2` | `COSINE_DISTANCE(v1, v2)` |
| `v1 <#> v2` | `DOT_PRODUCT(v1, v2)`     |

<a id="vector-ex" />

## Vector Search Examples

Vector searches can be performed using either
[named functions](/content/vector_search#vector-func-search) or the corresponding
[operators](/content/vector_search#vector-oper) for select functions.

<a id="vector-ex-oper" />

### Vector Operator Examples

<CodeGroup>
  ```sql SQL Literal theme={null}
  SELECT TOP 5 name, embedding <-> VECTOR('[-0.23764,0.43119,-0.72154]', 3) as distance
  FROM example.vs
  ORDER BY distance
  ```

  ```sql SQL Lookup theme={null}
  SELECT TOP 5 name, embedding <-> search_embedding as distance
  FROM
  	example.vs,
  	(SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
  WHERE name <> 'fun'
  ORDER BY distance
  ```

  ```python Python Literal theme={null}
  sql = """
      SELECT TOP 5 name, embedding <-> VECTOR('[-0.23764,0.43119,-0.72154]', 3) as distance
      FROM example.vs
      ORDER BY distance
  """

  with gpudb.GPUdbSqlIterator(kinetica, sql) as records:

      print('%-16s %s' % ('Name', 'Distance'))
      for record in records:
          print('%-16s %f' % (record[0], record[1]))
  ```

  ```python Python Lookup w/ SQL theme={null}
  sql = """
      SELECT TOP 5 name, embedding <-> search_embedding as distance
      FROM
          example.vs,
          (SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
      WHERE name <> 'fun'
      ORDER BY distance
  """

  with gpudb.GPUdbSqlIterator(kinetica, sql) as records:

      print('%-16s %s' % ('Name', 'Distance'))
      for record in records:
          print('%-16s %f' % (record[0], record[1]))
  ```

  ```python Python Literal to DataFrame theme={null}
  sql = """
      SELECT TOP 5 name, embedding <-> VECTOR('[-0.23764,0.43119,-0.72154]', 3) as distance
      FROM example.vs
      ORDER BY distance
  """

  df = kinetica.to_df(sql)

  print(df)
  ```

  ```python Python Lookup w/ SQL to DataFrame theme={null}
  sql = """
      SELECT TOP 5 name, embedding <-> search_embedding as distance
      FROM
          example.vs,
          (SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
      WHERE name <> 'fun'
      ORDER BY distance
  """

  df = kinetica.to_df(sql)

  print(df)
  ```
</CodeGroup>

<a id="vector-ex-func" />

### Vector Function Examples

<CodeGroup>
  ```sql SQL Literal theme={null}
  SELECT TOP 5 name, L2_DISTANCE(embedding,'[-0.23764,0.43119,-0.72154]') as distance
  FROM example.vs
  ORDER BY distance
  ```

  ```sql SQL Lookup theme={null}
  SELECT TOP 5 name, L2_DISTANCE(embedding, search_embedding) as distance
  FROM
  	example.vs,
  	(SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
  WHERE name <> 'fun'
  ORDER BY distance
  ```

  ```python Python Literal theme={null}
  vs = gpudb.GPUdbTable(name = 'example.vs', db = kinetica)

  records = vs.get_records_by_column(
          ["name", "L2_DISTANCE(embedding,'[-0.23764,0.43119,-0.72154]') as distance"],
          limit = 5,
          options = {"sort_by": "distance"}
  )

  print('%-16s %s' % ('Name', 'Distance'))
  for record in zip(records['name'], records['distance']):
      print('%-16s %f' % (record[0], record[1]))
  ```

  ```python Python Lookup w/ SQL theme={null}
  sql = """
      SELECT TOP 5 name, L2_DISTANCE(embedding, search_embedding) as distance
      FROM
          example.vs,
          (SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
      WHERE name <> 'fun'
      ORDER BY distance
  """

  with gpudb.GPUdbSqlIterator(kinetica, sql) as records:

      print('%-16s %s' % ('Name', 'Distance'))
      for record in records:
          print('%-16s %f' % (record[0], record[1]))
  ```

  ```python Python Literal to DataFrame theme={null}
  sql = """
      SELECT TOP 5 name, L2_DISTANCE(embedding,'[-0.23764,0.43119,-0.72154]') as distance
      FROM example.vs
      ORDER BY distance
  """

  df = kinetica.to_df(sql)

  print(df)
  ```

  ```python Python Lookup w/ SQL to DataFrame theme={null}
  sql = """
      SELECT TOP 5 name, L2_DISTANCE(embedding, search_embedding) as distance
      FROM
          example.vs,
          (SELECT embedding AS search_embedding FROM example.vs WHERE name = 'fun')
      WHERE name <> 'fun'
      ORDER BY distance
  """

  df = kinetica.to_df(sql)

  print(df)
  ```
</CodeGroup>

<a id="vector-model" />

## Embedding Models

*Kinetica* supports three different embedding models:

* *SQLGPT*: the default model, based on the OpenAI model at `sqlgpt.io`, with
  a maximum of 8191 tokens and a maximum returned vector size of 1536

* *OpenAI*: either of these models can be used:

  * `text-embedding-3-small`
  * `text-embedding-3-large`

  See [OpenAI documentation](https://platform.openai.com/docs/guides/embeddings/) for details.

* *Nvidia*: a NIM microservice, like `embed-qa-4` can be used, with a maximum
  of 512 tokens and a fixed returned vector size of 1024; an input type of
  `query` or `passage` must be specified for the model to generate the
  appropriate response text

  See [Nvidia Preview](https://build.nvidia.com/nvidia/embed-qa-4) for a demo.

*Kinetica* Also supports the deployment of a local model.

To deploy the Nvidia Nemo microservice, a server with 16GB of VRAM and access
to download the container is required.  See the [Nvidia Nemo documentation](https://developer.nvidia.com/docs/nemo-microservices/embedding/source/deploy.html) for
details.

<a id="vector-model-create" />

### CREATE MODEL

Creates a new [embedding model](/content/vector_search#vector-model) reference.

```sql title="CREATE MODEL Syntax" theme={null}
CREATE [OR REPLACE] [REMOTE] MODEL <model name>
WITH OPTIONS
(
    [CREDENTIAL = '[<credential_schema_name>.]<credential name>',]
    REMOTE_MODEL_NAME = '<remote model name>',
    REMOTE_MODEL_LOCATION = '<remote model location>'
)
```

<AccordionGroup>
  <Accordion title="OR REPLACE" id="or-replace" defaultOpen>
    Any existing *model* with the same name will be dropped before creating this one
  </Accordion>

  <Accordion title="REMOTE" id="remote" defaultOpen>
    Optional keyword for compatibility
  </Accordion>

  <Accordion title="<model name>" id="<model-name>" defaultOpen>
    Name of the *model* to create; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="WITH OPTIONS" id="with-options" defaultOpen>
    Indicator that a comma-delimited list of *model* option/value assignments will follow.
  </Accordion>

  <Accordion title="CREDENTIAL" id="credential" defaultOpen>
    [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to *model* service.
  </Accordion>

  <Accordion title="REMOTE_MODEL_NAME" id="remote_model_name" defaultOpen>
    Name of the *model* hosted by the embedding service; e.g., `NV-Embed-QA`.
  </Accordion>

  <Accordion title="REMOTE_MODEL_LOCATION" id="remote_model_location" defaultOpen>
    URL of the *model* host service.
  </Accordion>
</AccordionGroup>

For example, to create a remote model, first create an API key *credential*:

<CodeGroup>
  ```sql OpenAI API Credential Example theme={null}
  CREATE CREDENTIAL example.openai_api_cred
  TYPE = 'openai_api_key',
  SECRET = 'sk-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
  ```

  ```sql Nvidia API Credential Example theme={null}
  CREATE CREDENTIAL example.nvidia_api_cred
  TYPE = 'nvidia_api_key',
  SECRET = 'nvapi-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
  ```
</CodeGroup>

Then, create the model:

<CodeGroup>
  ```sql OpenAI Model Example theme={null}
  CREATE MODEL openai_remote_model
  WITH OPTIONS
  (
  	CREDENTIAL = 'example.openai_api_cred',
  	REMOTE_MODEL_NAME = 'text-embedding-3-small',
  	REMOTE_MODEL_LOCATION = 'https://api.openai.com/v1/embeddings'
  )
  ```

  ```sql Nvidia Remote Model Example theme={null}
  CREATE MODEL nvidia_remote_model
  WITH OPTIONS
  (
  	CREDENTIAL = 'example.nvidia_api_cred',
  	REMOTE_MODEL_NAME = 'NV-Embed-QA',
  	REMOTE_MODEL_LOCATION = 'https://ai.api.nvidia.com/v1/retrieval/nvidia/embeddings'
  )
  ```

  ```sql Nvidia Local (No Key) Model Example theme={null}
  CREATE MODEL nvidia_local_model
  WITH OPTIONS
  (
  	REMOTE_MODEL_NAME = 'NV-Embed-QA',
  	REMOTE_MODEL_LOCATION = 'http://localhost:8180/v1/embeddings'
  )
  ```
</CodeGroup>

Optionally, set the model as the default one:

<CodeGroup>
  ```sql OpenAI Default Model Example theme={null}
  ALTER SYSTEM SET PROPERTIES ('ai_api_embeddings_model' = 'openai_remote_model')
  ```

  ```sql Nvidia Default Remote Model Example theme={null}
  ALTER SYSTEM SET PROPERTIES ('ai_api_embeddings_model' = 'nvidia_remote_model')
  ```

  ```sql Nvidia Default Local (No Key) Model Example theme={null}
  ALTER SYSTEM SET PROPERTIES ('ai_api_embeddings_model' = 'nvidia_local_model')
  ```
</CodeGroup>

<a id="vector-model-alter" />

### ALTER MODEL

Alters the configuration of an existing
[embedding model](/content/vector_search#vector-model) reference.  Any of the model
configuration parameters can be modified individually.

```sql title="ALTER MODEL Syntax" theme={null}
ALTER MODEL <model name>
SET
<
    CREDENTIAL = '[<credential_schema_name>.]<credential name>'
    |
    REMOTE_MODEL_NAME = '<remote model name>'
    |
    REMOTE_MODEL_LOCATION = '<remote model location>'
>
```

<AccordionGroup>
  <Accordion title="<model name>" id="<model-name>-2" defaultOpen>
    Name of the *model* to modify; must adhere to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria)
  </Accordion>

  <Accordion title="CREDENTIAL" id="credential-2" defaultOpen>
    [Credential](/content/sql/ddl#sql-create-credential) object to use to authenticate to *model* service.
  </Accordion>

  <Accordion title="REMOTE_MODEL_NAME" id="remote_model_name-2" defaultOpen>
    Name of the *model* hosted by the embedding service; e.g., `NV-Embed-QA`.
  </Accordion>

  <Accordion title="REMOTE_MODEL_LOCATION" id="remote_model_location-2" defaultOpen>
    URL of the *model* host service.
  </Accordion>
</AccordionGroup>

For example, to change the name of the remote model referenced:

```sql ALTER MODEL Example theme={null}
ALTER MODEL openai_remote_model
SET REMOTE_MODEL_NAME = 'text-embedding-3-small'
```

<a id="vector-model-generate-embeddings" />

### GENERATE\_EMBEDDINGS

Generates embeddings for the specified input data using the specified
[embedding model](/content/vector_search#vector-model) reference.

```sql title="GENERATE_EMBEDDINGS Syntax" theme={null}
SELECT *
FROM TABLE [/* KI_HINT_SAVE_UDF_STATS */]
(
    GENERATE_EMBEDDINGS
    (
        [MODEL_NAME => '<model name>',]
        EMBEDDING_TABLE => INPUT_TABLE(<table name | query>),
        EMBEDDING_INPUT_COLUMNS => '<comma-delimited input column list>',
        [EMBEDDING_OUTPUT_COLUMNS => '<comma-delimited output column list>',]
        [DIMENSIONS => <dimensions>,]
        [PARAMS => KV_PAIRS('input_type' = <'query' | 'passage'>)]
    )
)
```

<AccordionGroup>
  <Accordion title="KI_HINT_SAVE_UDF_STATS" id="ki_hint_save_udf_stats" defaultOpen>
    SQL hint to log the embedding generation results of the UDF responsible for the processing
    (`rag_udf_embed`), so the logs can be viewed from the *Jobs* tab in
    [Workbench](/content/admin/workbench/ui/jobs).
  </Accordion>

  <Accordion title="MODEL_NAME" id="model_name" defaultOpen>
    Name of the *model* to use in generating embeddings, adhering to the supported
    [naming criteria](/content/sql/naming#sql-naming-criteria); if not specified, the default model, `sqlgpt`,
    will be used.

    To set the default to another model and avoid having to specify this parameter:

    ```sql Set Default Embeddings Model Example theme={null}
    ALTER SYSTEM SET PROPERTIES ('ai_api_embeddings_model' = 'nvidia_remote_model')
    ```
  </Accordion>

  <Accordion title="EMBEDDING_TABLE" id="embedding_table" defaultOpen>
    The query or name of the table to use for input data to the embedding generation process.
  </Accordion>

  <Accordion title="EMBEDDING_INPUT_COLUMNS" id="embedding_input_columns" defaultOpen>
    Names of the columns in the given `EMBEDDING_TABLE` for which embeddings will be generated.
  </Accordion>

  <Accordion title="EMBEDDING_OUTPUT_COLUMNS" id="embedding_output_columns" defaultOpen>
    Names of the columns to return the generated embeddings as; if none specified, each input column
    will have `_embedding` appended to it to construct the name of the corresponding output column.
  </Accordion>

  <Accordion title="DIMENSIONS" id="dimensions" defaultOpen>
    Size of the vector returned by the embedding generation process; required for the default
    `sqlgpt` model.
  </Accordion>

  <Accordion title="PARAMS" id="params" defaultOpen>
    Optional indicator that a list of embedding option/value assignments will follow, passed as a
    comma-delimited list of key/value pairs to the `KV_PAIRS` function

    <div>
      <table class="table w-full [&_td]:min-w-[150px] [&_th]:text-left [&_td[data-numeric]]:tabular-nums">
        <thead>
          <tr>
            <th>Option</th>
            <th>Description</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td><code>input\_type</code></td>
            <td>For Nvidia models, the type of input on which embeddings will be generated: <ul><li><code>passage</code> - Input is the data set that will be searched.</li><li><code>query</code>   - Input is the query that will be used for the search.</li></ul></td>
          </tr>
        </tbody>
      </table>
    </div>
  </Accordion>
</AccordionGroup>

For example, to generate embeddings with various models:

<CodeGroup>
  ```sql Generate Embeddings (Default) Example theme={null}
  SELECT * FROM TABLE /* KI_HINT_SAVE_UDF_STATS */
  (
  	GENERATE_EMBEDDINGS
  	(
  		EMBEDDING_TABLE => INPUT_TABLE(SELECT * FROM example.fine_food_reviews WHERE Score > 3),
  		EMBEDDING_INPUT_COLUMNS => 'Summary,Text',
  		DIMENSIONS => 256
  	)
  )
  ```

  ```sql Generate Embeddings (OpenAI) Example theme={null}
  SELECT * FROM TABLE /* KI_HINT_SAVE_UDF_STATS */
  (
  	GENERATE_EMBEDDINGS
  	(
  		MODEL_NAME => 'openai_remote_model',
  		EMBEDDING_TABLE => INPUT_TABLE(example.fine_food_reviews),
  		EMBEDDING_INPUT_COLUMNS => 'Summary,Text',
  		EMBEDDING_OUTPUT_COLUMNS => 'Summary_emb,Text_emb',
  		DIMENSIONS => 1536
  	)
  )
  ```

  ```sql Generate Source Embeddings (Nvidia) Example theme={null}
  SELECT * FROM TABLE /* KI_HINT_SAVE_UDF_STATS */
  (
  	GENERATE_EMBEDDINGS
  	(
  		MODEL_NAME => 'nvidia_remote_model',
  		EMBEDDING_TABLE => INPUT_TABLE(SELECT * FROM example.fine_food_reviews WHERE Score > 3),
  		EMBEDDING_INPUT_COLUMNS => 'Summary,Text',
  		PARAMS => KV_PAIRS('input_type' = 'passage')
  	)
  )
  ```

  ```sql Generate Query Embeddings (Nvidia) Example theme={null}
  SELECT * FROM TABLE /* KI_HINT_SAVE_UDF_STATS */
  (
  	GENERATE_EMBEDDINGS
  	(
  		MODEL_NAME => 'nvidia_remote_model',
  		EMBEDDING_TABLE => INPUT_TABLE(SELECT 'healthy food' AS search_query),
  		EMBEDDING_INPUT_COLUMNS => 'search_query',
  		EMBEDDING_OUTPUT_COLUMNS => 'search_query_emb',
  		PARAMS => KV_PAIRS('input_type' = 'query')
  	)
  )
  ```
</CodeGroup>

<a id="vector-model-search" />

### Vector Search with Embedding Models

Using [embedding models](/content/vector_search#vector-model), vector searches can be
performed dynamically on a given data set.

For example, to search for *healthy food* references within a data set of
product reviews:

<CodeGroup>
  ```sql Vector Search with Embeddings (OpenAI) Example theme={null}
  SELECT /* KI_HINT_SAVE_UDF_STATS */
  	COSINE_DISTANCE(p.Text_emb, q.query_emb) as dist,
  	p.ProductId,
  	p.UserId,
  	p.Summary,
  	p.Text
  FROM
  	TABLE
  	(
  		GENERATE_EMBEDDINGS
  		(
  			MODEL_NAME => 'openai_remote_model',
  			EMBEDDING_TABLE => INPUT_TABLE(SELECT * FROM example.fine_food_reviews WHERE Score > 3),
  			EMBEDDING_INPUT_COLUMNS => 'Summary,Text',
  			EMBEDDING_OUTPUT_COLUMNS => 'Summary_emb,Text_emb',
  			DIMENSIONS => 1536
  		)
  	) p,
  	TABLE
  	(
  		GENERATE_EMBEDDINGS
  		(
  			MODEL_NAME => 'openai_remote_model',
  			EMBEDDING_TABLE => INPUT_TABLE(SELECT 'healthy food' AS query),
  			EMBEDDING_INPUT_COLUMNS => 'query',
  			EMBEDDING_OUTPUT_COLUMNS => 'query_emb',
  			DIMENSIONS => 1536
  		)
  	) q
  ORDER BY 1
  ```

  ```sql Vector Search with Embeddings (Nvidia) Example theme={null}
  SELECT /* KI_HINT_SAVE_UDF_STATS */
  	COSINE_DISTANCE(p.Text_emb, q.query_emb) as dist,
  	p.ProductId,
  	p.UserId,
  	p.Summary,
  	p.Text
  FROM
  	TABLE
  	(
  		GENERATE_EMBEDDINGS
  		(
  			MODEL_NAME => 'nvidia_remote_model',
  			EMBEDDING_TABLE => INPUT_TABLE(SELECT * FROM example.fine_food_reviews WHERE Score > 3),
  			EMBEDDING_INPUT_COLUMNS => 'Summary,Text',
  			EMBEDDING_OUTPUT_COLUMNS => 'Summary_emb,Text_emb',
  			PARAMS => KV_PAIRS('input_type' = 'passage')
  		)
  	) p,
  	TABLE
  	(
  		GENERATE_EMBEDDINGS
  		(
  			MODEL_NAME => 'nvidia_remote_model',
  			EMBEDDING_TABLE => INPUT_TABLE(SELECT 'healthy food' AS query),
  			EMBEDDING_INPUT_COLUMNS => 'query',
  			EMBEDDING_OUTPUT_COLUMNS => 'query_emb',
  			PARAMS => KV_PAIRS('input_type' = 'query')
  		)
  	) q
  ORDER BY 1
  ```
</CodeGroup>
