Skip to content

feat: add ai/embed connector for RAG#167

Merged
michaelmcnees merged 2 commits into
mainfrom
claude/office-assistant-mantle-feasibility-n8f4bk
Jul 2, 2026
Merged

feat: add ai/embed connector for RAG#167
michaelmcnees merged 2 commits into
mainfrom
claude/office-assistant-mantle-feasibility-n8f4bk

Conversation

@michaelmcnees

Copy link
Copy Markdown
Collaborator

Summary

First increment on RAG (#153): an ai/embed text-embeddings connector, plus a working pgvector RAG example. Together with the existing ai/completion, this lets you build retrieval-augmented generation on stock connectors — embed → store → nearest-neighbour search → grounded answer.

Changes

  • ai/embed connector (internal/connector/embed.go) — provider selection, base-URL/model allowlists, and AI metrics mirroring ai/completion. It lives under the ai/ prefix, so the engine's token-budget accounting applies automatically (it returns usage.total_tokens).
  • EmbeddingProvider interface + OpenAI implementation — covers OpenAI, Azure OpenAI, and OpenAI-compatible servers via base_url. Extracted the shared OpenAI credential-header logic so chat and embeddings reuse it.
  • pgvector-friendly output — each embedding is returned both as a float array (output.embedding) and as a pgvector text literal (output.vector, "[0.1,0.2,...]"), which binds straight into a postgres/query arg cast with ::vector. This removes the array-encoding friction of hand-building RAG.
  • Registration + config — registered ai/embed; serve applies the base-URL allowlist to it (the model allowlist is intentionally not shared, since it lists chat models).
  • Example + docsrag-kb-schema.sql (pgvector table + HNSW index), rag-ingest.yaml, rag-ask.yaml, a rag-guide doc, and an ai/embed entry in the connector reference.

Scope

This is the foundational slice of #153. Deliberately deferred (follow-ups on #153): Bedrock embeddings (needs InvokeModel + per-model shapes, distinct from the Converse API used for chat), and native kb/upsert / kb/query connectors + chunking. RAG is fully composable today from ai/embed + postgres/query + ai/completion, as the example shows.

Testing

  • go test ./internal/connector/ -run TestEmbedding (httptest-based) passes, plus the existing OpenAI provider tests (credential refactor is covered).
  • go build, go vet, gofmt, and golangci-lint run clean.
  • rag-ingest.yaml and rag-ask.yaml pass mantle validate.
  • End-to-end (real OpenAI + pgvector) needs live services, so it can't run in CI; the guide documents how to exercise it.

Related Issues

Part of #153 (RAG subsystem).


Generated by Claude Code

Adds a text-embeddings connector as the foundation for retrieval-augmented
generation.

- ai/embed connector (internal/connector/embed.go): provider selection,
  base-URL/model allowlists, and AI metrics mirroring ai/completion. It
  lives under the "ai/" prefix so the engine's token-budget accounting
  applies automatically (it returns usage.total_tokens).
- EmbeddingProvider interface + OpenAI implementation (also covers Azure
  OpenAI and OpenAI-compatible servers via base_url). Extracted the shared
  OpenAI credential-header logic used by chat and embeddings.
- Output includes a pgvector text literal (output.vector, "[...]") so an
  embedding drops straight into a postgres/query arg cast with ::vector,
  removing the array-encoding friction of building RAG by hand.
- Registered ai/embed; serve applies the base-URL allowlist to it.
- Example: pgvector RAG (rag-kb-schema.sql, rag-ingest.yaml,
  rag-ask.yaml), a rag-guide doc, and an ai/embed connector-reference
  entry. Both workflows pass `mantle validate`.

Scoped as the first RAG increment. Bedrock embeddings (InvokeModel) and
native kb/upsert / kb/query + chunking are planned follow-ups on #153.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WnKgCRfMvFcZAkoVbr8k79
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@michaelmcnees, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 29 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9e9cb83c-cf33-40bb-9aeb-1cdceff8e74d

📥 Commits

Reviewing files that changed from the base of the PR and between 32557fc and f8d4552.

📒 Files selected for processing (12)
  • .changeset/ai-embed-connector.md
  • packages/engine/internal/cli/serve.go
  • packages/engine/internal/connector/connector.go
  • packages/engine/internal/connector/embed.go
  • packages/engine/internal/connector/embed_test.go
  • packages/engine/internal/connector/provider.go
  • packages/engine/internal/connector/provider_openai.go
  • packages/site/src/content/docs/rag-guide.md
  • packages/site/src/content/docs/workflow-reference/connectors.md
  • packages/site/src/content/examples/rag-ask.yaml
  • packages/site/src/content/examples/rag-ingest.yaml
  • packages/site/src/content/examples/rag-kb-schema.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/office-assistant-mantle-feasibility-n8f4bk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07a6e7cdb8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +233 to +237
out := make([][]float64, len(apiResp.Data))
for _, d := range apiResp.Data {
if d.Index < 0 || d.Index >= len(out) {
return nil, fmt.Errorf("openai: embedding index %d out of range", d.Index)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate every requested embedding is returned

When an OpenAI-compatible endpoint returns fewer data items than requested or repeats an index, this builds the result slice from len(apiResp.Data) and never verifies that each requested input got exactly one embedding. A multi-input ai/embed step can then silently return a shorter vectors list or include an empty [] vector for a missing slot, causing downstream pgvector writes/queries to be associated with the wrong input instead of failing fast; size the output by len(req.Inputs) and reject missing/duplicate indexes.

Useful? React with 👍 / 👎.

Addresses PR review (Codex P2). The OpenAI embeddings parser sized the
result by len(data) and indexed by the API's index field, so a response
with fewer items than inputs — or a duplicate index — could silently
misalign embeddings with their inputs or leave an empty [] vector,
corrupting downstream pgvector writes/queries. Size the output by
len(req.Inputs) and reject out-of-range, duplicate, or missing indexes.
Adds a regression test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WnKgCRfMvFcZAkoVbr8k79
@michaelmcnees michaelmcnees merged commit fa2bb14 into main Jul 2, 2026
11 checks passed
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