# US 2023/0273940 A1 · Distributed approximate nearest neighbor service architecture for retrieving items in an embedding space

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2023/0273940 A1
- Document ID: US20230273940A1
- Status: Published application
- Kind: A1
- Application number: 17/682,187
- Filed: 2022-02-28
- Published: 2023-08-31
- Earliest claimed: 2022-02-28
- Assignees: Maplebear, Inc.(dba Instacart)
- Applicants: Maplebear Inc. (dba Instacart)
- Inventors: Guanghua Shu; Taesik Na; Zhihong Xu; Wideet Shende; Manmeet Singh; Tejaswi Tenneti; Reza Sadri
- Web page: https://patentgrep.com/patent/US20230273940A1

## CPC

- G06F 16/2237: {Vectors, bitmaps or matrices}
- G06F 16/283: {Multi-dimensional databases or data warehouses, e.g. MOLAP or ROLAP}
- G06F 11/3409: {for performance assessment}
- G06F 16/2228: {Indexing structures}
- G06F 16/2255: {Hash tables}
- G06F 16/245: Query processing
- G06F 16/24556: {Aggregation; Duplicate elimination}
- G06F 16/285: {Clustering or classification}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

An online system maintains item embeddings for items. As a number of items maintained by the online system increases, maintaining a single index of the item embeddings is increasingly difficult. To increase scalability, the online system partitions item embeddings into multiple indices, with each index corresponding to a value of a specific attribute maintained by the online system for items. For example, an online system generates indices that each correspond to a different warehouse offering items. To expedite retrieval of item embeddings, the online system allocates each index to one of a number of shards. When the online system receives a query, the online system determines an embedding for the query and retrieves an index from a shard based on metadata received with the query. Based on distances between the query for the embedding and the item embeddings in the retrieved index, the online system selects one or more items.

## Claims

### Claim 1

A method comprising:
generating item embeddings for each of a plurality of items maintained in an item database by an online system, each item embedding representing an item in the latent space;
identifying a specific attribute associated with items maintained by the online system from attributes of items maintained by the item database;
determining a value of the specific attribute maintained for each item of the item database;
generating a plurality of indices, each index corresponding to a particular value of the specific attribute and including item embeddings for items having the particular value for the selected specific attribute, different indices corresponding to different particular values; and
for each index of the plurality of indices:
selecting a shard to include an index of the plurality of indices; and
storing the index of the plurality of indices in the selected shard.

### Claim 2 (depends on 1)

The method of claim 1, wherein selecting the shard to include the index of the plurality of indices comprises:
determining a number of shards;
generating a hash code for the index of the plurality of indices by applying a hash function to the particular value of the specific attribute corresponding to the index of the plurality of indices; and
determining a shard identifier of the shard to include the index of the plurality of indices as the hash code for the index of the plurality of indices modulo the number of shards.

### Claim 3 (depends on 1)

The method of claim 1, wherein selecting the shard to include the index of the plurality of indices comprises:
identifying a specific shard;
determining an aggregate frequency of access for the specific shard as a combination of frequencies with which indices stored in the specific shard were accessed by the online system;
identifying an additional shard;
determining a combined frequency of access for the additional shard as a combination of a frequency with which the index of the plurality of indices was accessed by the online system and frequencies with which shards stored in the additional shard were accessed by the online system; and
selecting the additional shard to include the index of the plurality of indices in response to the combined frequency of access for the additional shard being within a threshold amount of the aggregate frequency of access for the specific shard.

### Claim 4 (depends on 1)

The method of claim 1, wherein selecting the shard to include the index of the plurality of indices comprises:
determining an aggregate frequency of access to the indices by combining frequencies with which each index was accessed;
determining a target frequency of access for each shard as a ratio of the aggregate frequency of access to a number of shards; and
selecting the shard to include the index of the plurality of indices so a combination of frequencies with which the online system accesses indices within the shard is within a threshold amount of the target frequency of access.

### Claim 5 (depends on 1)

The method of claim 1, wherein the specific attribute comprises a warehouse associated with one or more items.

### Claim 6 (depends on 1)

The method of claim 1, wherein the specific attribute comprises an inventory area associated with one or more items.

### Claim 7 (depends on 1)

The method of claim 1, further comprising:
receiving, at the online system, a query;
identifying an index based on metadata received in conjunction with the query;
retrieving the identified index from a shard including the identified index.
generating an embedding for the query; and
comparing the embedding for the query to item embeddings included in the identified index.

### Claim 8

A computer program product comprising a non-transitory computer readable storage medium having instructions encoded thereon that, when executed by a processor, cause the processor to:
generate item embeddings for each of a plurality of items maintained in an item database by an online system, each item embedding representing an item in the latent space;
identify a specific attribute associated with items maintained by the online system from attributes of items maintained by the item database;
determine a value of the specific attribute maintained for each item of the item database;
generate a plurality of indices, each index corresponding to a particular value of the specific attribute and including item embeddings for items having the particular value for the selected specific attribute, different indices corresponding to different particular values; and
for each index of the plurality of indices:
select a shard to include an index of the plurality of indices; and
store the index of the plurality of indices in the selected shard.

