-
Notifications
You must be signed in to change notification settings - Fork 38
search w/ POST #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
search w/ POST #260
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,4 +11,5 @@ test.sql | |
| META.json | ||
| /vectorize-* | ||
| site/ | ||
| uv.lock | ||
| uv.lock | ||
| .vscode | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,70 +1,107 @@ | ||
| ## GET /api/v1/search | ||
|
|
||
| ## Hybrid Search | ||
|
|
||
| Perform a hybrid semantic + full-text search against a previously initialized vectorize job. | ||
|
|
||
| URL | ||
| ### /api/v1/search | ||
|
|
||
| The following query parameters are available on both the GET and POST methods. | ||
|
|
||
| - **GET**: Accepts parameters as URL query parameters. | ||
| - **POST**: Accepts parameters as a JSON object in the request body. | ||
|
|
||
| Query parameters: | ||
|
|
||
| /api/v1/search | ||
| | Parameter | Type | Required | Default | Description | | ||
| | ----------- | :----: | :------: | :-------: | ----------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | job_name | string | yes | — | Name of the vectorize job to search. This identifies the table, schema, model and other job configuration. | | ||
| | query | string | yes | — | The user's search query string. | | ||
| | limit | int | no | 10 | Maximum number of results to return. | | ||
| | window_size | int | no | 5 * limit | Internal window size used by the hybrid search algorithm. | | ||
| | rrf_k | float | no | 60.0 | Reciprocal Rank Fusion parameter used by the hybrid ranking. | | ||
| | semantic_wt | float | no | 1.0 | Weight applied to the semantic score. | | ||
| | fts_wt | float | no | 1.0 | Weight applied to the full-text-search score. | | ||
| | filters | object | no | — | Additional filters passed as separate query parameters. The server parses values into typed filter values and validates keys/values for safety. | | ||
|
|
||
| Method | ||
|
|
||
| GET | ||
| ### Notes on filters | ||
|
|
||
| Query parameters | ||
| - **GET**: Filters are supplied as individual URL query parameters (e.g., `product_category=outdoor`, `price=lt.10`). | ||
| - **POST**: Filters are supplied as a JSON object in the `filters` field (e.g., `{ "product_category": "outdoor", "price": "lt.10"}`). | ||
|
|
||
| - job_name (string) - required | ||
| - Name of the vectorize job to search. This identifies the table, schema, model and other job configuration. | ||
| - query (string) - required | ||
| - The user's search query string. | ||
| - limit (int) - optional, default: 10 | ||
| - Maximum number of results to return. | ||
| - window_size (int) - optional, default: 5 * limit | ||
| - Internal window size used by the hybrid search algorithm. | ||
| - rrf_k (float) - optional, default: 60.0 | ||
| - Reciprocal Rank Fusion param used by the hybrid ranking. | ||
| - semantic_wt (float) - optional, default: 1.0 | ||
| - Weight applied to the semantic score. | ||
| - fts_wt (float) - optional, default: 1.0 | ||
| - Weight applied to the full-text-search score. | ||
| - filters (object) - optional | ||
| - Additional filters are accepted as query params and are passed as typed filter values to the query builder. Filters are provided as URL query parameters and will be parsed into a map of keys to values. The server validates keys and raw string values for safety. | ||
| The Operator will default to `equal` if one is not provided. | ||
| Therefore, `product_category=outdoor` and `product_category=eq.outdoor` are equivalent. | ||
|
|
||
| Notes on filters | ||
| Supported operators: | ||
|
|
||
| Filters are supplied as query parameters and the server will parse them into a BTreeMap of filter keys and typed values. The server validates string inputs to avoid SQL injection; only the job is allowed to specify table/column names on job creation. See the source for details about accepted filter types. | ||
| | Operator | Full Name | | ||
| |----------|-----------| | ||
| | `eq` | Equal | | ||
| | `gt` | Greater Than | | ||
| | `gte` | Greater Than or Equal | | ||
| | `lt` | Less Than | | ||
| | `lte` | Less Than or Equal | | ||
|
|
||
| Example request | ||
| The server parses and validates filter values according to the job's schema and allowed columns. | ||
|
|
||
| ### GET /api/v1/search | ||
|
|
||
| Example with multiple `filter` values | ||
|
|
||
| ```bash | ||
| curl -G "http://localhost:8080/api/v1/search" \ | ||
| --data-urlencode "job_name=my_job" \ | ||
| --data-urlencode "query=camping gear" \ | ||
| --data-urlencode "limit=2" | ||
| --data-urlencode "limit=2" \ | ||
| --data-urlencode "product_category=outdoor" \ | ||
| --data-urlencode "price=gt.10" | ||
| ``` | ||
|
|
||
| Example response (200) | ||
|
|
||
| The endpoint returns an array of JSON objects. The exact shape depends on the columns selected by the job (server uses `SELECT *` for results), plus additional ranking fields. Example returned item: | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "product_id": 39, | ||
| "product_name": "Hammock", | ||
| "description": "Sling made of fabric or netting, suspended between two points for relaxation", | ||
| "product_category": "outdoor", | ||
| "fts_rank": null, | ||
| "price": 40.0, | ||
| "updated_at": "2025-06-25T19:57:22.410561+00:00", | ||
| "semantic_rank": 1, | ||
| "similarity_score": 0.3192296909597241, | ||
| "rrf_score": 0.01639344262295082, | ||
| "fts_rank": null | ||
| "product_category": "outdoor", | ||
| "product_id": 39, | ||
| "product_name": "Hammock", | ||
| "rrf_score": 0.015873015873015872, | ||
| "semantic_rank": 3, | ||
| "similarity_score": 0.3863893266436258, | ||
| "updated_at": "2025-11-01T16:30:42.501294+00:00" | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| Errors | ||
| ## POST /api/v1/search | ||
|
|
||
| Pass parameters as a JSON object in the request body. Example: | ||
|
|
||
| - 400 / InvalidRequest - missing or invalid parameters | ||
| - 404 / NotFound - job not found | ||
| - 500 / InternalServerError - other server-side errors | ||
| ```bash | ||
| curl -X POST "http://localhost:8080/api/v1/search" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "job_name": "my_job", | ||
| "query": "camping gear", | ||
| "limit": 2, | ||
| "filters": {"product_category": "outdoor", "price": "gt.10"} | ||
| }' | ||
| ``` | ||
|
|
||
| ```json | ||
| [ | ||
| { | ||
| "description": "Sling made of fabric or netting, suspended between two points for relaxation", | ||
| "fts_rank": null, | ||
| "price": 40.0, | ||
| "product_category": "outdoor", | ||
| "product_id": 39, | ||
| "product_name": "Hammock", | ||
| "rrf_score": 0.015873015873015872, | ||
| "semantic_rank": 3, | ||
| "similarity_score": 0.3863893266436258, | ||
| "updated_at": "2025-11-01T16:30:42.501294+00:00" | ||
| } | ||
| ] | ||
| ``` |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.