Every document must have a string _id field.

Every document is uniquely identified by its _id, which means that upserting a document with an existing _id will update the document.

To upsert documents, you can pass a list of documents to the upsert method. TopK will insert new documents or overwrite existing ones if they have the same _id.

client.collection("books").upsert(
    [
        {
            "_id": "book-1",
            "title": "The Great Gatsby", 
            "published_year": 1925, 
            "title_embedding": [0.12, 0.67, 0.82, 0.53, ...]
        },
        {
            "_id": "book-2",
            "title": "To Kill a Mockingbird",
            "published_year": 1960,
            "title_embedding": [0.42, 0.53, 0.65, 0.33, ...]
        },
        {
            "_id": "book-3", 
            "title": "1984", 
            "published_year": 1949, 
            "title_embedding": [0.59, 0.33, 0.71, 0.61, ...]
        }
    ]
)

Please note that nested types (eg. dicts and lists) are currently not supported. The only exception for complex types applies to f32 vectors, u8 vectors, binary vectors, and bytes.

Need support or want to give some feedback? You can join our community or drop us an email at support@topk.io.