This example demonstrates how to use GenSX's useSearch hook to create and query a vector search. The workflow provides a RAG (Retrieval Augmented Generation) example where an LLM uses vector search to find relevant information and answer questions. The data is stored in a GenSX Cloud search namespace.
The example consists of two main components:
InitializeSearch: Creates and populates a vector search namespace with baseball statisticsRagWorkflow: Processes questions by searching through the vector database to find relevant information and generate answers
Here's what happens when you run the RAG workflow:
- Your question is processed to find relevant information in the vector store
- The retrieved information is used by the LLM to generate an answer
- The results are formatted and displayed
-
Log in to GenSX (if you haven't already):
npx gensx login
-
Install dependencies:
pnpm install
-
Set up your environment variables:
export OPENAI_API_KEY=your_api_key_here
To run the workflow in GenSX Cloud:
-
Deploy your workflow:
pnpm run deploy
-
Initialize the vector search:
gensx run InitializeSearch
-
Ask questions about baseball statistics:
gensx run RagWorkflow --input '{"question": "Who plays for the Portland Pioneers?"}'
Once deployed, you can go to the GenSX console to see your workflows, test them, analyze traces, and get code snippets.
You can run the workflow directly:
pnpm dev "Who plays for the Portland Pioneers?"This will automatically initialize the vector search and run the workflow.
You can also test the workflow through a local API server:
pnpm startThis will start a local API server and you can call the workflow APIs via curl or any HTTP client:
Initialize the vector search first:
curl -X POST http://localhost:1337/workflows/InitializeSearch \
-H "Content-Type: application/json" \
-d '{}'Then run the workflow:
curl -X POST http://localhost:1337/workflows/RagWorkflow \
-H "Content-Type: application/json" \
-d '{
"question": "Who plays for the Portland Pioneers?"
}'A swagger UI will also be available at http://localhost:1337/swagger-ui to view the API details and test the workflow.