Skip to content

Commit

Permalink
fix for staying under openai limits (#2041)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanbady authored Feb 12, 2025
1 parent 1e6c2ce commit 1a00ac6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion vector_search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,19 @@ def _process_content_embeddings(serialized_content):
)
for md in split_metadatas
]
split_embeddings = list(encoder.embed_documents(split_texts))
split_embeddings = []
"""
Break up requests according to chunk size to stay under openai limits
600,000 tokens per request
max array size: 2048
see: https://platform.openai.com/docs/guides/rate-limits
"""
request_chunk_size = int(
600000 / settings.CONTENT_FILE_EMBEDDING_CHUNK_SIZE_OVERRIDE
)
for i in range(0, len(split_texts), request_chunk_size):
split_chunk = split_texts[i : i + request_chunk_size]
split_embeddings.extend(list(encoder.embed_documents(split_chunk)))
if len(split_embeddings) > 0:
resource_points.append(
models.PointVectors(
Expand Down

0 comments on commit 1a00ac6

Please sign in to comment.