Skip to content

Cohere ​

Hosted embeddings through Cohere's /v2/embed API. The key stays in providers.d on the inference host (the database machine in embedded mode, each postvec-server in remote mode).

Worker writes send search_document. search() sends search_query. Cohere applies the matching input type.

1. Add the provider ​

bash
sudo postvec provider add cohere --model embed-v4.0
postvec provider ls
sudo postvec doctor --database app

The command prompts for the key without echo, writes /etc/postvec/providers.d/cohere.toml (0600), probes the key with one embed call, reloads the host and refreshes postvec.models.

Expected

text
providers.d: /etc/postvec/providers.d
cohere  (cohere, key: inline (redacted))
  cohere-embed-v4-0                            dim 1536   served

doctor exits 0. The name is in postvec.models.

Built-in catalogue names:

--modelName in SQLDim
embed-v4.0cohere-embed-v4-01536
embed-english-v3.0cohere-embed-english-v3-01024
embed-multilingual-v3.0cohere-embed-multilingual-v3-01024

Pass --api-key-file PATH or --api-key-env VAR instead of the prompt. With --api-key-file the key stays in that file and provider ls reports file:PATH instead of inline.

v4 also accepts dim 256, 512 or 1024 (output_dimension). v3 widths are fixed per model (the -light- pair is 384). Pass --dim with --model embed-v4.0 to request a reduced width.

2. Bind a column ​

sql
SELECT postvec.enable('docs', 'body',
                      model => 'cohere-embed-v4-0');
-- NOTICE:  postvec: model "cohere-embed-v4-0" is served by
--          external provider "cohere"; source text from column "body" will
--          be sent to that provider for embedding

Expected

docs.body_semantic is vector(1536) at the default v4 width. pending_jobs returns to 0.

sql
SET postvec.query_timeout_ms = 10000;

SELECT postvec.create_vector_index('docs', 'body');
SELECT * FROM postvec.search('docs', 'body', 'revenue outlook', limit_n => 5);

On postvec-server ​

Run the add on a postvec-server node. The CLI finds no local cluster there and writes <server-root>/providers.d, the directory that node serves from:

bash
sudo postvec provider add cohere --model embed-v4.0 \
     --acknowledge-in-use --yes

Copy the same file onto every node, then reload each host. External providers covers keys, failures and moving a column off the provider.