cockroachdb / cockroachdb/sequelize-cockroachdb

Add (native) VECTOR data type support

Đang mở
#158 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
55
Fork
18
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

More recent CockroachDB versions (I think 25+) added the data type VECTOR for storing fixed-length arrays of floating-point numbers, which represent data points in multi-dimensional space. It is often used for vector search in applications with LLMs, e.g. RAG (retrieval augmented generation). See the [docs](https://www.cockroachlabs.com/docs/stable/vector) for more info.

As such, having support for this data type in sequelize-cockroachdb would be quite nice to enable such applications using CockroachDB, Sequelize and NodeJS.

The type VECTOR does not exist currently in sequelize-cockroachdb, also using ARRAY is not possible due to syntax mismatches between handling ARRAY and VECTOR in SQL. The workaround I'm using now (and documenting here for others stumbling upon this problem) is defining the column data type as STRING in the schema (but as VECTOR in the actual database) and then manually converting an array of floats to the format required by CockroachDB using JSON.stringify().

```javascript
//Schema file
...
embedding: {
type: Sequelize.DataTypes.STRING, //Should be VECTOR when supported
allowNull: true
},
...
```

Inserting/updating data in this column can be done like this:

```javascript
// Update data in VECTOR column
let embedding = [-0.03704405203461647, 0.024347146973013878, -0.007968421094119549, ...];
await model.update({ embedding: JSON.stringify(embedding) });
```

Querying works with literals:
```javascript
let queryEmbedding = [-0.03704405203461647, 0.024347146973013878, -0.007968421094119549, ...];
let results = await model.findAll({
where: Sequelize.literal(`embedding <=> '${JSON.stringify(queryEmbedding)}'::vector < 0.5`)
});
```

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.