Skip to content

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Dec 31, 2025

Summary

Add embeddings API support to the Rust SDK.

Changes

  • Add create_embeddings() method to OpenSecretClient
  • Add EmbeddingRequest, EmbeddingResponse, EmbeddingInput, EmbeddingData, and EmbeddingUsage types
  • Add From trait implementations for convenient EmbeddingInput construction from strings
  • Add comprehensive integration tests for single and multiple input embeddings
  • Fix clippy warning on AttestationVerifier::Default impl

Testing

All new embedding tests pass with the nomic-embed-text model (768 dimensions).

Summary by CodeRabbit

  • New Features

    • Added embeddings support enabling generation of text vector representations; supports single and batch text inputs with configurable embedding model selection.
  • Tests

    • Added comprehensive integration tests validating embeddings generation across different input types and response structure integrity.

✏️ Tip: You can customize this high-level summary in your review settings.

Add create_embeddings() method supporting single and multiple text inputs
with EmbeddingRequest/EmbeddingResponse types and From trait implementations
for convenient input handling.

Also fixes clippy warning in attestation.rs.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 31, 2025

Deploying opensecret-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 698cb9b
Status: ✅  Deploy successful!
Preview URL: https://235f3e90.opensecret-sdk.pages.dev
Branch Preview URL: https://feat-embeddings-api.opensecret-sdk.pages.dev

View logs

@coderabbitai
Copy link

coderabbitai bot commented Dec 31, 2025

📝 Walkthrough

Walkthrough

This change adds embeddings API support to the OpenSecretClient by introducing new request and response types, implementing conversion traits for flexible input handling, and adding a create_embeddings method following existing encrypted OpenAI call patterns. Additionally, a Default trait implementation is added to AttestationVerifier, and integration tests are added for embeddings functionality.

Changes

Cohort / File(s) Summary
Attestation trait implementation
rust/src/attestation.rs
Implements Default trait for AttestationVerifier with expected_pcrs: None and allow_debug driven by mock-attestation feature flag. Includes clippy allow attribute.
Embeddings types and utilities
rust/src/types.rs
Introduces five new structs/enums: EmbeddingRequest, EmbeddingResponse, EmbeddingData, EmbeddingUsage, and EmbeddingInput. Adds default_embedding_model helper and From trait implementations to convert String/&str/Vec into EmbeddingInput.
Embeddings client method
rust/src/client.rs
Adds public async method create_embeddings to OpenSecretClient that sends POST to /v1/embeddings with EmbeddingRequest, using encrypted_openai_call pattern and returning decrypted EmbeddingResponse.
Embeddings integration tests
rust/tests/ai_integration.rs
Extends test setup with conditional login/registration flow. Adds three embedding test cases: single input, multiple inputs, and string conversion. Validates response structure, embedding dimension (768), usage tokens, and per-embedding attributes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Rust sdk implementation #42: Introduced the same Rust modules (attestation, client, types) being modified here and established the foundation for encrypted OpenAI API patterns now extended with embeddings support.

Poem

Through encrypted tunnels, embeddings now fly,
New types and methods reaching for the sky,
Default implementations bind them all tight,
Vectors dancing, 768 dimensions of light,
The secret garden grows, row by row! 🐰✨🔐

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change—adding embeddings API support to the Rust SDK. It is concise, specific, and directly reflects the primary focus of the changeset across all modified files.
✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 31, 2025

Greptile Summary

Added embeddings API support to the Rust SDK, enabling text-to-vector conversion through the /v1/embeddings endpoint. The implementation follows existing SDK patterns with encrypted communication and proper error handling.

Major Changes:

  • Added create_embeddings() method to OpenSecretClient that uses the encrypted OpenAI API call pattern
  • Created comprehensive type system (EmbeddingRequest, EmbeddingResponse, EmbeddingInput, EmbeddingData, EmbeddingUsage) with ergonomic From trait implementations for easy string-to-input conversion
  • Added three integration tests covering single input, multiple inputs, and string conversion convenience methods
  • Fixed clippy warning on AttestationVerifier::Default implementation
  • Enhanced test setup with automatic registration fallback when login fails

Implementation Quality:

  • Properly reuses encrypted_openai_call() for consistency with chat completions
  • Type-safe enum for EmbeddingInput supporting both single and batch operations
  • Default model set to "nomic-embed-text" (768 dimensions)
  • Tests verify response structure, dimensions, and token usage

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The implementation is clean, well-tested, and follows established SDK patterns. The embeddings API is properly integrated with the existing encrypted communication layer, types are comprehensive with convenient conversions, and comprehensive tests validate functionality. The clippy fix is a minor quality improvement. No security concerns, breaking changes, or logical errors were found.
  • No files require special attention

Important Files Changed

Filename Overview
rust/src/client.rs Added create_embeddings method with proper documentation and integration with encrypted OpenAI API calls
rust/src/types.rs Added comprehensive embeddings type definitions with convenient From trait implementations for EmbeddingInput
rust/tests/ai_integration.rs Added comprehensive embeddings tests and improved test setup with fallback registration logic

