bandarra.me

Building Composite Indexes for Firestore on Windows

The command on the Firestore docs to create a composite index that includes a vector embedding doesn't work out of the box on Windows. This seems to be related on how escaping JSON works on Powershell. The solution I found to run the command was to create a JSON file with the index definition, like so:

[
    {
        "field-path": "user_id",
        "order": "ASCENDING"
    },
    {
        "field-path": "embedding",
        "vector-config": {
            "dimension": 768,
            "flat": "{}"
        }
    }
]

Then, create the index with a command that reads the index details from the file, like this:

gcloud beta firestore indexes composite create `
    --collection-group=MyCollection `
    --query-scope=COLLECTION `
    --field-config=field-config.json `
    --database=mydatabase