@foxnose/sdk 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/index.cjs +281 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -3
- package/dist/index.d.ts +115 -3
- package/dist/index.js +279 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -93,8 +93,8 @@ interface RetryConfig {
|
|
|
93
93
|
methods: readonly string[];
|
|
94
94
|
}
|
|
95
95
|
declare const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig>;
|
|
96
|
-
declare const SDK_VERSION = "0.
|
|
97
|
-
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.
|
|
96
|
+
declare const SDK_VERSION = "0.3.0";
|
|
97
|
+
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.3.0";
|
|
98
98
|
/**
|
|
99
99
|
* General transport-level configuration shared by all clients.
|
|
100
100
|
*/
|
|
@@ -709,6 +709,51 @@ interface FluxClientOptions {
|
|
|
709
709
|
retryConfig?: RetryConfig;
|
|
710
710
|
defaultHeaders?: Record<string, string>;
|
|
711
711
|
}
|
|
712
|
+
interface VectorSearchOptions {
|
|
713
|
+
query: string;
|
|
714
|
+
fields?: string[];
|
|
715
|
+
top_k?: number;
|
|
716
|
+
similarity_threshold?: number;
|
|
717
|
+
limit?: number;
|
|
718
|
+
offset?: number;
|
|
719
|
+
[extra: string]: any;
|
|
720
|
+
}
|
|
721
|
+
interface VectorFieldSearchOptions {
|
|
722
|
+
field: string;
|
|
723
|
+
query_vector: number[];
|
|
724
|
+
top_k?: number;
|
|
725
|
+
similarity_threshold?: number;
|
|
726
|
+
limit?: number;
|
|
727
|
+
offset?: number;
|
|
728
|
+
[extra: string]: any;
|
|
729
|
+
}
|
|
730
|
+
interface HybridSearchOptions {
|
|
731
|
+
query: string;
|
|
732
|
+
find_text: Record<string, any>;
|
|
733
|
+
fields?: string[];
|
|
734
|
+
top_k?: number;
|
|
735
|
+
similarity_threshold?: number;
|
|
736
|
+
vector_weight?: number;
|
|
737
|
+
text_weight?: number;
|
|
738
|
+
rerank_results?: boolean;
|
|
739
|
+
limit?: number;
|
|
740
|
+
offset?: number;
|
|
741
|
+
[extra: string]: any;
|
|
742
|
+
}
|
|
743
|
+
interface BoostedSearchOptions {
|
|
744
|
+
find_text: Record<string, any>;
|
|
745
|
+
query?: string;
|
|
746
|
+
field?: string;
|
|
747
|
+
query_vector?: number[];
|
|
748
|
+
top_k?: number;
|
|
749
|
+
similarity_threshold?: number;
|
|
750
|
+
boost_factor?: number;
|
|
751
|
+
boost_similarity_threshold?: number;
|
|
752
|
+
max_boost_results?: number;
|
|
753
|
+
limit?: number;
|
|
754
|
+
offset?: number;
|
|
755
|
+
[extra: string]: any;
|
|
756
|
+
}
|
|
712
757
|
/**
|
|
713
758
|
* Client for FoxNose Flux delivery APIs.
|
|
714
759
|
*
|
|
@@ -722,9 +767,76 @@ declare class FluxClient {
|
|
|
722
767
|
listResources<T = any>(folderPath: string, params?: Record<string, any>): Promise<T>;
|
|
723
768
|
getResource<T = any>(folderPath: string, resourceKey: string, params?: Record<string, any>): Promise<T>;
|
|
724
769
|
search<T = any>(folderPath: string, body: Record<string, any>): Promise<T>;
|
|
770
|
+
/** Semantic search using auto-generated embeddings. */
|
|
771
|
+
vectorSearch<T = any>(folderPath: string, options: VectorSearchOptions): Promise<T>;
|
|
772
|
+
/** Search using custom pre-computed embeddings. */
|
|
773
|
+
vectorFieldSearch<T = any>(folderPath: string, options: VectorFieldSearchOptions): Promise<T>;
|
|
774
|
+
/** Blended text + vector search with configurable weights. */
|
|
775
|
+
hybridSearch<T = any>(folderPath: string, options: HybridSearchOptions): Promise<T>;
|
|
776
|
+
/** Text search with results boosted by vector similarity. */
|
|
777
|
+
boostedSearch<T = any>(folderPath: string, options: BoostedSearchOptions): Promise<T>;
|
|
725
778
|
getRouter<T = any>(): Promise<T>;
|
|
726
779
|
getSchema<T = any>(folderPath: string): Promise<T>;
|
|
727
780
|
close(): void;
|
|
728
781
|
}
|
|
729
782
|
|
|
730
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Types and validation for Flux vector search requests.
|
|
785
|
+
*/
|
|
786
|
+
/** Search mode for the Flux search endpoint. */
|
|
787
|
+
declare const SearchMode: {
|
|
788
|
+
readonly TEXT: "text";
|
|
789
|
+
readonly VECTOR: "vector";
|
|
790
|
+
readonly VECTOR_BOOSTED: "vector_boosted";
|
|
791
|
+
readonly HYBRID: "hybrid";
|
|
792
|
+
};
|
|
793
|
+
type SearchMode = (typeof SearchMode)[keyof typeof SearchMode];
|
|
794
|
+
/** Configuration for auto-generated embedding search. */
|
|
795
|
+
interface VectorSearch {
|
|
796
|
+
query: string;
|
|
797
|
+
fields?: string[];
|
|
798
|
+
top_k?: number;
|
|
799
|
+
similarity_threshold?: number;
|
|
800
|
+
}
|
|
801
|
+
/** Configuration for custom pre-computed embedding search. */
|
|
802
|
+
interface VectorFieldSearch {
|
|
803
|
+
field: string;
|
|
804
|
+
query_vector: number[];
|
|
805
|
+
top_k?: number;
|
|
806
|
+
similarity_threshold?: number;
|
|
807
|
+
}
|
|
808
|
+
/** Configuration for vector-boosted search mode. */
|
|
809
|
+
interface VectorBoostConfig {
|
|
810
|
+
boost_factor?: number;
|
|
811
|
+
similarity_threshold?: number;
|
|
812
|
+
max_boost_results?: number;
|
|
813
|
+
}
|
|
814
|
+
/** Configuration for hybrid (text + vector) search mode. */
|
|
815
|
+
interface HybridConfig {
|
|
816
|
+
vector_weight?: number;
|
|
817
|
+
text_weight?: number;
|
|
818
|
+
rerank_results?: boolean;
|
|
819
|
+
}
|
|
820
|
+
/** Full search request payload for the Flux search endpoint. */
|
|
821
|
+
interface SearchRequest {
|
|
822
|
+
search_mode?: SearchMode;
|
|
823
|
+
find_text?: Record<string, any>;
|
|
824
|
+
find_phrase?: Record<string, any>;
|
|
825
|
+
vector_search?: VectorSearch;
|
|
826
|
+
vector_field_search?: VectorFieldSearch;
|
|
827
|
+
vector_boost_config?: VectorBoostConfig;
|
|
828
|
+
hybrid_config?: HybridConfig;
|
|
829
|
+
limit?: number;
|
|
830
|
+
offset?: number;
|
|
831
|
+
[extra: string]: any;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Validate a {@link SearchRequest} and return a clean body object (no undefined values).
|
|
835
|
+
*
|
|
836
|
+
* Enforces cross-field constraints:
|
|
837
|
+
* - `vector_search` and `vector_field_search` are mutually exclusive
|
|
838
|
+
* - Each search mode has specific required/forbidden fields
|
|
839
|
+
*/
|
|
840
|
+
declare function buildSearchBody(req: SearchRequest): Record<string, any>;
|
|
841
|
+
|
|
842
|
+
export { type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type ComponentList, type ComponentRef, type ComponentSummary, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, StaticTokenProvider, type StorageUsage, type TokenProvider, type UnitsUsage, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, resolveKey };
|
package/dist/index.d.ts
CHANGED
|
@@ -93,8 +93,8 @@ interface RetryConfig {
|
|
|
93
93
|
methods: readonly string[];
|
|
94
94
|
}
|
|
95
95
|
declare const DEFAULT_RETRY_CONFIG: Readonly<RetryConfig>;
|
|
96
|
-
declare const SDK_VERSION = "0.
|
|
97
|
-
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.
|
|
96
|
+
declare const SDK_VERSION = "0.3.0";
|
|
97
|
+
declare const DEFAULT_USER_AGENT = "foxnose-sdk-js/0.3.0";
|
|
98
98
|
/**
|
|
99
99
|
* General transport-level configuration shared by all clients.
|
|
100
100
|
*/
|
|
@@ -709,6 +709,51 @@ interface FluxClientOptions {
|
|
|
709
709
|
retryConfig?: RetryConfig;
|
|
710
710
|
defaultHeaders?: Record<string, string>;
|
|
711
711
|
}
|
|
712
|
+
interface VectorSearchOptions {
|
|
713
|
+
query: string;
|
|
714
|
+
fields?: string[];
|
|
715
|
+
top_k?: number;
|
|
716
|
+
similarity_threshold?: number;
|
|
717
|
+
limit?: number;
|
|
718
|
+
offset?: number;
|
|
719
|
+
[extra: string]: any;
|
|
720
|
+
}
|
|
721
|
+
interface VectorFieldSearchOptions {
|
|
722
|
+
field: string;
|
|
723
|
+
query_vector: number[];
|
|
724
|
+
top_k?: number;
|
|
725
|
+
similarity_threshold?: number;
|
|
726
|
+
limit?: number;
|
|
727
|
+
offset?: number;
|
|
728
|
+
[extra: string]: any;
|
|
729
|
+
}
|
|
730
|
+
interface HybridSearchOptions {
|
|
731
|
+
query: string;
|
|
732
|
+
find_text: Record<string, any>;
|
|
733
|
+
fields?: string[];
|
|
734
|
+
top_k?: number;
|
|
735
|
+
similarity_threshold?: number;
|
|
736
|
+
vector_weight?: number;
|
|
737
|
+
text_weight?: number;
|
|
738
|
+
rerank_results?: boolean;
|
|
739
|
+
limit?: number;
|
|
740
|
+
offset?: number;
|
|
741
|
+
[extra: string]: any;
|
|
742
|
+
}
|
|
743
|
+
interface BoostedSearchOptions {
|
|
744
|
+
find_text: Record<string, any>;
|
|
745
|
+
query?: string;
|
|
746
|
+
field?: string;
|
|
747
|
+
query_vector?: number[];
|
|
748
|
+
top_k?: number;
|
|
749
|
+
similarity_threshold?: number;
|
|
750
|
+
boost_factor?: number;
|
|
751
|
+
boost_similarity_threshold?: number;
|
|
752
|
+
max_boost_results?: number;
|
|
753
|
+
limit?: number;
|
|
754
|
+
offset?: number;
|
|
755
|
+
[extra: string]: any;
|
|
756
|
+
}
|
|
712
757
|
/**
|
|
713
758
|
* Client for FoxNose Flux delivery APIs.
|
|
714
759
|
*
|
|
@@ -722,9 +767,76 @@ declare class FluxClient {
|
|
|
722
767
|
listResources<T = any>(folderPath: string, params?: Record<string, any>): Promise<T>;
|
|
723
768
|
getResource<T = any>(folderPath: string, resourceKey: string, params?: Record<string, any>): Promise<T>;
|
|
724
769
|
search<T = any>(folderPath: string, body: Record<string, any>): Promise<T>;
|
|
770
|
+
/** Semantic search using auto-generated embeddings. */
|
|
771
|
+
vectorSearch<T = any>(folderPath: string, options: VectorSearchOptions): Promise<T>;
|
|
772
|
+
/** Search using custom pre-computed embeddings. */
|
|
773
|
+
vectorFieldSearch<T = any>(folderPath: string, options: VectorFieldSearchOptions): Promise<T>;
|
|
774
|
+
/** Blended text + vector search with configurable weights. */
|
|
775
|
+
hybridSearch<T = any>(folderPath: string, options: HybridSearchOptions): Promise<T>;
|
|
776
|
+
/** Text search with results boosted by vector similarity. */
|
|
777
|
+
boostedSearch<T = any>(folderPath: string, options: BoostedSearchOptions): Promise<T>;
|
|
725
778
|
getRouter<T = any>(): Promise<T>;
|
|
726
779
|
getSchema<T = any>(folderPath: string): Promise<T>;
|
|
727
780
|
close(): void;
|
|
728
781
|
}
|
|
729
782
|
|
|
730
|
-
|
|
783
|
+
/**
|
|
784
|
+
* Types and validation for Flux vector search requests.
|
|
785
|
+
*/
|
|
786
|
+
/** Search mode for the Flux search endpoint. */
|
|
787
|
+
declare const SearchMode: {
|
|
788
|
+
readonly TEXT: "text";
|
|
789
|
+
readonly VECTOR: "vector";
|
|
790
|
+
readonly VECTOR_BOOSTED: "vector_boosted";
|
|
791
|
+
readonly HYBRID: "hybrid";
|
|
792
|
+
};
|
|
793
|
+
type SearchMode = (typeof SearchMode)[keyof typeof SearchMode];
|
|
794
|
+
/** Configuration for auto-generated embedding search. */
|
|
795
|
+
interface VectorSearch {
|
|
796
|
+
query: string;
|
|
797
|
+
fields?: string[];
|
|
798
|
+
top_k?: number;
|
|
799
|
+
similarity_threshold?: number;
|
|
800
|
+
}
|
|
801
|
+
/** Configuration for custom pre-computed embedding search. */
|
|
802
|
+
interface VectorFieldSearch {
|
|
803
|
+
field: string;
|
|
804
|
+
query_vector: number[];
|
|
805
|
+
top_k?: number;
|
|
806
|
+
similarity_threshold?: number;
|
|
807
|
+
}
|
|
808
|
+
/** Configuration for vector-boosted search mode. */
|
|
809
|
+
interface VectorBoostConfig {
|
|
810
|
+
boost_factor?: number;
|
|
811
|
+
similarity_threshold?: number;
|
|
812
|
+
max_boost_results?: number;
|
|
813
|
+
}
|
|
814
|
+
/** Configuration for hybrid (text + vector) search mode. */
|
|
815
|
+
interface HybridConfig {
|
|
816
|
+
vector_weight?: number;
|
|
817
|
+
text_weight?: number;
|
|
818
|
+
rerank_results?: boolean;
|
|
819
|
+
}
|
|
820
|
+
/** Full search request payload for the Flux search endpoint. */
|
|
821
|
+
interface SearchRequest {
|
|
822
|
+
search_mode?: SearchMode;
|
|
823
|
+
find_text?: Record<string, any>;
|
|
824
|
+
find_phrase?: Record<string, any>;
|
|
825
|
+
vector_search?: VectorSearch;
|
|
826
|
+
vector_field_search?: VectorFieldSearch;
|
|
827
|
+
vector_boost_config?: VectorBoostConfig;
|
|
828
|
+
hybrid_config?: HybridConfig;
|
|
829
|
+
limit?: number;
|
|
830
|
+
offset?: number;
|
|
831
|
+
[extra: string]: any;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Validate a {@link SearchRequest} and return a clean body object (no undefined values).
|
|
835
|
+
*
|
|
836
|
+
* Enforces cross-field constraints:
|
|
837
|
+
* - `vector_search` and `vector_field_search` are mutually exclusive
|
|
838
|
+
* - Each search mode has specific required/forbidden fields
|
|
839
|
+
*/
|
|
840
|
+
declare function buildSearchBody(req: SearchRequest): Record<string, any>;
|
|
841
|
+
|
|
842
|
+
export { type APIFolderList, type APIFolderSummary, type APIInfo, type APIList, type APIRef, AnonymousAuth, type ApiFolderOptions, type ApiFolderRouteDescriptionOptions, type AuthStrategy, type BatchItemError, type BatchUpsertItem, type BatchUpsertResult, type BoostedSearchOptions, type ComponentList, type ComponentRef, type ComponentSummary, type CurrentUsage, DEFAULT_RETRY_CONFIG, DEFAULT_USER_AGENT, type EnvironmentList, type EnvironmentRef, type EnvironmentSummary, type FieldList, type FieldSummary, type FluxAPIKeyList, type FluxAPIKeyRef, type FluxAPIKeySummary, FluxClient, type FluxClientOptions, type FluxRoleList, type FluxRoleRef, type FluxRoleSummary, type FolderList, type FolderRef, type FolderSummary, FoxnoseAPIError, FoxnoseAuthError, type FoxnoseConfig, FoxnoseError, FoxnoseTransportError, HttpTransport, type HybridConfig, type HybridSearchOptions, JWTAuth, type LocaleList, type LocaleSummary, type ManagementAPIKeyList, type ManagementAPIKeyRef, type ManagementAPIKeySummary, ManagementClient, type ManagementClientOptions, type ManagementRoleList, type ManagementRoleRef, type ManagementRoleSummary, type OrgRef, type OrganizationList, type OrganizationOwner, type OrganizationPlanStatus, type OrganizationSummary, type OrganizationUsage, type PaginatedResponse, type PlanDetails, type PlanLimits, type ProjectList, type ProjectRef, type ProjectSummary, type RegionInfo, type RequestData, type ResourceList, type ResourceRef, type ResourceSummary, type RetryConfig, type RevisionList, type RevisionRef, type RevisionSummary, type RolePermission, type RolePermissionObject, SDK_VERSION, type SchemaVersionList, type SchemaVersionRef, type SchemaVersionSummary, SearchMode, type SearchRequest, SecureKeyAuth, SimpleKeyAuth, StaticTokenProvider, type StorageUsage, type TokenProvider, type UnitsUsage, type UsageBreakdown, type UsageMetric, type UserReference, SDK_VERSION as VERSION, type VectorBoostConfig, type VectorFieldSearch, type VectorFieldSearchOptions, type VectorSearch, type VectorSearchOptions, buildSearchBody, createConfig, resolveKey };
|
package/dist/index.js
CHANGED
|
@@ -104,9 +104,6 @@ var SecureKeyAuth = class {
|
|
|
104
104
|
try {
|
|
105
105
|
const parsed = new URL(request.url);
|
|
106
106
|
path = parsed.pathname || "/";
|
|
107
|
-
if (parsed.search) {
|
|
108
|
-
path = `${path}${parsed.search}`;
|
|
109
|
-
}
|
|
110
107
|
} catch {
|
|
111
108
|
path = request.path || "/";
|
|
112
109
|
}
|
|
@@ -150,7 +147,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
150
147
|
statusCodes: [408, 425, 429, 500, 502, 503, 504],
|
|
151
148
|
methods: ["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]
|
|
152
149
|
};
|
|
153
|
-
var SDK_VERSION = "0.
|
|
150
|
+
var SDK_VERSION = "0.3.0";
|
|
154
151
|
var DEFAULT_USER_AGENT = `foxnose-sdk-js/${SDK_VERSION}`;
|
|
155
152
|
function createConfig(options) {
|
|
156
153
|
if (!options.baseUrl) {
|
|
@@ -1316,6 +1313,156 @@ var ManagementClient = class {
|
|
|
1316
1313
|
}
|
|
1317
1314
|
};
|
|
1318
1315
|
|
|
1316
|
+
// src/flux/models.ts
|
|
1317
|
+
var SearchMode = {
|
|
1318
|
+
TEXT: "text",
|
|
1319
|
+
VECTOR: "vector",
|
|
1320
|
+
VECTOR_BOOSTED: "vector_boosted",
|
|
1321
|
+
HYBRID: "hybrid"
|
|
1322
|
+
};
|
|
1323
|
+
var SEARCH_REQUEST_KNOWN_KEYS = /* @__PURE__ */ new Set([
|
|
1324
|
+
"search_mode",
|
|
1325
|
+
"find_text",
|
|
1326
|
+
"find_phrase",
|
|
1327
|
+
"vector_search",
|
|
1328
|
+
"vector_field_search",
|
|
1329
|
+
"vector_boost_config",
|
|
1330
|
+
"hybrid_config",
|
|
1331
|
+
"limit",
|
|
1332
|
+
"offset"
|
|
1333
|
+
]);
|
|
1334
|
+
function checkFinite(value, name) {
|
|
1335
|
+
if (!Number.isFinite(value)) {
|
|
1336
|
+
throw new Error(`${name} must be a finite number`);
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
function checkThreshold(value, name) {
|
|
1340
|
+
if (value != null) {
|
|
1341
|
+
checkFinite(value, name);
|
|
1342
|
+
if (value < 0 || value > 1) {
|
|
1343
|
+
throw new Error(`${name} must be between 0.0 and 1.0`);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
function checkPositiveInt(value, name) {
|
|
1348
|
+
if (value != null) {
|
|
1349
|
+
checkFinite(value, name);
|
|
1350
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
1351
|
+
throw new Error(`${name} must be a positive integer (>= 1)`);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
function validateVectorSearch(vs) {
|
|
1356
|
+
checkPositiveInt(vs.top_k, "top_k");
|
|
1357
|
+
checkThreshold(vs.similarity_threshold, "similarity_threshold");
|
|
1358
|
+
}
|
|
1359
|
+
function validateVectorFieldSearch(vfs) {
|
|
1360
|
+
if (!vfs.query_vector || vfs.query_vector.length === 0) {
|
|
1361
|
+
throw new Error("query_vector must not be empty");
|
|
1362
|
+
}
|
|
1363
|
+
for (let i = 0; i < vfs.query_vector.length; i++) {
|
|
1364
|
+
if (!Number.isFinite(vfs.query_vector[i])) {
|
|
1365
|
+
throw new Error(`query_vector[${i}] must be a finite number`);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
checkPositiveInt(vfs.top_k, "top_k");
|
|
1369
|
+
checkThreshold(vfs.similarity_threshold, "similarity_threshold");
|
|
1370
|
+
}
|
|
1371
|
+
function validateBoostConfig(cfg) {
|
|
1372
|
+
if (cfg.boost_factor != null) {
|
|
1373
|
+
checkFinite(cfg.boost_factor, "boost_factor");
|
|
1374
|
+
if (cfg.boost_factor <= 0) {
|
|
1375
|
+
throw new Error("boost_factor must be > 0");
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
checkThreshold(cfg.similarity_threshold, "similarity_threshold");
|
|
1379
|
+
checkPositiveInt(cfg.max_boost_results, "max_boost_results");
|
|
1380
|
+
}
|
|
1381
|
+
function validateHybridConfig(cfg) {
|
|
1382
|
+
if (cfg.vector_weight != null) {
|
|
1383
|
+
checkFinite(cfg.vector_weight, "vector_weight");
|
|
1384
|
+
if (cfg.vector_weight < 0 || cfg.vector_weight > 1) {
|
|
1385
|
+
throw new Error("vector_weight must be between 0.0 and 1.0");
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
if (cfg.text_weight != null) {
|
|
1389
|
+
checkFinite(cfg.text_weight, "text_weight");
|
|
1390
|
+
if (cfg.text_weight < 0 || cfg.text_weight > 1) {
|
|
1391
|
+
throw new Error("text_weight must be between 0.0 and 1.0");
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
const vw = cfg.vector_weight ?? 0.6;
|
|
1395
|
+
const tw = cfg.text_weight ?? 0.4;
|
|
1396
|
+
if (Math.abs(vw + tw - 1) > 1e-6) {
|
|
1397
|
+
throw new Error(`vector_weight + text_weight must equal 1.0, got ${vw + tw}`);
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
function buildSearchBody(req) {
|
|
1401
|
+
const mode = req.search_mode ?? SearchMode.TEXT;
|
|
1402
|
+
const vs = req.vector_search;
|
|
1403
|
+
const vfs = req.vector_field_search;
|
|
1404
|
+
const boost = req.vector_boost_config;
|
|
1405
|
+
const hybrid = req.hybrid_config;
|
|
1406
|
+
const hasText = req.find_text != null || req.find_phrase != null;
|
|
1407
|
+
if (vs) validateVectorSearch(vs);
|
|
1408
|
+
if (vfs) validateVectorFieldSearch(vfs);
|
|
1409
|
+
if (boost) validateBoostConfig(boost);
|
|
1410
|
+
if (hybrid) validateHybridConfig(hybrid);
|
|
1411
|
+
if (vs && vfs) {
|
|
1412
|
+
throw new Error("vector_search and vector_field_search are mutually exclusive");
|
|
1413
|
+
}
|
|
1414
|
+
if (mode === SearchMode.TEXT) {
|
|
1415
|
+
if (vs) throw new Error("vector_search is not allowed in text search mode");
|
|
1416
|
+
if (vfs) throw new Error("vector_field_search is not allowed in text search mode");
|
|
1417
|
+
if (boost) throw new Error("vector_boost_config is not allowed in text search mode");
|
|
1418
|
+
if (hybrid) throw new Error("hybrid_config is not allowed in text search mode");
|
|
1419
|
+
} else if (mode === SearchMode.VECTOR) {
|
|
1420
|
+
if (!vs && !vfs) {
|
|
1421
|
+
throw new Error("vector search mode requires vector_search or vector_field_search");
|
|
1422
|
+
}
|
|
1423
|
+
if (boost) throw new Error("vector_boost_config is not allowed in vector search mode");
|
|
1424
|
+
if (hybrid) throw new Error("hybrid_config is not allowed in vector search mode");
|
|
1425
|
+
} else if (mode === SearchMode.VECTOR_BOOSTED) {
|
|
1426
|
+
if (!vs && !vfs) {
|
|
1427
|
+
throw new Error("vector_boosted mode requires vector_search or vector_field_search");
|
|
1428
|
+
}
|
|
1429
|
+
if (!hasText) throw new Error("vector_boosted mode requires find_text or find_phrase");
|
|
1430
|
+
if (hybrid) throw new Error("hybrid_config is not allowed in vector_boosted mode");
|
|
1431
|
+
} else if (mode === SearchMode.HYBRID) {
|
|
1432
|
+
if (vfs) throw new Error("vector_field_search is not allowed in hybrid mode");
|
|
1433
|
+
if (!vs) throw new Error("hybrid mode requires vector_search");
|
|
1434
|
+
if (!hasText) throw new Error("hybrid mode requires find_text or find_phrase");
|
|
1435
|
+
if (boost) throw new Error("vector_boost_config is not allowed in hybrid mode");
|
|
1436
|
+
} else {
|
|
1437
|
+
const validModes = Object.values(SearchMode).join(", ");
|
|
1438
|
+
throw new Error(`Unknown search_mode: "${mode}". Valid modes: ${validModes}`);
|
|
1439
|
+
}
|
|
1440
|
+
const body = {};
|
|
1441
|
+
for (const [key, value] of Object.entries(req)) {
|
|
1442
|
+
if (value !== void 0) {
|
|
1443
|
+
body[key] = value;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
if (!body.search_mode) {
|
|
1447
|
+
body.search_mode = mode;
|
|
1448
|
+
}
|
|
1449
|
+
return body;
|
|
1450
|
+
}
|
|
1451
|
+
function mergeExtra(validated, extra) {
|
|
1452
|
+
const conflicts = [];
|
|
1453
|
+
for (const key of Object.keys(extra)) {
|
|
1454
|
+
if (SEARCH_REQUEST_KNOWN_KEYS.has(key)) {
|
|
1455
|
+
conflicts.push(key);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
if (conflicts.length > 0) {
|
|
1459
|
+
throw new Error(
|
|
1460
|
+
`extra keys conflict with SearchRequest fields: ${conflicts.sort().join(", ")}. Use the explicit parameters instead.`
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
return { ...validated, ...extra };
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1319
1466
|
// src/flux/client.ts
|
|
1320
1467
|
function cleanPrefix(prefix) {
|
|
1321
1468
|
const value = prefix.replace(/^\/+|\/+$/g, "");
|
|
@@ -1327,6 +1474,15 @@ function cleanPrefix(prefix) {
|
|
|
1327
1474
|
function normalizeFolderPath(folderPath) {
|
|
1328
1475
|
return folderPath.replace(/^\/+|\/+$/g, "");
|
|
1329
1476
|
}
|
|
1477
|
+
function stripUndefined(obj) {
|
|
1478
|
+
const result = {};
|
|
1479
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1480
|
+
if (value !== void 0) {
|
|
1481
|
+
result[key] = value;
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
return result;
|
|
1485
|
+
}
|
|
1330
1486
|
var FluxClient = class {
|
|
1331
1487
|
apiPrefix;
|
|
1332
1488
|
transport;
|
|
@@ -1360,6 +1516,123 @@ var FluxClient = class {
|
|
|
1360
1516
|
const path = this.buildPath(folderPath, "/_search");
|
|
1361
1517
|
return this.transport.request("POST", path, { jsonBody: body });
|
|
1362
1518
|
}
|
|
1519
|
+
/** Semantic search using auto-generated embeddings. */
|
|
1520
|
+
async vectorSearch(folderPath, options) {
|
|
1521
|
+
const { query, fields, top_k = 10, similarity_threshold, limit, offset, ...rest } = options;
|
|
1522
|
+
const extra = stripUndefined(rest);
|
|
1523
|
+
const vs = { query, fields, top_k, similarity_threshold };
|
|
1524
|
+
const req = {
|
|
1525
|
+
search_mode: SearchMode.VECTOR,
|
|
1526
|
+
vector_search: vs,
|
|
1527
|
+
limit,
|
|
1528
|
+
offset
|
|
1529
|
+
};
|
|
1530
|
+
const body = mergeExtra(buildSearchBody(req), extra);
|
|
1531
|
+
return this.search(folderPath, body);
|
|
1532
|
+
}
|
|
1533
|
+
/** Search using custom pre-computed embeddings. */
|
|
1534
|
+
async vectorFieldSearch(folderPath, options) {
|
|
1535
|
+
const {
|
|
1536
|
+
field,
|
|
1537
|
+
query_vector,
|
|
1538
|
+
top_k = 10,
|
|
1539
|
+
similarity_threshold,
|
|
1540
|
+
limit,
|
|
1541
|
+
offset,
|
|
1542
|
+
...rest
|
|
1543
|
+
} = options;
|
|
1544
|
+
const extra = stripUndefined(rest);
|
|
1545
|
+
const vfs = { field, query_vector, top_k, similarity_threshold };
|
|
1546
|
+
const req = {
|
|
1547
|
+
search_mode: SearchMode.VECTOR,
|
|
1548
|
+
vector_field_search: vfs,
|
|
1549
|
+
limit,
|
|
1550
|
+
offset
|
|
1551
|
+
};
|
|
1552
|
+
const body = mergeExtra(buildSearchBody(req), extra);
|
|
1553
|
+
return this.search(folderPath, body);
|
|
1554
|
+
}
|
|
1555
|
+
/** Blended text + vector search with configurable weights. */
|
|
1556
|
+
async hybridSearch(folderPath, options) {
|
|
1557
|
+
const {
|
|
1558
|
+
query,
|
|
1559
|
+
find_text,
|
|
1560
|
+
fields,
|
|
1561
|
+
top_k = 10,
|
|
1562
|
+
similarity_threshold,
|
|
1563
|
+
vector_weight = 0.6,
|
|
1564
|
+
text_weight = 0.4,
|
|
1565
|
+
rerank_results = true,
|
|
1566
|
+
limit,
|
|
1567
|
+
offset,
|
|
1568
|
+
...rest
|
|
1569
|
+
} = options;
|
|
1570
|
+
const extra = stripUndefined(rest);
|
|
1571
|
+
const vs = { query, fields, top_k, similarity_threshold };
|
|
1572
|
+
const hybrid = { vector_weight, text_weight, rerank_results };
|
|
1573
|
+
const req = {
|
|
1574
|
+
search_mode: SearchMode.HYBRID,
|
|
1575
|
+
find_text,
|
|
1576
|
+
vector_search: vs,
|
|
1577
|
+
hybrid_config: hybrid,
|
|
1578
|
+
limit,
|
|
1579
|
+
offset
|
|
1580
|
+
};
|
|
1581
|
+
const body = mergeExtra(buildSearchBody(req), extra);
|
|
1582
|
+
return this.search(folderPath, body);
|
|
1583
|
+
}
|
|
1584
|
+
/** Text search with results boosted by vector similarity. */
|
|
1585
|
+
async boostedSearch(folderPath, options) {
|
|
1586
|
+
const {
|
|
1587
|
+
find_text,
|
|
1588
|
+
query,
|
|
1589
|
+
field,
|
|
1590
|
+
query_vector,
|
|
1591
|
+
top_k = 10,
|
|
1592
|
+
similarity_threshold,
|
|
1593
|
+
boost_factor = 1.5,
|
|
1594
|
+
boost_similarity_threshold,
|
|
1595
|
+
max_boost_results = 20,
|
|
1596
|
+
limit,
|
|
1597
|
+
offset,
|
|
1598
|
+
...rest
|
|
1599
|
+
} = options;
|
|
1600
|
+
const extra = stripUndefined(rest);
|
|
1601
|
+
const hasAuto = query != null;
|
|
1602
|
+
const hasCustom = field != null || query_vector != null;
|
|
1603
|
+
if (hasAuto && hasCustom) {
|
|
1604
|
+
throw new Error(
|
|
1605
|
+
"Provide either 'query' for auto-generated embeddings or 'field' + 'query_vector' for custom embeddings, not both"
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
let vs;
|
|
1609
|
+
let vfs;
|
|
1610
|
+
if (hasAuto) {
|
|
1611
|
+
vs = { query, top_k, similarity_threshold };
|
|
1612
|
+
} else if (field != null && query_vector != null) {
|
|
1613
|
+
vfs = { field, query_vector, top_k, similarity_threshold };
|
|
1614
|
+
} else {
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
"Provide either 'query' for auto-generated embeddings or 'field' + 'query_vector' for custom embeddings"
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
const boostConfig = {
|
|
1620
|
+
boost_factor,
|
|
1621
|
+
similarity_threshold: boost_similarity_threshold,
|
|
1622
|
+
max_boost_results
|
|
1623
|
+
};
|
|
1624
|
+
const req = {
|
|
1625
|
+
search_mode: SearchMode.VECTOR_BOOSTED,
|
|
1626
|
+
find_text,
|
|
1627
|
+
vector_search: vs,
|
|
1628
|
+
vector_field_search: vfs,
|
|
1629
|
+
vector_boost_config: boostConfig,
|
|
1630
|
+
limit,
|
|
1631
|
+
offset
|
|
1632
|
+
};
|
|
1633
|
+
const body = mergeExtra(buildSearchBody(req), extra);
|
|
1634
|
+
return this.search(folderPath, body);
|
|
1635
|
+
}
|
|
1363
1636
|
async getRouter() {
|
|
1364
1637
|
const path = `/${this.apiPrefix}/_router`;
|
|
1365
1638
|
return this.transport.request("GET", path);
|
|
@@ -1385,10 +1658,12 @@ export {
|
|
|
1385
1658
|
JWTAuth,
|
|
1386
1659
|
ManagementClient,
|
|
1387
1660
|
SDK_VERSION,
|
|
1661
|
+
SearchMode,
|
|
1388
1662
|
SecureKeyAuth,
|
|
1389
1663
|
SimpleKeyAuth,
|
|
1390
1664
|
StaticTokenProvider,
|
|
1391
1665
|
SDK_VERSION as VERSION,
|
|
1666
|
+
buildSearchBody,
|
|
1392
1667
|
createConfig,
|
|
1393
1668
|
resolveKey
|
|
1394
1669
|
};
|