### Claim 9 (depends on 8)

The computer program product of claim 8, wherein selecting the shard to include the index of the plurality of indices comprises:
determining a number of shards;
generating a hash code for the index of the plurality of indices by applying a hash function to the particular value of the specific attribute corresponding to the index of the plurality of indices; and
determining a shard identifier of the shard for the index of the plurality of indices as the hash code for the index of the plurality of indices modulo the number of shards.

### Claim 10 (depends on 8)

The computer program product of claim 8, wherein selecting the shard to include the index of the plurality of indices comprises:
identifying a specific shard;
determining an aggregate frequency of access for the specific shard as a combination of frequencies with which indices stored in the specific shard were accessed by the online system;
identifying an additional shard;
determining a combined frequency of access for the additional shard as a combination of a frequency with which the index of the plurality of indices was accessed by the online system and frequencies with which shards stored in the additional shard were accessed by the online system; and
selecting the additional shard to include the index of the plurality of indices in response to the combined frequency of access for the additional shard being within a threshold amount of the aggregate frequency of access for the specific shard.

### Claim 11 (depends on 8)

The computer program product of claim 8, wherein selecting the shard to include the index of the plurality of indices comprises:
determining an aggregate frequency of access to the indices by combining frequencies with which each index was accessed;
determining a target frequency of access for each shard as a ratio of the aggregate frequency of access to a number of shards; and
determining the shard to include the index of the plurality of indices so a combination of frequencies with which the online system accesses indices within the shard is within a threshold amount of the target frequency of access.

### Claim 12 (depends on 8)

The computer program product of claim 8, wherein the specific attribute comprises a warehouse associated with one or more items.

### Claim 13 (depends on 8)

The computer program product of claim 8, wherein the specific attribute comprises an inventory area associated with one or more items.

### Claim 14 (depends on 8)

The computer program product of claim 8, wherein the non-transitory computer readable storage medium further has instructions encoded thereon that, when executed by the processor, cause the processor to:
receive, at the online system, a query;
identify an index based on metadata received in conjunction with the query;
retrieve the identified index from a shard including the identified index.
generate an embedding for the query; and
compare the embedding for the query to item embeddings included in the identified index.

### Claim 15

A system comprising:
a processor;
a non-transitory computer readable storage medium coupled to the processor and having instructions encoded thereon that, when executed by the processor, cause the processor to:
generate item embeddings for each of a plurality of items maintained in an item database by an online system, each item embedding representing an item in the latent space;
identify a specific attribute associated with items maintained by the online system from attributes of items maintained by the item database;
determine a value of the specific attribute maintained for each item of the item database;
generate a plurality of indices, each index corresponding to a particular value of the specific attribute and including item embeddings for items having the particular value for the selected specific attribute, different indices corresponding to different particular values; and
for each index of the plurality of indices:
select a shard to include an index of the plurality of indices; and
store the index of the plurality of indices in the selected shard.

### Claim 16 (depends on 15)

The system of claim 15, wherein selecting the shard to include the index of the plurality of indices comprises:
determining a number of shards;
generating a hash code for the index of the plurality of indices by applying a hash function to the particular value of the specific attribute corresponding to the index of the plurality of indices; and
determining a shard identifier of the shard for the index of the plurality of indices as the hash code for the index of the plurality of indices modulo the number of shards.

### Claim 17 (depends on 15)

The system of claim 15, wherein selecting the shard to include the index of the plurality of indices comprises:
identifying a specific shard;
determining an aggregate frequency of access for the specific shard as a combination of frequencies with which indices stored in the specific shard were accessed by the online system;
identifying an additional shard;
determining a combined frequency of access for the additional shard as a combination of a frequency with which the index of the plurality of indices was accessed by the online system and frequencies with which shards stored in the additional shard were accessed by the online system; and
selecting the additional shard to include the index of the plurality of indices in response to the combined frequency of access for the additional shard being within a threshold amount of the aggregate frequency of access for the specific shard.

### Claim 18 (depends on 15)

The system of claim 15, wherein selecting the shard to include the index of the plurality of indices comprises:
determining an aggregate frequency of access to the indices by combining frequencies with which each index was accessed;
determining a target frequency of access for each shard as a ratio of the aggregate frequency of access to a number of shards; and
determining the shard to include the index of the plurality of indices so a combination of frequencies with which the online system accesses indices within the shard is within a threshold amount of the target frequency of access.

### Claim 19 (depends on 15)

The system of claim 15, wherein the specific attribute comprises a warehouse associated with one or more items.

### Claim 20 (depends on 15)

The system of claim 15, wherein the non-transitory computer readable storage medium further has instructions encoded thereon that, when executed by the processor, cause the processor to:
receive, at the online system, a query;
identify an index based on metadata received in conjunction with the query;
retrieve the identified index from a shard including the identified index.
generate an embedding for the query; and
compare the embedding for the query to item embeddings included in the identified index.
