@nexo-labs/payload-typesense 1.9.0 → 1.9.2
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/dist/index.d.mts +304 -371
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1084 -1002
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -6
package/dist/index.d.mts
CHANGED
|
@@ -5,10 +5,7 @@ import { CollectionSlug, Config, Payload, PayloadHandler, PayloadRequest } from
|
|
|
5
5
|
import { Agent } from "http";
|
|
6
6
|
import { Agent as Agent$1 } from "https";
|
|
7
7
|
import { ReadStream } from "fs";
|
|
8
|
-
import { ReadStream as ReadStream$1 } from "node:fs";
|
|
9
8
|
|
|
10
|
-
//#region rolldown:runtime
|
|
11
|
-
//#endregion
|
|
12
9
|
//#region src/shared/types/plugin-types.d.ts
|
|
13
10
|
/**
|
|
14
11
|
* Hybrid search configuration for combining semantic and keyword search
|
|
@@ -254,7 +251,7 @@ interface RAGFeatureConfig extends RAGConfig {
|
|
|
254
251
|
callbacks?: RAGCallbacks;
|
|
255
252
|
agents: AgentConfig[] | AgentProvider;
|
|
256
253
|
}
|
|
257
|
-
type TypesenseProtocol =
|
|
254
|
+
type TypesenseProtocol = 'http' | 'https';
|
|
258
255
|
type TypesenseNode = {
|
|
259
256
|
host: string;
|
|
260
257
|
port: number;
|
|
@@ -420,6 +417,8 @@ interface TypesenseRAGPluginConfig<TSlug extends CollectionSlug> {
|
|
|
420
417
|
hnsw?: HNSWConfig;
|
|
421
418
|
/** Advanced search configuration */
|
|
422
419
|
advanced?: AdvancedSearchConfig;
|
|
420
|
+
/** Resolve document type from Typesense collection name (e.g. 'posts_chunk' → 'post') */
|
|
421
|
+
documentTypeResolver?: (collectionName: string) => string;
|
|
423
422
|
}
|
|
424
423
|
//#endregion
|
|
425
424
|
//#region src/plugin/create-rag-plugin.d.ts
|
|
@@ -1829,80 +1828,12 @@ declare class Client {
|
|
|
1829
1828
|
nlSearchModels(id: string): NLSearchModel;
|
|
1830
1829
|
}
|
|
1831
1830
|
//#endregion
|
|
1832
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/SearchOnlyCollection.d.ts
|
|
1833
|
-
declare class SearchOnlyCollection<T extends DocumentSchema> {
|
|
1834
|
-
private readonly name;
|
|
1835
|
-
private readonly apiCall;
|
|
1836
|
-
private readonly configuration;
|
|
1837
|
-
private readonly _documents;
|
|
1838
|
-
constructor(name: string, apiCall: ApiCall, configuration: any);
|
|
1839
|
-
documents(): SearchableDocuments<T>;
|
|
1840
|
-
}
|
|
1841
|
-
//#endregion
|
|
1842
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/SearchClient.d.ts
|
|
1843
|
-
declare class SearchClient {
|
|
1844
|
-
readonly multiSearch: MultiSearch;
|
|
1845
|
-
private readonly configuration;
|
|
1846
|
-
private readonly apiCall;
|
|
1847
|
-
private readonly individualCollections;
|
|
1848
|
-
constructor(options: ConfigurationOptions);
|
|
1849
|
-
clearCache(): void;
|
|
1850
|
-
collections<TDocumentSchema extends DocumentSchema>(collectionName: string): SearchOnlyCollection<TDocumentSchema>;
|
|
1851
|
-
}
|
|
1852
|
-
//#endregion
|
|
1853
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/HTTPError.d.ts
|
|
1854
|
-
declare class HTTPError extends TypesenseError {}
|
|
1855
|
-
//#endregion
|
|
1856
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/MissingConfigurationError.d.ts
|
|
1857
|
-
declare class MissingConfigurationError extends TypesenseError {}
|
|
1858
|
-
//#endregion
|
|
1859
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/ObjectAlreadyExists.d.ts
|
|
1860
|
-
declare class ObjectAlreadyExists extends TypesenseError {}
|
|
1861
|
-
//#endregion
|
|
1862
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/ObjectNotFound.d.ts
|
|
1863
|
-
declare class ObjectNotFound extends TypesenseError {}
|
|
1864
|
-
//#endregion
|
|
1865
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/ObjectUnprocessable.d.ts
|
|
1866
|
-
declare class ObjectUnprocessable extends TypesenseError {}
|
|
1867
|
-
//#endregion
|
|
1868
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/RequestMalformed.d.ts
|
|
1869
|
-
declare class RequestMalformed extends TypesenseError {}
|
|
1870
|
-
//#endregion
|
|
1871
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/RequestUnauthorized.d.ts
|
|
1872
|
-
declare class RequestUnauthorized extends TypesenseError {}
|
|
1873
|
-
//#endregion
|
|
1874
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/ServerError.d.ts
|
|
1875
|
-
declare class ServerError extends TypesenseError {}
|
|
1876
|
-
//#endregion
|
|
1877
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense/Errors/ImportError.d.ts
|
|
1878
|
-
interface ImportErrorPayload {
|
|
1879
|
-
documentsInJSONLFormat: string | ReadStream$1;
|
|
1880
|
-
options: DocumentImportParameters;
|
|
1881
|
-
failedItems: ImportResponse[];
|
|
1882
|
-
successCount: number;
|
|
1883
|
-
}
|
|
1884
|
-
declare class ImportError extends TypesenseError {
|
|
1885
|
-
payload: ImportErrorPayload;
|
|
1886
|
-
importResults: ImportResponse[];
|
|
1887
|
-
constructor(message: string, importResults: ImportResponse[], payload: ImportErrorPayload);
|
|
1888
|
-
}
|
|
1889
|
-
declare namespace index_d_exports {
|
|
1890
|
-
export { HTTPError, ImportError, MissingConfigurationError, ObjectAlreadyExists, ObjectNotFound, ObjectUnprocessable, RequestMalformed, RequestUnauthorized, ServerError, TypesenseError };
|
|
1891
|
-
}
|
|
1892
|
-
//#endregion
|
|
1893
|
-
//#region ../../node_modules/.pnpm/typesense@2.1.0_@babel+runtime@7.28.6/node_modules/typesense/lib/Typesense.d.ts
|
|
1894
|
-
declare const _default: {
|
|
1895
|
-
Client: typeof Client;
|
|
1896
|
-
SearchClient: typeof SearchClient;
|
|
1897
|
-
Errors: typeof index_d_exports;
|
|
1898
|
-
};
|
|
1899
|
-
//#endregion
|
|
1900
1831
|
//#region src/adapter/types.d.ts
|
|
1901
1832
|
/**
|
|
1902
1833
|
* All valid Typesense field types
|
|
1903
1834
|
* @see https://typesense.org/docs/latest/api/collections.html#schema-parameters
|
|
1904
1835
|
*/
|
|
1905
|
-
type TypesenseFieldType =
|
|
1836
|
+
type TypesenseFieldType = 'string' | 'int32' | 'int64' | 'float' | 'bool' | 'string[]' | 'float[]' | 'int32[]' | 'int64[]' | 'bool[]' | 'object' | 'object[]' | 'geopoint' | 'geopoint[]' | 'auto';
|
|
1906
1837
|
/**
|
|
1907
1838
|
* Typesense-specific field mapping
|
|
1908
1839
|
* Extends the base FieldMapping with Typesense-specific properties
|
|
@@ -2080,6 +2011,63 @@ declare function createTypesenseAdapter(config: TypesenseConnectionConfig): Type
|
|
|
2080
2011
|
*/
|
|
2081
2012
|
declare function createTypesenseAdapterFromClient(client: Client): TypesenseAdapter;
|
|
2082
2013
|
//#endregion
|
|
2014
|
+
//#region src/core/config/types.d.ts
|
|
2015
|
+
type SearchMode = 'semantic' | 'keyword' | 'hybrid';
|
|
2016
|
+
interface SearchDefaults {
|
|
2017
|
+
mode?: SearchMode;
|
|
2018
|
+
perPage?: number;
|
|
2019
|
+
tables?: string[];
|
|
2020
|
+
}
|
|
2021
|
+
interface SearchFeatureConfig {
|
|
2022
|
+
enabled: boolean;
|
|
2023
|
+
defaults?: SearchDefaults;
|
|
2024
|
+
}
|
|
2025
|
+
interface SyncFeatureConfig {
|
|
2026
|
+
enabled: boolean;
|
|
2027
|
+
autoSync?: boolean;
|
|
2028
|
+
batchSize?: number;
|
|
2029
|
+
}
|
|
2030
|
+
interface FeatureFlags {
|
|
2031
|
+
embedding?: EmbeddingProviderConfig$1;
|
|
2032
|
+
search?: SearchFeatureConfig;
|
|
2033
|
+
rag?: RAGFeatureConfig;
|
|
2034
|
+
sync?: SyncFeatureConfig;
|
|
2035
|
+
}
|
|
2036
|
+
interface ModularPluginConfig {
|
|
2037
|
+
typesense: TypesenseConnectionConfig;
|
|
2038
|
+
features: FeatureFlags;
|
|
2039
|
+
collections: Record<CollectionSlug | string, TableConfig[]>;
|
|
2040
|
+
/** Resolve document type from Typesense collection name */
|
|
2041
|
+
documentTypeResolver?: (collectionName: string) => string;
|
|
2042
|
+
}
|
|
2043
|
+
//#endregion
|
|
2044
|
+
//#region src/features/embedding/embeddings.d.ts
|
|
2045
|
+
/**
|
|
2046
|
+
* Generates an embedding for the given text using OpenAI or Gemini API
|
|
2047
|
+
* @param text - The text to generate an embedding for
|
|
2048
|
+
* @param config - Optional embedding configuration (provider, model, dimensions, apiKey)
|
|
2049
|
+
* @returns The embedding vector as an array of numbers, or null if generation fails
|
|
2050
|
+
*/
|
|
2051
|
+
declare const generateEmbedding: (text: string, config?: EmbeddingProviderConfig$1) => Promise<number[] | null>;
|
|
2052
|
+
/**
|
|
2053
|
+
* Generate embedding with usage tracking
|
|
2054
|
+
*
|
|
2055
|
+
* This function returns both the embedding and usage information (tokens used)
|
|
2056
|
+
*
|
|
2057
|
+
* @param text - The text to generate an embedding for
|
|
2058
|
+
* @param config - Optional embedding configuration
|
|
2059
|
+
* @returns Embedding with usage information, or null if generation fails
|
|
2060
|
+
*/
|
|
2061
|
+
declare const generateEmbeddingWithUsage: (text: string, config?: EmbeddingProviderConfig$1) => Promise<EmbeddingWithUsage | null>;
|
|
2062
|
+
/**
|
|
2063
|
+
* Generate embeddings for multiple texts with usage tracking (batch)
|
|
2064
|
+
*
|
|
2065
|
+
* @param texts - Array of texts to generate embeddings for
|
|
2066
|
+
* @param config - Optional embedding configuration
|
|
2067
|
+
* @returns Embeddings with total usage information, or null if generation fails
|
|
2068
|
+
*/
|
|
2069
|
+
declare const generateEmbeddingsBatchWithUsage: (texts: string[], config?: EmbeddingProviderConfig$1) => Promise<BatchEmbeddingWithUsage | null>;
|
|
2070
|
+
//#endregion
|
|
2083
2071
|
//#region src/shared/types/types.d.ts
|
|
2084
2072
|
interface TypesenseDocument {
|
|
2085
2073
|
id: string;
|
|
@@ -2247,206 +2235,120 @@ interface ApiResponse<T = unknown> {
|
|
|
2247
2235
|
success: boolean;
|
|
2248
2236
|
}
|
|
2249
2237
|
//#endregion
|
|
2250
|
-
//#region src/features/
|
|
2238
|
+
//#region src/features/rag/chat-session-repository.d.ts
|
|
2251
2239
|
/**
|
|
2252
|
-
*
|
|
2253
|
-
* @param text - The text to generate an embedding for
|
|
2254
|
-
* @param config - Optional embedding configuration (provider, model, dimensions, apiKey)
|
|
2255
|
-
* @returns The embedding vector as an array of numbers, or null if generation fails
|
|
2240
|
+
* Chat message format with optional sources
|
|
2256
2241
|
*/
|
|
2257
|
-
|
|
2242
|
+
interface ChatMessageWithSources {
|
|
2243
|
+
role: 'user' | 'assistant';
|
|
2244
|
+
content: string;
|
|
2245
|
+
timestamp: string;
|
|
2246
|
+
sources?: Array<{
|
|
2247
|
+
id: string;
|
|
2248
|
+
title: string;
|
|
2249
|
+
type: string;
|
|
2250
|
+
chunk_index: number;
|
|
2251
|
+
slug?: string;
|
|
2252
|
+
}>;
|
|
2253
|
+
}
|
|
2258
2254
|
/**
|
|
2259
|
-
*
|
|
2260
|
-
*
|
|
2261
|
-
* This function returns both the embedding and usage information (tokens used)
|
|
2255
|
+
* Save or update chat session in PayloadCMS
|
|
2262
2256
|
*
|
|
2263
|
-
* @param
|
|
2264
|
-
* @param
|
|
2265
|
-
* @
|
|
2257
|
+
* @param payload - Payload CMS instance
|
|
2258
|
+
* @param userId - User ID
|
|
2259
|
+
* @param conversationId - Conversation ID from Typesense
|
|
2260
|
+
* @param userMessage - User's message
|
|
2261
|
+
* @param assistantMessage - Assistant's response
|
|
2262
|
+
* @param sources - Source chunks used for the response
|
|
2263
|
+
* @param spending - Token spending entries
|
|
2264
|
+
* @param collectionName - Collection name for sessions (default: 'chat-sessions')
|
|
2265
|
+
* @param agentSlug - Slug of the agent used in this conversation (optional)
|
|
2266
2266
|
*/
|
|
2267
|
-
declare
|
|
2267
|
+
declare function saveChatSession(payload: Payload, userId: string | number, conversationId: string, userMessage: string, assistantMessage: string, sources: ChunkSource[], spending: SpendingEntry[], collectionName: CollectionSlug, agentSlug?: string): Promise<void>;
|
|
2268
|
+
//#endregion
|
|
2269
|
+
//#region src/features/rag/endpoints/chat/validators/request-validator.d.ts
|
|
2268
2270
|
/**
|
|
2269
|
-
*
|
|
2270
|
-
*
|
|
2271
|
-
* @param texts - Array of texts to generate embeddings for
|
|
2272
|
-
* @param config - Optional embedding configuration
|
|
2273
|
-
* @returns Embeddings with total usage information, or null if generation fails
|
|
2271
|
+
* JSON Response helper
|
|
2274
2272
|
*/
|
|
2275
|
-
declare const
|
|
2273
|
+
declare const jsonResponse: (data: unknown, options?: ResponseInit) => Response;
|
|
2276
2274
|
//#endregion
|
|
2277
|
-
//#region src/features/rag/
|
|
2275
|
+
//#region src/features/rag/endpoints/types.d.ts
|
|
2278
2276
|
/**
|
|
2279
|
-
*
|
|
2277
|
+
* Framework-agnostic types for API handlers
|
|
2278
|
+
* These types provide compatibility with Next.js without requiring it as a direct dependency
|
|
2280
2279
|
*/
|
|
2281
|
-
interface TypesenseSearchRequest {
|
|
2282
|
-
collection: string;
|
|
2283
|
-
query_by: string;
|
|
2284
|
-
vector_query: string;
|
|
2285
|
-
exclude_fields: string;
|
|
2286
|
-
filter_by?: string;
|
|
2287
|
-
typo_tokens_threshold?: number;
|
|
2288
|
-
num_typos?: number;
|
|
2289
|
-
prefix?: boolean;
|
|
2290
|
-
drop_tokens_threshold?: number;
|
|
2291
|
-
enable_stemming?: boolean;
|
|
2292
|
-
}
|
|
2293
2280
|
/**
|
|
2294
|
-
*
|
|
2295
|
-
*
|
|
2296
|
-
* @param config - Query configuration
|
|
2297
|
-
* @param config.userMessage - The user's message/query
|
|
2298
|
-
* @param config.chatId - Optional conversation ID for follow-up questions
|
|
2299
|
-
* @param conversationModelId - The conversation model ID in Typesense
|
|
2300
|
-
* @param typesenseConfig - Typesense connection config
|
|
2301
|
-
* @returns URL for the Typesense multi_search endpoint with conversation parameters
|
|
2281
|
+
* Context for dynamic route parameters (Next.js App Router style)
|
|
2302
2282
|
*/
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2283
|
+
type ApiContext<T = Record<string, string>> = {
|
|
2284
|
+
params: Promise<T>;
|
|
2285
|
+
};
|
|
2286
|
+
type AuthenticateMethod = (options?: {
|
|
2287
|
+
depth?: number;
|
|
2288
|
+
}) => Promise<{
|
|
2289
|
+
id: string | number;
|
|
2290
|
+
email?: string;
|
|
2291
|
+
} | {
|
|
2292
|
+
error: string;
|
|
2293
|
+
status: number;
|
|
2294
|
+
}>;
|
|
2295
|
+
//#endregion
|
|
2296
|
+
//#region src/features/rag/handlers/chunk-fetch-handler.d.ts
|
|
2307
2297
|
/**
|
|
2308
|
-
*
|
|
2309
|
-
*
|
|
2310
|
-
* @param config - Query configuration including embedding, collections, and filters
|
|
2311
|
-
* @returns Array of search requests for Typesense multi_search
|
|
2298
|
+
* Configuration for fetching a chunk by ID
|
|
2312
2299
|
*/
|
|
2313
|
-
|
|
2300
|
+
type ChunkFetchConfig = {
|
|
2301
|
+
/** Chunk document ID */
|
|
2302
|
+
chunkId: string;
|
|
2303
|
+
/** Collection name */
|
|
2304
|
+
collectionName: string;
|
|
2305
|
+
/** Valid collection names for validation */
|
|
2306
|
+
validCollections?: string[];
|
|
2307
|
+
};
|
|
2314
2308
|
/**
|
|
2315
|
-
*
|
|
2316
|
-
*
|
|
2317
|
-
* @param config - Query configuration
|
|
2318
|
-
* @returns Request body for Typesense multi_search endpoint
|
|
2309
|
+
* Result of fetching a chunk
|
|
2319
2310
|
*/
|
|
2320
|
-
|
|
2321
|
-
|
|
2311
|
+
type ChunkFetchResult = {
|
|
2312
|
+
id: string;
|
|
2313
|
+
chunk_text: string;
|
|
2314
|
+
title?: string;
|
|
2315
|
+
slug?: string;
|
|
2316
|
+
chunk_index?: number;
|
|
2317
|
+
collection: string;
|
|
2322
2318
|
};
|
|
2323
2319
|
/**
|
|
2324
|
-
*
|
|
2320
|
+
* Fetch a chunk document by ID from Typesense
|
|
2325
2321
|
*
|
|
2326
|
-
* @param
|
|
2327
|
-
* @param
|
|
2328
|
-
* @
|
|
2329
|
-
* @
|
|
2322
|
+
* @param client - Typesense client instance
|
|
2323
|
+
* @param config - Chunk fetch configuration
|
|
2324
|
+
* @returns Promise with chunk data
|
|
2325
|
+
* @throws Error if chunk not found or collection is invalid
|
|
2330
2326
|
*/
|
|
2331
|
-
declare function
|
|
2332
|
-
alpha: number;
|
|
2333
|
-
rerank_hybrid_matches: boolean;
|
|
2334
|
-
query_fields: string;
|
|
2335
|
-
};
|
|
2327
|
+
declare function fetchChunkById(client: Client, config: ChunkFetchConfig): Promise<ChunkFetchResult>;
|
|
2336
2328
|
//#endregion
|
|
2337
|
-
//#region src/features/rag/
|
|
2329
|
+
//#region src/features/rag/handlers/rag-search-handler.d.ts
|
|
2338
2330
|
/**
|
|
2339
|
-
*
|
|
2331
|
+
* Configuration for RAG search
|
|
2340
2332
|
*/
|
|
2341
|
-
|
|
2342
|
-
/**
|
|
2343
|
-
|
|
2344
|
-
/**
|
|
2345
|
-
|
|
2346
|
-
/**
|
|
2347
|
-
|
|
2348
|
-
/**
|
|
2349
|
-
|
|
2350
|
-
|
|
2333
|
+
type RAGSearchConfig = {
|
|
2334
|
+
/** Collections to search in */
|
|
2335
|
+
searchCollections: string[];
|
|
2336
|
+
/** Conversation model ID */
|
|
2337
|
+
modelId: string;
|
|
2338
|
+
/** Number of results to retrieve */
|
|
2339
|
+
kResults?: number;
|
|
2340
|
+
/** Advanced search configuration */
|
|
2341
|
+
advancedConfig?: {
|
|
2342
|
+
typoTokensThreshold?: number;
|
|
2343
|
+
numTypos?: number;
|
|
2344
|
+
prefix?: boolean;
|
|
2345
|
+
dropTokensThreshold?: number;
|
|
2346
|
+
};
|
|
2347
|
+
/** Taxonomy slugs to filter RAG content */
|
|
2348
|
+
taxonomySlugs?: string[];
|
|
2349
|
+
};
|
|
2351
2350
|
/**
|
|
2352
|
-
*
|
|
2353
|
-
*/
|
|
2354
|
-
interface StreamProcessingResult {
|
|
2355
|
-
/** Full assistant message */
|
|
2356
|
-
fullMessage: string;
|
|
2357
|
-
/** Conversation ID */
|
|
2358
|
-
conversationId: string | null;
|
|
2359
|
-
/** Extracted sources */
|
|
2360
|
-
sources: ChunkSource[];
|
|
2361
|
-
/** Context text (for token estimation) */
|
|
2362
|
-
contextText: string;
|
|
2363
|
-
}
|
|
2364
|
-
/**
|
|
2365
|
-
* Parse a single SSE event from Typesense conversation stream
|
|
2366
|
-
*
|
|
2367
|
-
* @param line - Raw SSE event line
|
|
2368
|
-
* @returns Parsed conversation event or null if not parseable
|
|
2369
|
-
*/
|
|
2370
|
-
declare function parseConversationEvent(line: string): ConversationEvent | null;
|
|
2371
|
-
/**
|
|
2372
|
-
* Extract sources from Typesense search results
|
|
2373
|
-
*
|
|
2374
|
-
* @param results - Typesense multi-search results array
|
|
2375
|
-
* @param documentTypeResolver - Optional function to resolve document type from collection name
|
|
2376
|
-
* @returns Array of chunk sources with metadata
|
|
2377
|
-
*/
|
|
2378
|
-
declare function extractSourcesFromResults(results: TypesenseRAGSearchResult[], documentTypeResolver?: (collectionName: string) => string): ChunkSource[];
|
|
2379
|
-
/**
|
|
2380
|
-
* Build context text from results (useful for token estimation)
|
|
2381
|
-
*
|
|
2382
|
-
* @param results - Typesense multi-search results array
|
|
2383
|
-
* @returns Combined context text from all chunks
|
|
2384
|
-
*/
|
|
2385
|
-
declare function buildContextText(results: TypesenseRAGSearchResult[]): string;
|
|
2386
|
-
/**
|
|
2387
|
-
* Process a Typesense conversation stream
|
|
2388
|
-
*
|
|
2389
|
-
* @param response - Fetch Response with SSE stream
|
|
2390
|
-
* @param onEvent - Callback for each parsed event
|
|
2391
|
-
* @param documentTypeResolver - Optional function to resolve document type
|
|
2392
|
-
* @returns Processing result with full message, ID, and sources
|
|
2393
|
-
*/
|
|
2394
|
-
declare function processConversationStream(response: Response, onEvent?: (event: ConversationEvent) => void, documentTypeResolver?: (collectionName: string) => string): Promise<StreamProcessingResult>;
|
|
2395
|
-
/**
|
|
2396
|
-
* Create a ReadableStream that forwards SSE events
|
|
2397
|
-
*
|
|
2398
|
-
* @param response - Fetch Response with SSE stream
|
|
2399
|
-
* @param onData - Callback for processing each event before forwarding
|
|
2400
|
-
* @returns ReadableStream for SSE events
|
|
2401
|
-
*/
|
|
2402
|
-
declare function createSSEForwardStream(response: Response, onData?: (event: ConversationEvent) => void): ReadableStream<Uint8Array>;
|
|
2403
|
-
//#endregion
|
|
2404
|
-
//#region src/features/rag/setup.d.ts
|
|
2405
|
-
/**
|
|
2406
|
-
* Ensure conversation history collection exists
|
|
2407
|
-
*
|
|
2408
|
-
* @param client - Typesense client
|
|
2409
|
-
* @param collectionName - Name of the conversation history collection
|
|
2410
|
-
* @returns true if collection exists or was created successfully
|
|
2411
|
-
*/
|
|
2412
|
-
declare function ensureConversationCollection(client: Client, collectionName?: string): Promise<boolean>;
|
|
2413
|
-
/**
|
|
2414
|
-
* Get default RAG configuration values
|
|
2415
|
-
*
|
|
2416
|
-
* @returns Default RAG configuration
|
|
2417
|
-
*/
|
|
2418
|
-
declare function getDefaultRAGConfig(): Required<Omit<RAGConfig, 'agents'>>;
|
|
2419
|
-
/**
|
|
2420
|
-
* Merge user RAG config with defaults
|
|
2421
|
-
*
|
|
2422
|
-
* @param userConfig - User-provided RAG configuration
|
|
2423
|
-
* @returns Merged configuration with defaults
|
|
2424
|
-
*/
|
|
2425
|
-
declare function mergeRAGConfigWithDefaults(userConfig?: RAGConfig): RAGConfig;
|
|
2426
|
-
//#endregion
|
|
2427
|
-
//#region src/features/rag/handlers/rag-search-handler.d.ts
|
|
2428
|
-
/**
|
|
2429
|
-
* Configuration for RAG search
|
|
2430
|
-
*/
|
|
2431
|
-
type RAGSearchConfig = {
|
|
2432
|
-
/** Collections to search in */
|
|
2433
|
-
searchCollections: string[];
|
|
2434
|
-
/** Conversation model ID */
|
|
2435
|
-
modelId: string;
|
|
2436
|
-
/** Number of results to retrieve */
|
|
2437
|
-
kResults?: number;
|
|
2438
|
-
/** Advanced search configuration */
|
|
2439
|
-
advancedConfig?: {
|
|
2440
|
-
typoTokensThreshold?: number;
|
|
2441
|
-
numTypos?: number;
|
|
2442
|
-
prefix?: boolean;
|
|
2443
|
-
dropTokensThreshold?: number;
|
|
2444
|
-
};
|
|
2445
|
-
/** Taxonomy slugs to filter RAG content */
|
|
2446
|
-
taxonomySlugs?: string[];
|
|
2447
|
-
};
|
|
2448
|
-
/**
|
|
2449
|
-
* Request parameters for RAG chat
|
|
2351
|
+
* Request parameters for RAG chat
|
|
2450
2352
|
*/
|
|
2451
2353
|
type RAGChatRequest = {
|
|
2452
2354
|
/** User's message */
|
|
@@ -2489,39 +2391,6 @@ type RAGSearchResult = {
|
|
|
2489
2391
|
*/
|
|
2490
2392
|
declare function executeRAGSearch(typesenseConfig: TypesenseConnectionConfig, searchConfig: RAGSearchConfig, request: RAGChatRequest): Promise<RAGSearchResult>;
|
|
2491
2393
|
//#endregion
|
|
2492
|
-
//#region src/features/rag/handlers/chunk-fetch-handler.d.ts
|
|
2493
|
-
/**
|
|
2494
|
-
* Configuration for fetching a chunk by ID
|
|
2495
|
-
*/
|
|
2496
|
-
type ChunkFetchConfig = {
|
|
2497
|
-
/** Chunk document ID */
|
|
2498
|
-
chunkId: string;
|
|
2499
|
-
/** Collection name */
|
|
2500
|
-
collectionName: string;
|
|
2501
|
-
/** Valid collection names for validation */
|
|
2502
|
-
validCollections?: string[];
|
|
2503
|
-
};
|
|
2504
|
-
/**
|
|
2505
|
-
* Result of fetching a chunk
|
|
2506
|
-
*/
|
|
2507
|
-
type ChunkFetchResult = {
|
|
2508
|
-
id: string;
|
|
2509
|
-
chunk_text: string;
|
|
2510
|
-
title?: string;
|
|
2511
|
-
slug?: string;
|
|
2512
|
-
chunk_index?: number;
|
|
2513
|
-
collection: string;
|
|
2514
|
-
};
|
|
2515
|
-
/**
|
|
2516
|
-
* Fetch a chunk document by ID from Typesense
|
|
2517
|
-
*
|
|
2518
|
-
* @param client - Typesense client instance
|
|
2519
|
-
* @param config - Chunk fetch configuration
|
|
2520
|
-
* @returns Promise with chunk data
|
|
2521
|
-
* @throws Error if chunk not found or collection is invalid
|
|
2522
|
-
*/
|
|
2523
|
-
declare function fetchChunkById(client: Client, config: ChunkFetchConfig): Promise<ChunkFetchResult>;
|
|
2524
|
-
//#endregion
|
|
2525
2394
|
//#region src/features/rag/handlers/session-handlers.d.ts
|
|
2526
2395
|
/**
|
|
2527
2396
|
* Session data structure
|
|
@@ -2574,111 +2443,175 @@ declare function getSessionByConversationId<TSlug extends CollectionSlug>(payloa
|
|
|
2574
2443
|
*/
|
|
2575
2444
|
declare function closeSession<TSlug extends CollectionSlug>(payload: Payload, userId: string | number, conversationId: string, config?: SessionConfig<TSlug>): Promise<ChatSessionData | null>;
|
|
2576
2445
|
//#endregion
|
|
2577
|
-
//#region src/features/rag/
|
|
2446
|
+
//#region src/features/rag/query-builder.d.ts
|
|
2578
2447
|
/**
|
|
2579
|
-
*
|
|
2448
|
+
* Typesense search request object
|
|
2449
|
+
*/
|
|
2450
|
+
interface TypesenseSearchRequest {
|
|
2451
|
+
collection: string;
|
|
2452
|
+
query_by: string;
|
|
2453
|
+
vector_query: string;
|
|
2454
|
+
exclude_fields: string;
|
|
2455
|
+
filter_by?: string;
|
|
2456
|
+
typo_tokens_threshold?: number;
|
|
2457
|
+
num_typos?: number;
|
|
2458
|
+
prefix?: boolean;
|
|
2459
|
+
drop_tokens_threshold?: number;
|
|
2460
|
+
enable_stemming?: boolean;
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Build the Typesense conversational search URL with all necessary parameters
|
|
2580
2464
|
*
|
|
2581
|
-
* @param
|
|
2582
|
-
* @
|
|
2465
|
+
* @param config - Query configuration
|
|
2466
|
+
* @param config.userMessage - The user's message/query
|
|
2467
|
+
* @param config.chatId - Optional conversation ID for follow-up questions
|
|
2468
|
+
* @param conversationModelId - The conversation model ID in Typesense
|
|
2469
|
+
* @param typesenseConfig - Typesense connection config
|
|
2470
|
+
* @returns URL for the Typesense multi_search endpoint with conversation parameters
|
|
2583
2471
|
*/
|
|
2584
|
-
declare function
|
|
2472
|
+
declare function buildConversationalUrl(config: {
|
|
2473
|
+
userMessage: string;
|
|
2474
|
+
chatId?: string;
|
|
2475
|
+
}, conversationModelId: string, typesenseConfig: TypesenseConnectionConfig): URL;
|
|
2585
2476
|
/**
|
|
2586
|
-
*
|
|
2477
|
+
* Build multi-search requests for Typesense with hybrid search configuration
|
|
2587
2478
|
*
|
|
2588
|
-
* @param
|
|
2589
|
-
* @
|
|
2590
|
-
* @param event - SSE event to send
|
|
2479
|
+
* @param config - Query configuration including embedding, collections, and filters
|
|
2480
|
+
* @returns Array of search requests for Typesense multi_search
|
|
2591
2481
|
*/
|
|
2592
|
-
declare function
|
|
2593
|
-
//#endregion
|
|
2594
|
-
//#region src/features/rag/chat-session-repository.d.ts
|
|
2482
|
+
declare function buildMultiSearchRequests(config: TypesenseQueryConfig): TypesenseSearchRequest[];
|
|
2595
2483
|
/**
|
|
2596
|
-
*
|
|
2484
|
+
* Build the complete Typesense request body for multi-search
|
|
2485
|
+
*
|
|
2486
|
+
* @param config - Query configuration
|
|
2487
|
+
* @returns Request body for Typesense multi_search endpoint
|
|
2597
2488
|
*/
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
timestamp: string;
|
|
2602
|
-
sources?: Array<{
|
|
2603
|
-
id: string;
|
|
2604
|
-
title: string;
|
|
2605
|
-
type: string;
|
|
2606
|
-
chunk_index: number;
|
|
2607
|
-
slug?: string;
|
|
2608
|
-
}>;
|
|
2609
|
-
}
|
|
2489
|
+
declare function buildMultiSearchRequestBody(config: TypesenseQueryConfig): {
|
|
2490
|
+
searches: TypesenseSearchRequest[];
|
|
2491
|
+
};
|
|
2610
2492
|
/**
|
|
2611
|
-
*
|
|
2493
|
+
* Build hybrid search parameters for combining semantic and keyword search
|
|
2612
2494
|
*
|
|
2613
|
-
* @param
|
|
2614
|
-
* @param
|
|
2615
|
-
* @param
|
|
2616
|
-
* @
|
|
2617
|
-
* @param assistantMessage - Assistant's response
|
|
2618
|
-
* @param sources - Source chunks used for the response
|
|
2619
|
-
* @param spending - Token spending entries
|
|
2620
|
-
* @param collectionName - Collection name for sessions (default: 'chat-sessions')
|
|
2621
|
-
* @param agentSlug - Slug of the agent used in this conversation (optional)
|
|
2495
|
+
* @param alpha - Weight between semantic (1.0) and keyword (0.0) search
|
|
2496
|
+
* @param rerankMatches - Whether to rerank hybrid search results
|
|
2497
|
+
* @param queryFields - Fields to use for keyword search
|
|
2498
|
+
* @returns Object with hybrid search parameters
|
|
2622
2499
|
*/
|
|
2623
|
-
declare function
|
|
2500
|
+
declare function buildHybridSearchParams(alpha?: number, rerankMatches?: boolean, queryFields?: string): {
|
|
2501
|
+
alpha: number;
|
|
2502
|
+
rerank_hybrid_matches: boolean;
|
|
2503
|
+
query_fields: string;
|
|
2504
|
+
};
|
|
2624
2505
|
//#endregion
|
|
2625
|
-
//#region src/features/rag/
|
|
2506
|
+
//#region src/features/rag/setup.d.ts
|
|
2626
2507
|
/**
|
|
2627
|
-
*
|
|
2628
|
-
*
|
|
2508
|
+
* Ensure conversation history collection exists
|
|
2509
|
+
*
|
|
2510
|
+
* @param client - Typesense client
|
|
2511
|
+
* @param collectionName - Name of the conversation history collection
|
|
2512
|
+
* @returns true if collection exists or was created successfully
|
|
2629
2513
|
*/
|
|
2514
|
+
declare function ensureConversationCollection(client: Client, collectionName?: string): Promise<boolean>;
|
|
2630
2515
|
/**
|
|
2631
|
-
*
|
|
2516
|
+
* Get default RAG configuration values
|
|
2517
|
+
*
|
|
2518
|
+
* @returns Default RAG configuration
|
|
2632
2519
|
*/
|
|
2633
|
-
|
|
2634
|
-
params: Promise<T>;
|
|
2635
|
-
};
|
|
2636
|
-
type AuthenticateMethod = (options?: {
|
|
2637
|
-
depth?: number;
|
|
2638
|
-
}) => Promise<{
|
|
2639
|
-
id: string | number;
|
|
2640
|
-
email?: string;
|
|
2641
|
-
} | {
|
|
2642
|
-
error: string;
|
|
2643
|
-
status: number;
|
|
2644
|
-
}>;
|
|
2645
|
-
//#endregion
|
|
2646
|
-
//#region src/features/rag/endpoints/chat/validators/request-validator.d.ts
|
|
2520
|
+
declare function getDefaultRAGConfig(): Required<Omit<RAGConfig, 'agents'>>;
|
|
2647
2521
|
/**
|
|
2648
|
-
*
|
|
2522
|
+
* Merge user RAG config with defaults
|
|
2523
|
+
*
|
|
2524
|
+
* @param userConfig - User-provided RAG configuration
|
|
2525
|
+
* @returns Merged configuration with defaults
|
|
2649
2526
|
*/
|
|
2650
|
-
declare
|
|
2527
|
+
declare function mergeRAGConfigWithDefaults(userConfig?: RAGConfig): RAGConfig;
|
|
2651
2528
|
//#endregion
|
|
2652
|
-
//#region src/
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
autoSync?: boolean;
|
|
2666
|
-
batchSize?: number;
|
|
2667
|
-
}
|
|
2668
|
-
interface FeatureFlags {
|
|
2669
|
-
embedding?: EmbeddingProviderConfig$1;
|
|
2670
|
-
search?: SearchFeatureConfig;
|
|
2671
|
-
rag?: RAGFeatureConfig;
|
|
2672
|
-
sync?: SyncFeatureConfig;
|
|
2529
|
+
//#region src/features/rag/stream-handler.d.ts
|
|
2530
|
+
/**
|
|
2531
|
+
* Parsed conversation event from Typesense SSE stream
|
|
2532
|
+
*/
|
|
2533
|
+
interface ConversationEvent {
|
|
2534
|
+
/** Conversation ID */
|
|
2535
|
+
conversationId?: string;
|
|
2536
|
+
/** Message token/chunk */
|
|
2537
|
+
message?: string;
|
|
2538
|
+
/** Search results (only in first event) */
|
|
2539
|
+
results?: TypesenseRAGSearchResult[];
|
|
2540
|
+
/** Raw parsed data */
|
|
2541
|
+
raw?: unknown;
|
|
2673
2542
|
}
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2543
|
+
/**
|
|
2544
|
+
* Stream processing result
|
|
2545
|
+
*/
|
|
2546
|
+
interface StreamProcessingResult {
|
|
2547
|
+
/** Full assistant message */
|
|
2548
|
+
fullMessage: string;
|
|
2549
|
+
/** Conversation ID */
|
|
2550
|
+
conversationId: string | null;
|
|
2551
|
+
/** Extracted sources */
|
|
2552
|
+
sources: ChunkSource[];
|
|
2553
|
+
/** Context text (for token estimation) */
|
|
2554
|
+
contextText: string;
|
|
2678
2555
|
}
|
|
2556
|
+
/**
|
|
2557
|
+
* Parse a single SSE event from Typesense conversation stream
|
|
2558
|
+
*
|
|
2559
|
+
* @param line - Raw SSE event line
|
|
2560
|
+
* @returns Parsed conversation event or null if not parseable
|
|
2561
|
+
*/
|
|
2562
|
+
declare function parseConversationEvent(line: string): ConversationEvent | null;
|
|
2563
|
+
/**
|
|
2564
|
+
* Extract sources from Typesense search results
|
|
2565
|
+
*
|
|
2566
|
+
* @param results - Typesense multi-search results array
|
|
2567
|
+
* @param documentTypeResolver - Optional function to resolve document type from collection name
|
|
2568
|
+
* @returns Array of chunk sources with metadata
|
|
2569
|
+
*/
|
|
2570
|
+
declare function extractSourcesFromResults(results: TypesenseRAGSearchResult[], documentTypeResolver?: (collectionName: string) => string): ChunkSource[];
|
|
2571
|
+
/**
|
|
2572
|
+
* Build context text from results (useful for token estimation)
|
|
2573
|
+
*
|
|
2574
|
+
* @param results - Typesense multi-search results array
|
|
2575
|
+
* @returns Combined context text from all chunks
|
|
2576
|
+
*/
|
|
2577
|
+
declare function buildContextText(results: TypesenseRAGSearchResult[]): string;
|
|
2578
|
+
/**
|
|
2579
|
+
* Process a Typesense conversation stream
|
|
2580
|
+
*
|
|
2581
|
+
* @param response - Fetch Response with SSE stream
|
|
2582
|
+
* @param onEvent - Callback for each parsed event
|
|
2583
|
+
* @param documentTypeResolver - Optional function to resolve document type
|
|
2584
|
+
* @returns Processing result with full message, ID, and sources
|
|
2585
|
+
*/
|
|
2586
|
+
declare function processConversationStream(response: Response, onEvent?: (event: ConversationEvent) => void, documentTypeResolver?: (collectionName: string) => string): Promise<StreamProcessingResult>;
|
|
2587
|
+
/**
|
|
2588
|
+
* Create a ReadableStream that forwards SSE events
|
|
2589
|
+
*
|
|
2590
|
+
* @param response - Fetch Response with SSE stream
|
|
2591
|
+
* @param onData - Callback for processing each event before forwarding
|
|
2592
|
+
* @returns ReadableStream for SSE events
|
|
2593
|
+
*/
|
|
2594
|
+
declare function createSSEForwardStream(response: Response, onData?: (event: ConversationEvent) => void): ReadableStream<Uint8Array>;
|
|
2595
|
+
//#endregion
|
|
2596
|
+
//#region src/features/rag/utils/sse-utils.d.ts
|
|
2597
|
+
/**
|
|
2598
|
+
* Helper to create an SSE event string
|
|
2599
|
+
*
|
|
2600
|
+
* @param event - SSE event object
|
|
2601
|
+
* @returns Formatted SSE event string
|
|
2602
|
+
*/
|
|
2603
|
+
declare function formatSSEEvent(event: SSEEvent): string;
|
|
2604
|
+
/**
|
|
2605
|
+
* Helper to send an SSE event through a controller
|
|
2606
|
+
*
|
|
2607
|
+
* @param controller - ReadableStreamDefaultController
|
|
2608
|
+
* @param encoder - TextEncoder instance
|
|
2609
|
+
* @param event - SSE event to send
|
|
2610
|
+
*/
|
|
2611
|
+
declare function sendSSEEvent(controller: ReadableStreamDefaultController<Uint8Array>, encoder: TextEncoder, event: SSEEvent): void;
|
|
2679
2612
|
//#endregion
|
|
2680
2613
|
//#region src/core/client/typesense-client.d.ts
|
|
2681
|
-
declare const createTypesenseClient: (typesenseConfig: TypesenseConnectionConfig) =>
|
|
2614
|
+
declare const createTypesenseClient: (typesenseConfig: TypesenseConnectionConfig) => Client;
|
|
2682
2615
|
declare const testTypesenseConnection: (client: Client) => Promise<boolean>;
|
|
2683
2616
|
//#endregion
|
|
2684
2617
|
//#region src/features/sync/services/document-delete.d.ts
|
|
@@ -2688,13 +2621,6 @@ declare const testTypesenseConnection: (client: Client) => Promise<boolean>;
|
|
|
2688
2621
|
*/
|
|
2689
2622
|
declare const deleteDocumentFromTypesense: (typesenseClient: Client, collectionSlug: string, docId: string, tableConfig: TableConfig) => Promise<void>;
|
|
2690
2623
|
//#endregion
|
|
2691
|
-
//#region src/features/search/endpoints.d.ts
|
|
2692
|
-
declare const createSearchEndpoints: (typesenseClient: Client, pluginOptions: ModularPluginConfig) => {
|
|
2693
|
-
handler: payload0.PayloadHandler;
|
|
2694
|
-
method: "get";
|
|
2695
|
-
path: string;
|
|
2696
|
-
}[];
|
|
2697
|
-
//#endregion
|
|
2698
2624
|
//#region src/features/rag/endpoints.d.ts
|
|
2699
2625
|
/**
|
|
2700
2626
|
* Creates Payload handlers for RAG endpoints
|
|
@@ -2707,6 +2633,13 @@ declare function createRAGPayloadHandlers<TSlug extends CollectionSlug>(config:
|
|
|
2707
2633
|
handler: PayloadHandler;
|
|
2708
2634
|
}>;
|
|
2709
2635
|
//#endregion
|
|
2636
|
+
//#region src/features/search/endpoints.d.ts
|
|
2637
|
+
declare const createSearchEndpoints: (typesenseClient: Client, pluginOptions: ModularPluginConfig) => {
|
|
2638
|
+
handler: payload0.PayloadHandler;
|
|
2639
|
+
method: "get";
|
|
2640
|
+
path: string;
|
|
2641
|
+
}[];
|
|
2642
|
+
//#endregion
|
|
2710
2643
|
//#region src/core/config/constants.d.ts
|
|
2711
2644
|
/**
|
|
2712
2645
|
* Constants for payload-typesense plugin
|