6bf8bebf51
CI / Test and Build (push) Failing after 1s
CI / Migrate Dev DB (push) Has been skipped
CI / Migrate DB (push) Has been skipped
CodeQL / Analyze actions (push) Has been cancelled
CodeQL / Analyze javascript-typescript (push) Has been cancelled
CI / Detect Version (push) Has been cancelled
CI / Detect Desktop Changes (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/cron.Dockerfile, ubuntu-latest, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build AMD64 (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build AMD64 (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/cron.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/db.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/pii.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-4vcpu-ubuntu-2404-arm, ./docker/realtime.Dockerfile, ubuntu-24.04-arm, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (blacksmith-8vcpu-ubuntu-2404-arm, ./docker/app.Dockerfile, linux-arm64-8-core, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
Helm Chart / Lint, test, and validate chart (push) Has been cancelled
Helm Chart / Chart version bumped (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Build Dev ECR (blacksmith-8vcpu-ubuntu-2404, ./docker/app.Dockerfile, ECR_APP, linux-x64-8-core) (push) Has been cancelled
CI / Promote Images (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/cron) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-2vcpu-ubuntu-2404, ./docker/db.Dockerfile, ECR_MIGRATIONS, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/pii.Dockerfile, ECR_PII, ubuntu-latest) (push) Has been cancelled
CI / Build Dev ECR (blacksmith-4vcpu-ubuntu-2404, ./docker/realtime.Dockerfile, ECR_REALTIME, ubuntu-latest) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Check Desktop Signing Secrets (push) Has been cancelled
CI / Desktop Release (push) Has been cancelled
CI / Create Desktop Prerelease (push) Has been cancelled
CI / Desktop Prerelease Build (push) Has been cancelled
CI / Publish Desktop Prerelease (push) Has been cancelled
CI / Prune Desktop Prereleases (push) Has been cancelled
Helm Chart / Install on kind and run helm test (push) Has been cancelled
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import { z } from 'zod'
|
||
import { DEFAULT_RERANKER_MODEL, rerankerModelSchema } from '@/lib/knowledge/reranker-models'
|
||
|
||
export const knowledgeSearchTagFilterSchema = z.object({
|
||
tagName: z.string(),
|
||
tagSlot: z.string().optional(),
|
||
fieldType: z.enum(['text', 'number', 'date', 'boolean']).optional(),
|
||
operator: z.string().default('eq'),
|
||
value: z.union([z.string(), z.number(), z.boolean()]),
|
||
valueTo: z.union([z.string(), z.number()]).optional(),
|
||
})
|
||
|
||
export const KNOWLEDGE_SEARCH_MODES = ['vector', 'hybrid'] as const
|
||
|
||
/**
|
||
* Shared by the internal and v1 search contracts. Defaults to `vector` so every
|
||
* existing caller keeps its current ranking; hybrid is opt-in.
|
||
*/
|
||
export const knowledgeSearchModeSchema = z
|
||
.enum(KNOWLEDGE_SEARCH_MODES)
|
||
.optional()
|
||
.nullable()
|
||
.default('vector')
|
||
.transform((val) => val ?? 'vector')
|
||
|
||
export const knowledgeSearchBodySchema = z
|
||
.object({
|
||
knowledgeBaseIds: z.union([
|
||
z.string().min(1, 'Knowledge base ID is required'),
|
||
z.array(z.string().min(1)).min(1, 'At least one knowledge base ID is required'),
|
||
]),
|
||
query: z
|
||
.string()
|
||
.optional()
|
||
.nullable()
|
||
.transform((val) => val || undefined),
|
||
topK: z
|
||
.number()
|
||
.min(1)
|
||
.max(100)
|
||
.optional()
|
||
.nullable()
|
||
.default(10)
|
||
.transform((val) => val ?? 10),
|
||
tagFilters: z
|
||
.array(knowledgeSearchTagFilterSchema)
|
||
.optional()
|
||
.nullable()
|
||
.transform((val) => val || undefined),
|
||
/**
|
||
* `vector` (default) is semantic-only retrieval. `hybrid` additionally runs a
|
||
* full-text leg and fuses the two by reciprocal rank, which recovers exact
|
||
* tokens (error codes, ticket keys, identifiers) that embeddings rank poorly.
|
||
*/
|
||
searchMode: knowledgeSearchModeSchema,
|
||
rerankerEnabled: z.boolean().optional().default(false),
|
||
rerankerModel: rerankerModelSchema.optional().default(DEFAULT_RERANKER_MODEL),
|
||
/**
|
||
* Number of vector results sent to Cohere as the documents array for reranking. Capped at 100
|
||
* so each rerank call stays within a single Cohere search unit (1 query × ≤100 docs); see
|
||
* `RERANK_MODEL_PRICING` in `providers/models.ts`.
|
||
*/
|
||
rerankerInputCount: z
|
||
.number()
|
||
.int('rerankerInputCount must be an integer')
|
||
.min(1, 'rerankerInputCount must be at least 1')
|
||
.max(100, 'rerankerInputCount cannot exceed 100')
|
||
.optional()
|
||
.nullable()
|
||
.transform((val) => val ?? undefined),
|
||
rerankerApiKey: z
|
||
.string()
|
||
.optional()
|
||
.nullable()
|
||
.transform((val) => val || undefined),
|
||
})
|
||
.refine(
|
||
(data) => {
|
||
const hasQuery = data.query && data.query.trim().length > 0
|
||
const hasTagFilters = data.tagFilters && data.tagFilters.length > 0
|
||
return hasQuery || hasTagFilters
|
||
},
|
||
{
|
||
message: 'Please provide either a search query or tag filters to search your knowledge base',
|
||
}
|
||
)
|
||
export type KnowledgeSearchBody = z.output<typeof knowledgeSearchBodySchema>
|