Skip to content

feat(templates): add openai-vector-store-search template - #656

Open
jacobdanner wants to merge 2 commits into
twilio-labs:mainfrom
jacobdanner:template_fna-serverless_openai_vector-search
Open

jacobdanner wants to merge 2 commits into
twilio-labs:mainfrom
jacobdanner:template_fna-serverless_openai_vector-search

Conversation

@jacobdanner

Copy link
Copy Markdown

Description

Adds a new openai-vector-store-search Function template that queries an OpenAI Vector Store for the documents most relevant to a search query, using the official openai Node SDK.

  • /search Function — accepts query (required) plus optional vector_store_id, max_num_results, filters, score_threshold, and rewrite_query, and returns the raw OpenAI search response. Falls back to an OPENAI_VECTOR_STORE_ID env var when a request doesn't supply its own vector_store_id, and trims whitespace from either source before use (a stray leading/trailing space in an env var otherwise produces a confusing 400 from OpenAI).
  • Self-contained package — the template's own package.json declares all of its dependencies/devDependencies and its own test/lint/format scripts, ESLint/Prettier config, and ignore files, so it can be copied out of this workspace and run standalone (npm install && npm test with no access to the repo root).
  • Tests — an SDK-mocked suite (tests/search.test.js, 12 cases) plus a small nock-based suite (tests/search.endpoint.test.js) that lets the real SDK build and send its HTTP request and intercepts it at the network layer, to catch drift between what we assume the SDK sends and what it actually sends.
  • scripts/smoke-test.js (npm run smoke-test) — hits a real deployed /search endpoint via FNA_SERVERLESS_EMBEDDINGS_ENDPOINT to verify a deployment works end-to-end, not just against local mocks.
  • Also fixes a path bug in _helpers/template-docs.js that broke automatic regeneration of docs/templates.md (it wrote to a path relative to process.cwd() instead of __dirname), and regenerates that file — which is why the diff includes updates to several unrelated templates' listings.

A note for reviewers

Pre-existing, unrelated to this change: npm run lint and npm test at the repo root currently fail even on main —

  • international-telephone-input/functions/lookup.js has 3 multiline-comment-style violations that predate this branch (confirmed identical to origin/main), which trips the whole-repo npm run lint (and the pre-push hook, and this repo's nodejs.yml CI).
  • 10 unrelated test suites (video-token, voice-client-javascript, sync-token, chat-token, google-sheets, covid-vaccine-faq-bot, etc.) fail under the current Node version, unrelated to this PR.

openai-vector-store-search's own tests and lint are clean in isolation (npx eslint --ext js openai-vector-store-search, npx jest openai-vector-store-search — 0 errors, 12/12 passing). Flagging so the repo-wide CI failure isn't mistaken for something this PR introduced.

Checklist

  • I ran npm test locally and it passed without errors.
  • I acknowledge that all my contributions will be made under the project's license.

Related issues

Adds a new Function template that queries an OpenAI Vector Store for the
documents most relevant to a search query, using the official openai Node
SDK. Accepts a query plus optional vector_store_id, max_num_results,
filters, score_threshold, and rewrite_query, and returns the raw OpenAI
search response. Falls back to an OPENAI_VECTOR_STORE_ID env var when no
vector_store_id is provided in the request, and trims whitespace from
either source before use.

The template is self-contained: its own package.json declares all
dependencies and devDependencies (including test/lint/format scripts and
config) so it can be copied out of the workspace and run standalone. Tests
cover both an SDK-mocked suite and a small nock-based suite that exercises
the real HTTP request/response shape. A scripts/smoke-test.js script
(exposed via `npm run smoke-test`) hits a live deployed endpoint via the
FNA_SERVERLESS_EMBEDDINGS_ENDPOINT env var to verify a deployment actually
works end-to-end.

Also fixes a path bug in _helpers/template-docs.js that broke automatic
regeneration of docs/templates.md, and regenerates that file.
@jacobdanner
jacobdanner requested review from a team as code owners September 2, 2026 18:00

This branch has not been deployed

No deployments
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.

1 participant