Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(node, lancedb): unable to 'add' to a table created with a Float64 vector #1293

Open
universalmind303 opened this issue May 10, 2024 · 1 comment
Labels
bug Something isn't working typescript Typescript / javascript

Comments

@universalmind303
Copy link
Contributor

LanceDB version

@lancedb/lancedb main

What happened?

if you try to create a table with a specific schema, then try to add data to it, it seems that the arrow conversion does not account for the schema and tries to instead convert the array to a Float32 vector

Are there known steps to reproduce?

import lancedb from "@lancedb/lancedb";


const db = await lancedb.connect("/tmp/lancedb");

const data = [
  {text: "hello", vector: Array(512).fill(1.0)},
  {text: "hello world", vector: Array(512).fill(1.0)},
]
const f64Schema = new Schema([
  new Field("text", new Utf8(), true),
  new Field("vector", new FixedSizeList(512, new Field("item", new Float64())), true)
]);

let f64Table = await db.createEmptyTable("f64", f64Schema, {mode: "overwrite"})

await f64Table.add(data)
[Error: Failed to add batches to table f64: lance error: Append with different schema: `vector` should have type fixed_size_list:double:512 but type was fixed_size_list:float:512, location: /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lance-core-0.10.18/src/datatypes/schema.rs:150:27] {
@universalmind303 universalmind303 added bug Something isn't working typescript Typescript / javascript labels May 10, 2024
@Macbook-Specter
Copy link

I had the same problem. I couldn't create an empty table and then add data to it first.
"@lancedb/lancedb": "^0.5.0"
"apache-arrow": "^16.1.0"

const uri = "./db/sample-lancedb";
const db = await lancedb.connect(uri);
const document_fragment_schema = new Schema([
    new Field("id", new Float32(), false),
    new Field("fragment_content", new Utf8(), false),
    new Field("docment_id", new Float32(), false),
    new Field("vector", new FixedSizeList(2, new Field("vector_values", new Float32(), false)), false),
]);
const tb = db.createEmptyTable("document_fragment", document_fragment_schema);
await tb.add(
    [
        {
            id: 2,
            fragment_content: "hello world2",
            docment_id: 1,
            vector: [1, 2]
        },
        {
            id: 3,
            fragment_content: "hello world3",
            docment_id: 1,
            vector: [4, 8]
        },
    ]
);
const tb_schema = await tb.schema();
console.log(tb_schema);

const res = await tb.vectorSearch([5,6]).limit(3).toArray();
console.log(res);

node:internal/process/esm_loader:34
internalBinding('errors').triggerUncaughtException(
^

[Error: Failed to add batches to table document_fragment: lance error: Append with different schema: id should have type float but type was double, id should have nullable=false but nullable=true, fragment_content should have nullable=false but nullable=true, keywords should have nullable=false but nullable=true, docment_id should have type float but type was double, docment_id should have nullable=false but nullable=true, vector should have nullable=false but nullable=true, location: C:\Users\runneradmin.cargo\registry\src\index.crates.io-6f17d22bba15001f\lance-core-0.11.0\src\datatypes\schema.rs:150:27] {
code: 'GenericFailure'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript Typescript / javascript
Projects
None yet
Development

No branches or pull requests

2 participants