Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index-deletion #297

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add index deletion, linting catastrophe.
  • Loading branch information
bmschmidt committed Apr 25, 2024
commit 3ab6ba792f3c6106b24450367eb4d715434509bf
19 changes: 1 addition & 18 deletions nomic/aws/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ def embed_texts(
region_name: str,
task_type: str = "search_document",
batch_size: int = 32,
dimensionality: int = 768,
binary: bool = False,
):
"""
Embed a list of texts using a sagemaker model endpoint.
Expand All @@ -141,8 +139,6 @@ def embed_texts(
region_name: AWS region sagemaker endpoint is in.
task_type: The task type to use when embedding.
batch_size: Size of each batch. Default is 32.
dimensionality: Number of dimensions to return. Options are (64, 128, 256, 512, 768).
binary: Whether to return binary embeddings.

Returns:
Dictionary with "embeddings" (python 2d list of floats), "model" (sagemaker endpoint used to generate embeddings).
Expand All @@ -153,25 +149,12 @@ def embed_texts(
return None

texts = preprocess_texts(texts, task_type)
assert dimensionality in (
64,
128,
256,
512,
768,
), f"Invalid number of dimensions: {dimensionality}"

client = boto3.client("sagemaker-runtime", region_name=region_name)
embeddings = []

for i in tqdm(range(0, len(texts), batch_size)):
batch = json.dumps(
{
"texts": texts[i : i + batch_size],
"binary": binary,
"dimensionality": dimensionality,
}
)
batch = json.dumps({"texts": texts[i : i + batch_size]})
response = client.invoke_endpoint(EndpointName=sagemaker_endpoint, Body=batch, ContentType="application/json")
embeddings.extend(parse_sagemaker_response(response))

Expand Down
Loading