redis-developer / redis-as-a-vector-database

A companion codebase for the Explainer Video Redis as a Vector Database
1 stars 2 forks source link

numeric ID #1

Closed AhmedFathyDev closed 1 month ago

AhmedFathyDev commented 1 month ago
book = {
    "id": 1, ###################### Me adding the id ######################
    "title": "Fire In His Spirit",
    "author": "Ruby Dixon",
    "score": "3.94",
    "votes": "2754",
    "description": "Gwen’s never wanted to be a leader, but when no one else stepped up, she took on the role. As the mayor of post-apocalyptic Shreveport, she’s made decisions to protect her people... and most of them have backfired disastrously. When she discovers that the dangerous gold dragon lurking outside of the fort has decided she’s his mate, heartsick Gwen thinks that the best thing she can do is confront him and take him far away from the city. She does this to save her people - her sister, her friends, her fort. She doesn’t expect to understand the dragon. She certainly doesn’t expect to fall in love.",
    "year_published": "2018",
    "url": "http://www.goodreads.com/book/show/40790825-fire-in-his-spirit",
    "genres": ["Romance", "Fantasy (Dragons)", "Fantasy", "Romance (Paranormal Romance)", "Fantasy (Paranormal)", "Science Fiction", "Paranormal (Shapeshifters)", "Science Fiction (Aliens)", "Science Fiction (Dystopia)", "Apocalyptic (Post Apocalyptic)"],
    "editions": ["English", "Japanese", "Arabic", "French"],
    "pages": 241
}

and schema is

schema = {
    "index": {
        "name": "book_index",
        "prefix": "book",
        "storage_type": "json",
    },
    "fields": [
        {"name": "id", "type": "numeric"}, ###################### Updated to 'numeric' ######################
        {"name": "$.editions[*]", "type": "tag"},
        {"name": "$.genres[*]", "type": "tag"},
        {"name": "author", "type": "text"},
        {"name": "description", "type": "text"},
        {"name": "title", "type": "text"},
        {"name": "pages", "type": "numeric"},
        {"name": "$.year_published", "type": "numeric"},
        {"name": "$.votes", "type": "numeric"},
        {"name": "$.score", "type": "numeric"},
        {
            "name": "embedding",
            "type": "vector",
            "attrs": {
                "dims": 384,
                "distance_metric": "cosine",
                "algorithm": "flat",
                "datatype": "float32",
            },
        },
    ],
}

I tried this, and the 'id' is an auto-generated string from Redis like this 'id': 'book:fd4349b359d14222932c7349f3436883' How can I make the 'id' numeric to set it myself?

AhmedFathyDev commented 1 month ago

I should made this. I didn't know id_field.

index.load(data=[book], id_field="id")