feat(templates): add openai-vector-store-search template - #656
Open
jacobdanner wants to merge 2 commits into
Open
jacobdanner wants to merge 2 commits into
jacobdanner wants to merge 2 commits into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
openai-vector-store-searchFunction template that queries an OpenAI Vector Store for the documents most relevant to a search query, using the officialopenaiNode SDK./searchFunction — acceptsquery(required) plus optionalvector_store_id,max_num_results,filters,score_threshold, andrewrite_query, and returns the raw OpenAI search response. Falls back to anOPENAI_VECTOR_STORE_IDenv var when a request doesn't supply its ownvector_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).package.jsondeclares all of itsdependencies/devDependenciesand its owntest/lint/formatscripts, ESLint/Prettier config, and ignore files, so it can be copied out of this workspace and run standalone (npm install && npm testwith no access to the repo root).tests/search.test.js, 12 cases) plus a smallnock-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/searchendpoint viaFNA_SERVERLESS_EMBEDDINGS_ENDPOINTto verify a deployment works end-to-end, not just against local mocks._helpers/template-docs.jsthat broke automatic regeneration ofdocs/templates.md(it wrote to a path relative toprocess.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 lintandnpm testat the repo root currently fail even onmain—international-telephone-input/functions/lookup.jshas 3multiline-comment-styleviolations that predate this branch (confirmed identical toorigin/main), which trips the whole-reponpm run lint(and the pre-push hook, and this repo'snodejs.ymlCI).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
npm testlocally and it passed without errors.Related issues