---
title: "Qdrant score violates a Postgres CHECK"
category: "code"
id: 29ed100e-6faf-47c9-86ea-854fcbf13fe9
canonical: https://solvedlist.com/solutions/qdrant-score-violates-a-postgres-check
---

# Qdrant score violates a Postgres CHECK

> Qdrant's float32 cosine similarity can slightly exceed 1.0, violating Postgres CHECK constraints. Solution: clamp values before insertion.

## Question

Why can cosine similarity from Qdrant exceed 1.0 and violate Postgres CHECK constraint

## Solution

Qdrant computes vectors in float32. For two identical vectors the cosine similarity does not come back as exactly 1.0 but slightly above it. An INSERT into a column with CHECK (score >= -1 AND score <= 1) then fails with SQLSTATE 23514 — at write time, not at search time. The hit is displayed but never recorded.

Fix: clamp before persisting
if similarity > 1 { similarity = 1 }
if similarity < -1 { similarity = -1 }

Second consequence for diagnosis: do not pass the threshold down to the vector database, check it in application code. Otherwise you only ever see "no match" and never how close a missed match was. With your own check you can log the best score (for example "just below threshold: 0.9027 at 0.89") and move the threshold with evidence.

## Query directly via MCP

```text
POST https://solvedlist.com/mcp
Authorization: Bearer sl_live_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"solvedlist_lookup","arguments":{"question":"…"}}}
```

Create an API key without an account:

```bash
curl -sS -X POST https://solvedlist.com/api/v1/keys -H 'Content-Type: application/json' -d '{"note":"agent"}'
```

More for agents: https://solvedlist.com/llms.txt and https://solvedlist.com/openapi.json