Sequence Diagram

sequenceDiagram
    participant Client as OpenSecretClient
    participant API as OpenSecret API
    participant Crypto as Encryption Layer
    
    Note over Client,API: Embeddings API Flow
    
    Client->>Client: Create EmbeddingRequest
    Note right of Client: input: String or Vec<String><br/>model: "nomic-embed-text"
    
    Client->>Crypto: Encrypt request with session key
    Crypto-->>Client: Encrypted payload
    
    Client->>API: POST /v1/embeddings<br/>(encrypted + session-id header)
    Note right of Client: Uses encrypted_openai_call()<br/>Supports API key or JWT auth
    
    API->>API: Decrypt request
    API->>API: Generate embeddings
    API->>API: Encrypt response
    
    API-->>Client: Encrypted EmbeddingResponse
    
    Client->>Crypto: Decrypt response
    Crypto-->>Client: Decrypted data
    
    Client->>Client: Parse EmbeddingResponse
    Note left of Client: Returns:<br/>- data: Vec<EmbeddingData><br/>- usage: token counts<br/>- model info
    
    Client-->>Client: Return Result<EmbeddingResponse>
Loading

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
rust/src/types.rs (1)

485-508: Excellent ergonomic design with From trait implementations.

The #[serde(untagged)] attribute on EmbeddingInput allows flexible JSON serialization (either a single string or an array of strings), and the From trait implementations provide convenient construction. The API feels natural and type-safe.

💡 Optional: Consider adding From<&[String]> for slice references

If you want to avoid an allocation when passing a borrowed slice:

+impl From<&[String]> for EmbeddingInput {
+    fn from(v: &[String]) -> Self {
+        EmbeddingInput::Multiple(v.to_vec())
+    }
+}

This is optional and only beneficial if callers frequently have &[String] rather than Vec<String>.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4793bde and 698cb9b.

📒 Files selected for processing (4)
  • rust/src/attestation.rs
  • rust/src/client.rs
  • rust/src/types.rs
  • rust/tests/ai_integration.rs
🧰 Additional context used
🧬 Code graph analysis (1)
rust/tests/ai_integration.rs (1)
rust/tests/api_keys.rs (1)
  • env (24-26)
🪛 GitHub Actions: Rust CI
rust/tests/ai_integration.rs

[error] 255-255: Guest users should not be able to access models. Test failed: test_guest_user_cannot_use_ai in ai_integration; Process exited with code 101 while running 'cargo test --all-features'.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Greptile Review
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (7)
rust/src/attestation.rs (1)

29-37: LGTM! Clippy suppression is justified.

The #[allow(clippy::derivable_impls)] attribute is appropriate here because the allow_debug field uses cfg!(feature = "mock-attestation"), which cannot be expressed in a derived Default implementation. The delegation from new() to default() is good practice.

rust/src/types.rs (2)

467-479: LGTM! Well-structured request type.

The EmbeddingRequest follows OpenAI API conventions with appropriate defaults. The use of default_embedding_model() for the model field provides a sensible default while allowing customization.


510-529: Response types correctly match OpenAI API structure.

The EmbeddingResponse, EmbeddingData, and EmbeddingUsage types accurately model the API response. Using Vec<f64> for embeddings is appropriate for the floating-point vectors returned by embedding models.

rust/src/client.rs (1)

969-985: Excellent implementation following established patterns.

The create_embeddings method properly reuses the encrypted_openai_call helper, ensuring consistent encryption and authentication behavior with other OpenAI endpoints. The doc comment provides a clear usage example.

rust/tests/ai_integration.rs (3)

26-42: Good improvement to test setup robustness.

The try-login-first approach with fallback to registration makes the tests more resilient to repeated runs and avoids registration conflicts. The optional name parameter aligns with the registration API.


283-396: Comprehensive test coverage for embeddings functionality.

The three test cases provide excellent coverage:

  1. Single input validation with dimension checks (768 for nomic-embed-text)
  2. Multiple inputs with proper indexing verification
  3. Ergonomic string conversion via From traits

All assertions verify the response structure, embedding dimensions, and usage metrics appropriately.


224-281: Address unimplemented guest access restrictions test.

The test_guest_user_cannot_use_ai test was added in this PR but expects guest users to be denied access to models and completions. However, the SDK currently has no guest-specific authorization checks—get_models() and create_chat_completion() use the same session-based authentication for all user types, with no logic to distinguish or restrict guests. Either implement guest access enforcement on the server/SDK side, or remove/mark this test as #[ignore] if guest restrictions are not yet supported.

@AnthonyRonning AnthonyRonning merged commit a7df301 into master Dec 31, 2025
8 of 9 checks passed
@AnthonyRonning AnthonyRonning deleted the feat/embeddings-api branch December 31, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants