@langchain/core 1.0.0-alpha.3 → 1.0.0-alpha.5
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 +3 -19
- package/dist/agents.d.ts.map +1 -1
- package/dist/caches/base.cjs +2 -2
- package/dist/caches/base.cjs.map +1 -1
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/document_loaders/langsmith.cjs +1 -1
- package/dist/document_loaders/langsmith.cjs.map +1 -1
- package/dist/document_loaders/langsmith.js +1 -1
- package/dist/document_loaders/langsmith.js.map +1 -1
- package/dist/embeddings.cjs.map +1 -1
- package/dist/embeddings.d.cts +6 -6
- package/dist/embeddings.d.cts.map +1 -1
- package/dist/embeddings.d.ts +6 -6
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/indexing/base.cjs +2 -2
- package/dist/indexing/base.cjs.map +1 -1
- package/dist/indexing/base.d.cts +0 -3
- package/dist/indexing/base.d.cts.map +1 -1
- package/dist/indexing/base.d.ts +0 -3
- package/dist/indexing/base.d.ts.map +1 -1
- package/dist/indexing/base.js +2 -2
- package/dist/indexing/base.js.map +1 -1
- package/dist/language_models/base.cjs +1 -1
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +3 -3
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +3 -3
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +1 -1
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/chat_models.cjs.map +1 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/language_models/chat_models.js.map +1 -1
- package/dist/language_models/llms.cjs.map +1 -1
- package/dist/language_models/llms.js.map +1 -1
- package/dist/load/import_map.cjs +0 -4
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +2 -6
- package/dist/load/import_map.js.map +1 -1
- package/dist/load/index.cjs.map +1 -1
- package/dist/load/index.js.map +1 -1
- package/dist/load/serializable.cjs.map +1 -1
- package/dist/load/serializable.d.cts +1 -3
- package/dist/load/serializable.d.cts.map +1 -1
- package/dist/load/serializable.d.ts +1 -3
- package/dist/load/serializable.d.ts.map +1 -1
- package/dist/load/serializable.js.map +1 -1
- package/dist/messages/ai.cjs +17 -12
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +17 -12
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +12 -5
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.d.cts +1 -2
- package/dist/messages/base.d.cts.map +1 -1
- package/dist/messages/base.d.ts +1 -2
- package/dist/messages/base.d.ts.map +1 -1
- package/dist/messages/base.js +12 -5
- package/dist/messages/base.js.map +1 -1
- package/dist/messages/block_translators/utils.cjs +1 -1
- package/dist/messages/block_translators/utils.cjs.map +1 -1
- package/dist/messages/block_translators/utils.js +1 -1
- package/dist/messages/block_translators/utils.js.map +1 -1
- package/dist/messages/index.cjs +1 -1
- package/dist/messages/index.js +1 -1
- package/dist/messages/modifier.cjs +4 -1
- package/dist/messages/modifier.cjs.map +1 -1
- package/dist/messages/modifier.js +4 -1
- package/dist/messages/modifier.js.map +1 -1
- package/dist/messages/tool.cjs +7 -7
- package/dist/messages/tool.cjs.map +1 -1
- package/dist/messages/tool.js +7 -7
- package/dist/messages/tool.js.map +1 -1
- package/dist/messages/transformers.cjs +2 -2
- package/dist/messages/transformers.cjs.map +1 -1
- package/dist/messages/transformers.js +2 -2
- package/dist/messages/transformers.js.map +1 -1
- package/dist/messages/utils.cjs +5 -0
- package/dist/messages/utils.cjs.map +1 -1
- package/dist/messages/utils.js +5 -0
- package/dist/messages/utils.js.map +1 -1
- package/dist/output_parsers/list.cjs +1 -1
- package/dist/output_parsers/list.cjs.map +1 -1
- package/dist/output_parsers/list.js +1 -1
- package/dist/output_parsers/list.js.map +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +1 -1
- package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.cjs.map +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js +1 -1
- package/dist/output_parsers/openai_tools/json_output_tools_parsers.js.map +1 -1
- package/dist/output_parsers/structured.cjs +2 -1
- package/dist/output_parsers/structured.cjs.map +1 -1
- package/dist/output_parsers/structured.js +2 -1
- package/dist/output_parsers/structured.js.map +1 -1
- package/dist/prompts/chat.cjs +3 -1
- package/dist/prompts/chat.cjs.map +1 -1
- package/dist/prompts/chat.d.cts +4 -12
- package/dist/prompts/chat.d.cts.map +1 -1
- package/dist/prompts/chat.d.ts +4 -12
- package/dist/prompts/chat.d.ts.map +1 -1
- package/dist/prompts/chat.js +3 -1
- package/dist/prompts/chat.js.map +1 -1
- package/dist/prompts/image.cjs.map +1 -1
- package/dist/prompts/image.d.cts +0 -2
- package/dist/prompts/image.d.cts.map +1 -1
- package/dist/prompts/image.d.ts +0 -2
- package/dist/prompts/image.d.ts.map +1 -1
- package/dist/prompts/image.js.map +1 -1
- package/dist/prompts/pipeline.cjs.map +1 -1
- package/dist/prompts/pipeline.js.map +1 -1
- package/dist/prompts/prompt.cjs.map +1 -1
- package/dist/prompts/prompt.d.cts +4 -16
- package/dist/prompts/prompt.d.cts.map +1 -1
- package/dist/prompts/prompt.d.ts +4 -16
- package/dist/prompts/prompt.d.ts.map +1 -1
- package/dist/prompts/prompt.js.map +1 -1
- package/dist/prompts/structured.cjs.map +1 -1
- package/dist/prompts/structured.js.map +1 -1
- package/dist/prompts/template.cjs +4 -2
- package/dist/prompts/template.cjs.map +1 -1
- package/dist/prompts/template.js +4 -2
- package/dist/prompts/template.js.map +1 -1
- package/dist/runnables/base.cjs +6 -6
- package/dist/runnables/base.cjs.map +1 -1
- package/dist/runnables/base.d.cts +0 -3
- package/dist/runnables/base.d.cts.map +1 -1
- package/dist/runnables/base.d.ts +0 -3
- package/dist/runnables/base.d.ts.map +1 -1
- package/dist/runnables/base.js +6 -6
- package/dist/runnables/base.js.map +1 -1
- package/dist/runnables/branch.cjs +2 -2
- package/dist/runnables/branch.cjs.map +1 -1
- package/dist/runnables/branch.js +2 -2
- package/dist/runnables/branch.js.map +1 -1
- package/dist/runnables/config.cjs.map +1 -1
- package/dist/runnables/config.js.map +1 -1
- package/dist/runnables/graph.cjs +1 -1
- package/dist/runnables/graph.cjs.map +1 -1
- package/dist/runnables/graph.js +1 -1
- package/dist/runnables/graph.js.map +1 -1
- package/dist/runnables/graph_mermaid.cjs +26 -3
- package/dist/runnables/graph_mermaid.cjs.map +1 -1
- package/dist/runnables/graph_mermaid.js +26 -3
- package/dist/runnables/graph_mermaid.js.map +1 -1
- package/dist/runnables/remote.cjs.map +1 -1
- package/dist/runnables/remote.js.map +1 -1
- package/dist/runnables/types.d.cts +0 -1
- package/dist/runnables/types.d.cts.map +1 -1
- package/dist/runnables/types.d.ts +0 -1
- package/dist/runnables/types.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.cjs.map +1 -1
- package/dist/singletons/async_local_storage/context.d.cts +0 -1
- package/dist/singletons/async_local_storage/context.d.cts.map +1 -1
- package/dist/singletons/async_local_storage/context.d.ts +0 -1
- package/dist/singletons/async_local_storage/context.d.ts.map +1 -1
- package/dist/singletons/async_local_storage/context.js.map +1 -1
- package/dist/singletons/callbacks.cjs.map +1 -1
- package/dist/singletons/callbacks.js.map +1 -1
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +2 -2
- package/dist/tools/index.d.cts.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/types.d.cts +5 -5
- package/dist/tools/types.d.cts.map +1 -1
- package/dist/tools/types.d.ts +5 -5
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tracers/base.cjs.map +1 -1
- package/dist/tracers/base.js.map +1 -1
- package/dist/tracers/console.cjs +1 -1
- package/dist/tracers/console.cjs.map +1 -1
- package/dist/tracers/console.js +1 -1
- package/dist/tracers/console.js.map +1 -1
- package/dist/tracers/event_stream.cjs +1 -1
- package/dist/tracers/event_stream.cjs.map +1 -1
- package/dist/tracers/event_stream.d.cts +0 -1
- package/dist/tracers/event_stream.d.cts.map +1 -1
- package/dist/tracers/event_stream.d.ts +0 -1
- package/dist/tracers/event_stream.d.ts.map +1 -1
- package/dist/tracers/event_stream.js +1 -1
- package/dist/tracers/event_stream.js.map +1 -1
- package/dist/tracers/log_stream.cjs.map +1 -1
- package/dist/tracers/log_stream.js.map +1 -1
- package/dist/tracers/tracer_langchain.cjs.map +1 -1
- package/dist/tracers/tracer_langchain.js.map +1 -1
- package/dist/utils/chunk_array.cjs.map +1 -1
- package/dist/utils/chunk_array.js.map +1 -1
- package/dist/utils/env.cjs +1 -1
- package/dist/utils/env.cjs.map +1 -1
- package/dist/utils/env.js +1 -1
- package/dist/utils/env.js.map +1 -1
- package/dist/utils/event_source_parse.cjs.map +1 -1
- package/dist/utils/event_source_parse.d.cts.map +1 -1
- package/dist/utils/event_source_parse.d.ts.map +1 -1
- package/dist/utils/event_source_parse.js.map +1 -1
- package/dist/utils/hash.cjs +3 -8
- package/dist/utils/hash.cjs.map +1 -1
- package/dist/utils/hash.d.cts +1 -2
- package/dist/utils/hash.d.cts.map +1 -1
- package/dist/utils/hash.d.ts +1 -2
- package/dist/utils/hash.d.ts.map +1 -1
- package/dist/utils/hash.js +2 -6
- package/dist/utils/hash.js.map +1 -1
- package/dist/utils/js-sha256/hash.cjs +0 -9
- package/dist/utils/js-sha256/hash.cjs.map +1 -1
- package/dist/utils/js-sha256/hash.js +1 -5
- package/dist/utils/js-sha256/hash.js.map +1 -1
- package/dist/utils/json.cjs +2 -2
- package/dist/utils/json.cjs.map +1 -1
- package/dist/utils/json.js +2 -2
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/json_schema.cjs +3 -2
- package/dist/utils/json_schema.cjs.map +1 -1
- package/dist/utils/json_schema.d.cts +8 -4
- package/dist/utils/json_schema.d.cts.map +1 -1
- package/dist/utils/json_schema.d.ts +8 -4
- package/dist/utils/json_schema.d.ts.map +1 -1
- package/dist/utils/json_schema.js +2 -1
- package/dist/utils/json_schema.js.map +1 -1
- package/dist/utils/stream.cjs.map +1 -1
- package/dist/utils/stream.js.map +1 -1
- package/dist/utils/testing/chat_models.cjs +245 -0
- package/dist/utils/testing/chat_models.cjs.map +1 -0
- package/dist/utils/testing/chat_models.d.cts +134 -0
- package/dist/utils/testing/chat_models.d.cts.map +1 -0
- package/dist/utils/testing/chat_models.d.ts +134 -0
- package/dist/utils/testing/chat_models.d.ts.map +1 -0
- package/dist/utils/testing/chat_models.js +243 -0
- package/dist/utils/testing/chat_models.js.map +1 -0
- package/dist/utils/testing/embeddings.cjs +90 -0
- package/dist/utils/testing/embeddings.cjs.map +1 -0
- package/dist/utils/testing/embeddings.d.cts +58 -0
- package/dist/utils/testing/embeddings.d.cts.map +1 -0
- package/dist/utils/testing/embeddings.d.ts +58 -0
- package/dist/utils/testing/embeddings.d.ts.map +1 -0
- package/dist/utils/testing/embeddings.js +89 -0
- package/dist/utils/testing/embeddings.js.map +1 -0
- package/dist/utils/testing/index.cjs +42 -655
- package/dist/utils/testing/index.cjs.map +1 -1
- package/dist/utils/testing/index.d.cts +11 -384
- package/dist/utils/testing/index.d.ts +11 -384
- package/dist/utils/testing/index.js +10 -623
- package/dist/utils/testing/index.js.map +1 -1
- package/dist/utils/testing/llms.cjs +59 -0
- package/dist/utils/testing/llms.cjs.map +1 -0
- package/dist/utils/testing/llms.d.cts +31 -0
- package/dist/utils/testing/llms.d.cts.map +1 -0
- package/dist/utils/testing/llms.d.ts +31 -0
- package/dist/utils/testing/llms.d.ts.map +1 -0
- package/dist/utils/testing/llms.js +58 -0
- package/dist/utils/testing/llms.js.map +1 -0
- package/dist/utils/testing/message_history.cjs +67 -0
- package/dist/utils/testing/message_history.cjs.map +1 -0
- package/dist/utils/testing/message_history.d.cts +31 -0
- package/dist/utils/testing/message_history.d.cts.map +1 -0
- package/dist/utils/testing/message_history.d.ts +31 -0
- package/dist/utils/testing/message_history.d.ts.map +1 -0
- package/dist/utils/testing/message_history.js +65 -0
- package/dist/utils/testing/message_history.js.map +1 -0
- package/dist/utils/testing/output_parsers.cjs +20 -0
- package/dist/utils/testing/output_parsers.cjs.map +1 -0
- package/dist/utils/testing/output_parsers.d.cts +16 -0
- package/dist/utils/testing/output_parsers.d.cts.map +1 -0
- package/dist/utils/testing/output_parsers.d.ts +16 -0
- package/dist/utils/testing/output_parsers.d.ts.map +1 -0
- package/dist/utils/testing/output_parsers.js +20 -0
- package/dist/utils/testing/output_parsers.js.map +1 -0
- package/dist/utils/testing/retrievers.cjs +19 -0
- package/dist/utils/testing/retrievers.cjs.map +1 -0
- package/dist/utils/testing/retrievers.d.cts +17 -0
- package/dist/utils/testing/retrievers.d.cts.map +1 -0
- package/dist/utils/testing/retrievers.d.ts +17 -0
- package/dist/utils/testing/retrievers.d.ts.map +1 -0
- package/dist/utils/testing/retrievers.js +19 -0
- package/dist/utils/testing/retrievers.js.map +1 -0
- package/dist/utils/testing/runnables.cjs +19 -0
- package/dist/utils/testing/runnables.cjs.map +1 -0
- package/dist/utils/testing/runnables.d.cts +15 -0
- package/dist/utils/testing/runnables.d.cts.map +1 -0
- package/dist/utils/testing/runnables.d.ts +15 -0
- package/dist/utils/testing/runnables.d.ts.map +1 -0
- package/dist/utils/testing/runnables.js +19 -0
- package/dist/utils/testing/runnables.js.map +1 -0
- package/dist/utils/testing/tools.cjs +21 -0
- package/dist/utils/testing/tools.cjs.map +1 -0
- package/dist/utils/testing/tools.d.cts +21 -0
- package/dist/utils/testing/tools.d.cts.map +1 -0
- package/dist/utils/testing/tools.d.ts +21 -0
- package/dist/utils/testing/tools.d.ts.map +1 -0
- package/dist/utils/testing/tools.js +21 -0
- package/dist/utils/testing/tools.js.map +1 -0
- package/dist/utils/testing/tracers.cjs +25 -0
- package/dist/utils/testing/tracers.cjs.map +1 -0
- package/dist/utils/testing/tracers.d.cts +15 -0
- package/dist/utils/testing/tracers.d.cts.map +1 -0
- package/dist/utils/testing/tracers.d.ts +15 -0
- package/dist/utils/testing/tracers.d.ts.map +1 -0
- package/dist/utils/testing/tracers.js +25 -0
- package/dist/utils/testing/tracers.js.map +1 -0
- package/dist/utils/testing/vectorstores.cjs +129 -0
- package/dist/utils/testing/vectorstores.cjs.map +1 -0
- package/dist/utils/testing/vectorstores.d.cts +101 -0
- package/dist/utils/testing/vectorstores.d.cts.map +1 -0
- package/dist/utils/testing/vectorstores.d.ts +101 -0
- package/dist/utils/testing/vectorstores.d.ts.map +1 -0
- package/dist/utils/testing/vectorstores.js +129 -0
- package/dist/utils/testing/vectorstores.js.map +1 -0
- package/dist/utils/zod-to-json-schema/Options.cjs +40 -0
- package/dist/utils/zod-to-json-schema/Options.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Options.js +37 -0
- package/dist/utils/zod-to-json-schema/Options.js.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs +30 -0
- package/dist/utils/zod-to-json-schema/Refs.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/Refs.js +30 -0
- package/dist/utils/zod-to-json-schema/Refs.js.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs +18 -0
- package/dist/utils/zod-to-json-schema/errorMessages.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/errorMessages.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js +16 -0
- package/dist/utils/zod-to-json-schema/errorMessages.js.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs +11 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js +10 -0
- package/dist/utils/zod-to-json-schema/getRelativePath.js.map +1 -0
- package/dist/utils/zod-to-json-schema/index.cjs +37 -0
- package/dist/utils/zod-to-json-schema/index.js +37 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parseDef.js +57 -0
- package/dist/utils/zod-to-json-schema/parseDef.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts +38 -0
- package/dist/utils/zod-to-json-schema/parseTypes.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/any.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/any.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs +24 -0
- package/dist/utils/zod-to-json-schema/parsers/array.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/array.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js +23 -0
- package/dist/utils/zod-to-json-schema/parsers/array.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js +36 -0
- package/dist/utils/zod-to-json-schema/parsers/bigint.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs +9 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js +8 -0
- package/dist/utils/zod-to-json-schema/parsers/boolean.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/branded.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/catch.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/date.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js +39 -0
- package/dist/utils/zod-to-json-schema/parsers/date.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/default.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/effects.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/enum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js +47 -0
- package/dist/utils/zod-to-json-schema/parsers/intersection.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts +11 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/literal.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts +17 -0
- package/dist/utils/zod-to-json-schema/parsers/map.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js +40 -0
- package/dist/utils/zod-to-json-schema/parsers/map.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs +18 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts +8 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts +10 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js +17 -0
- package/dist/utils/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/never.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js +13 -0
- package/dist/utils/zod-to-json-schema/parsers/never.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs +12 -0
- package/dist/utils/zod-to-json-schema/parsers/null.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/null.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js +11 -0
- package/dist/utils/zod-to-json-schema/parsers/null.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js +46 -0
- package/dist/utils/zod-to-json-schema/parsers/nullable.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/number.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js +37 -0
- package/dist/utils/zod-to-json-schema/parsers/number.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts +12 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts +13 -0
- package/dist/utils/zod-to-json-schema/parsers/object.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js +64 -0
- package/dist/utils/zod-to-json-schema/parsers/object.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js +20 -0
- package/dist/utils/zod-to-json-schema/parsers/optional.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js +28 -0
- package/dist/utils/zod-to-json-schema/parsers/pipeline.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/promise.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/readonly.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs +57 -0
- package/dist/utils/zod-to-json-schema/parsers/record.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts +14 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/record.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js +56 -0
- package/dist/utils/zod-to-json-schema/parsers/record.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/set.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js +22 -0
- package/dist/utils/zod-to-json-schema/parsers/set.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs +255 -0
- package/dist/utils/zod-to-json-schema/parsers/string.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts +28 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts +29 -0
- package/dist/utils/zod-to-json-schema/parsers/string.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js +254 -0
- package/dist/utils/zod-to-json-schema/parsers/string.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts +15 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts +16 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js +38 -0
- package/dist/utils/zod-to-json-schema/parsers/tuple.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts +9 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/undefined.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs +67 -0
- package/dist/utils/zod-to-json-schema/parsers/union.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts +24 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts +25 -0
- package/dist/utils/zod-to-json-schema/parsers/union.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js +66 -0
- package/dist/utils/zod-to-json-schema/parsers/union.js.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.cts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts +7 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js +10 -0
- package/dist/utils/zod-to-json-schema/parsers/unknown.js.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs +81 -0
- package/dist/utils/zod-to-json-schema/selectParser.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/selectParser.js +80 -0
- package/dist/utils/zod-to-json-schema/selectParser.js.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.cjs.map +1 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js +70 -0
- package/dist/utils/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
- package/package.json +7 -36
- package/dist/utils/js-sha1/hash.cjs +0 -291
- package/dist/utils/js-sha1/hash.cjs.map +0 -1
- package/dist/utils/js-sha1/hash.d.cts +0 -9
- package/dist/utils/js-sha1/hash.d.cts.map +0 -1
- package/dist/utils/js-sha1/hash.d.ts +0 -9
- package/dist/utils/js-sha1/hash.d.ts.map +0 -1
- package/dist/utils/js-sha1/hash.js +0 -284
- package/dist/utils/js-sha1/hash.js.map +0 -1
- package/dist/utils/testing/index.d.cts.map +0 -1
- package/dist/utils/testing/index.d.ts.map +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Document } from "../../documents/document.cjs";
|
|
2
|
+
import { EmbeddingsInterface } from "../../embeddings.cjs";
|
|
3
|
+
import { VectorStore } from "../../vectorstores.cjs";
|
|
4
|
+
import { cosine } from "../ml-distance/similarities.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/testing/vectorstores.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Interface representing a vector in memory. It includes the content
|
|
10
|
+
* (text), the corresponding embedding (vector), and any associated
|
|
11
|
+
* metadata.
|
|
12
|
+
*/
|
|
13
|
+
interface MemoryVector {
|
|
14
|
+
content: string;
|
|
15
|
+
embedding: number[];
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
metadata: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface for the arguments that can be passed to the
|
|
21
|
+
* `FakeVectorStore` constructor. It includes an optional `similarity`
|
|
22
|
+
* function.
|
|
23
|
+
*/
|
|
24
|
+
interface FakeVectorStoreArgs {
|
|
25
|
+
similarity?: typeof cosine;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Class that extends `VectorStore` to store vectors in memory. Provides
|
|
29
|
+
* methods for adding documents, performing similarity searches, and
|
|
30
|
+
* creating instances from texts, documents, or an existing index.
|
|
31
|
+
*/
|
|
32
|
+
declare class FakeVectorStore extends VectorStore {
|
|
33
|
+
FilterType: (doc: Document) => boolean;
|
|
34
|
+
memoryVectors: MemoryVector[];
|
|
35
|
+
similarity: typeof cosine;
|
|
36
|
+
_vectorstoreType(): string;
|
|
37
|
+
constructor(embeddings: EmbeddingsInterface, {
|
|
38
|
+
similarity,
|
|
39
|
+
...rest
|
|
40
|
+
}?: FakeVectorStoreArgs);
|
|
41
|
+
/**
|
|
42
|
+
* Method to add documents to the memory vector store. It extracts the
|
|
43
|
+
* text from each document, generates embeddings for them, and adds the
|
|
44
|
+
* resulting vectors to the store.
|
|
45
|
+
* @param documents Array of `Document` instances to be added to the store.
|
|
46
|
+
* @returns Promise that resolves when all documents have been added.
|
|
47
|
+
*/
|
|
48
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Method to add vectors to the memory vector store. It creates
|
|
51
|
+
* `MemoryVector` instances for each vector and document pair and adds
|
|
52
|
+
* them to the store.
|
|
53
|
+
* @param vectors Array of vectors to be added to the store.
|
|
54
|
+
* @param documents Array of `Document` instances corresponding to the vectors.
|
|
55
|
+
* @returns Promise that resolves when all vectors have been added.
|
|
56
|
+
*/
|
|
57
|
+
addVectors(vectors: number[][], documents: Document[]): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Method to perform a similarity search in the memory vector store. It
|
|
60
|
+
* calculates the similarity between the query vector and each vector in
|
|
61
|
+
* the store, sorts the results by similarity, and returns the top `k`
|
|
62
|
+
* results along with their scores.
|
|
63
|
+
* @param query Query vector to compare against the vectors in the store.
|
|
64
|
+
* @param k Number of top results to return.
|
|
65
|
+
* @param filter Optional filter function to apply to the vectors before performing the search.
|
|
66
|
+
* @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.
|
|
67
|
+
*/
|
|
68
|
+
similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
|
|
69
|
+
/**
|
|
70
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
71
|
+
* texts. It creates a `Document` for each text and metadata pair, and
|
|
72
|
+
* adds them to the store.
|
|
73
|
+
* @param texts Array of texts to be added to the store.
|
|
74
|
+
* @param metadatas Array or single object of metadata corresponding to the texts.
|
|
75
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the texts.
|
|
76
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
77
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
78
|
+
*/
|
|
79
|
+
static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
80
|
+
/**
|
|
81
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
82
|
+
* `Document` instances. It adds the documents to the store.
|
|
83
|
+
* @param docs Array of `Document` instances to be added to the store.
|
|
84
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
85
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
86
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
87
|
+
*/
|
|
88
|
+
static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
89
|
+
/**
|
|
90
|
+
* Static method to create a `FakeVectorStore` instance from an existing
|
|
91
|
+
* index. It creates a new `FakeVectorStore` instance without adding any
|
|
92
|
+
* documents or vectors.
|
|
93
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
94
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
95
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
96
|
+
*/
|
|
97
|
+
static fromExistingIndex(embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { FakeVectorStore, FakeVectorStoreArgs };
|
|
101
|
+
//# sourceMappingURL=vectorstores.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectorstores.d.cts","names":["Document","EmbeddingsInterface","VectorStore","cosine","MemoryVector","Record","FakeVectorStoreArgs","FakeVectorStore","similarity","Promise"],"sources":["../../../src/utils/testing/vectorstores.d.ts"],"sourcesContent":["import { Document } from \"../../documents/document.js\";\nimport { EmbeddingsInterface } from \"../../embeddings.js\";\nimport { VectorStore } from \"../../vectorstores.js\";\nimport { cosine } from \"../ml-distance/similarities.js\";\n/**\n * Interface representing a vector in memory. It includes the content\n * (text), the corresponding embedding (vector), and any associated\n * metadata.\n */\ninterface MemoryVector {\n content: string;\n embedding: number[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n}\n/**\n * Interface for the arguments that can be passed to the\n * `FakeVectorStore` constructor. It includes an optional `similarity`\n * function.\n */\nexport interface FakeVectorStoreArgs {\n similarity?: typeof cosine;\n}\n/**\n * Class that extends `VectorStore` to store vectors in memory. Provides\n * methods for adding documents, performing similarity searches, and\n * creating instances from texts, documents, or an existing index.\n */\nexport declare class FakeVectorStore extends VectorStore {\n FilterType: (doc: Document) => boolean;\n memoryVectors: MemoryVector[];\n similarity: typeof cosine;\n _vectorstoreType(): string;\n constructor(embeddings: EmbeddingsInterface, { similarity, ...rest }?: FakeVectorStoreArgs);\n /**\n * Method to add documents to the memory vector store. It extracts the\n * text from each document, generates embeddings for them, and adds the\n * resulting vectors to the store.\n * @param documents Array of `Document` instances to be added to the store.\n * @returns Promise that resolves when all documents have been added.\n */\n addDocuments(documents: Document[]): Promise<void>;\n /**\n * Method to add vectors to the memory vector store. It creates\n * `MemoryVector` instances for each vector and document pair and adds\n * them to the store.\n * @param vectors Array of vectors to be added to the store.\n * @param documents Array of `Document` instances corresponding to the vectors.\n * @returns Promise that resolves when all vectors have been added.\n */\n addVectors(vectors: number[][], documents: Document[]): Promise<void>;\n /**\n * Method to perform a similarity search in the memory vector store. It\n * calculates the similarity between the query vector and each vector in\n * the store, sorts the results by similarity, and returns the top `k`\n * results along with their scores.\n * @param query Query vector to compare against the vectors in the store.\n * @param k Number of top results to return.\n * @param filter Optional filter function to apply to the vectors before performing the search.\n * @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.\n */\n similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[Document, number][]>;\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * texts. It creates a `Document` for each text and metadata pair, and\n * adds them to the store.\n * @param texts Array of texts to be added to the store.\n * @param metadatas Array or single object of metadata corresponding to the texts.\n * @param embeddings `Embeddings` instance used to generate embeddings for the texts.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * `Document` instances. It adds the documents to the store.\n * @param docs Array of `Document` instances to be added to the store.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n /**\n * Static method to create a `FakeVectorStore` instance from an existing\n * index. It creates a new `FakeVectorStore` instance without adding any\n * documents or vectors.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromExistingIndex(embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n}\nexport {};\n"],"mappings":";;;;;;;;;AAGwD;AAiBxD;AAQA;UAnBUI,YAAAA,CAmB0B;EAAA,OACdJ,EAAAA,MAAAA;EAAQ,SACXI,EAAAA,MAAAA,EAAAA;EAAY;EACF,QAEDH,EApBdI,MAoBcJ,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;;;;;;;AA4B2ED,UAzCtFM,mBAAAA,CAyCsFN;EAAQ,UAAjBS,CAAAA,EAAAA,OAxCtEN,MAwCsEM;;;;;;;AAoBPH,cArDlEC,eAAAA,SAAwBL,WAAAA,CAqD0CI;EAAmB,UAAWC,EAAAA,CAAAA,GAAAA,EApD/FP,QAoD+FO,EAAAA,GAAAA,OAAAA;EAAe,aAAvBE,EAnD1FL,YAmD0FK,EAAAA;EAAO,UAS3ER,EAAAA,OA3DlBE,MA2DkBF;EAAmB,gBAAaK,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,WAAWC,CAAAA,UAAAA,EAzD3EN,mBAyD2EM,EAAAA;IAAAA,UAAAA;IAAAA,GAAAA;EAAAA,CAAAA,CAAAA,EAzD5BD,mBAyD4BC;EAAe;;AA9D9D;;;;;0BAa5BP,aAAaS;;;;;;;;;6CASMT,aAAaS;;;;;;;;;;;4FAWkCA,SAAST;;;;;;;;;;;8EAWvBC,gCAAgCK,sBAAsBG,QAAQF;;;;;;;;;6BAS/GP,wBAAwBC,gCAAgCK,sBAAsBG,QAAQF;;;;;;;;;uCAS5EN,gCAAgCK,sBAAsBG,QAAQF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Document } from "../../documents/document.js";
|
|
2
|
+
import { EmbeddingsInterface } from "../../embeddings.js";
|
|
3
|
+
import { VectorStore } from "../../vectorstores.js";
|
|
4
|
+
import { cosine } from "../ml-distance/similarities.js";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/testing/vectorstores.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Interface representing a vector in memory. It includes the content
|
|
10
|
+
* (text), the corresponding embedding (vector), and any associated
|
|
11
|
+
* metadata.
|
|
12
|
+
*/
|
|
13
|
+
interface MemoryVector {
|
|
14
|
+
content: string;
|
|
15
|
+
embedding: number[];
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
metadata: Record<string, any>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface for the arguments that can be passed to the
|
|
21
|
+
* `FakeVectorStore` constructor. It includes an optional `similarity`
|
|
22
|
+
* function.
|
|
23
|
+
*/
|
|
24
|
+
interface FakeVectorStoreArgs {
|
|
25
|
+
similarity?: typeof cosine;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Class that extends `VectorStore` to store vectors in memory. Provides
|
|
29
|
+
* methods for adding documents, performing similarity searches, and
|
|
30
|
+
* creating instances from texts, documents, or an existing index.
|
|
31
|
+
*/
|
|
32
|
+
declare class FakeVectorStore extends VectorStore {
|
|
33
|
+
FilterType: (doc: Document) => boolean;
|
|
34
|
+
memoryVectors: MemoryVector[];
|
|
35
|
+
similarity: typeof cosine;
|
|
36
|
+
_vectorstoreType(): string;
|
|
37
|
+
constructor(embeddings: EmbeddingsInterface, {
|
|
38
|
+
similarity,
|
|
39
|
+
...rest
|
|
40
|
+
}?: FakeVectorStoreArgs);
|
|
41
|
+
/**
|
|
42
|
+
* Method to add documents to the memory vector store. It extracts the
|
|
43
|
+
* text from each document, generates embeddings for them, and adds the
|
|
44
|
+
* resulting vectors to the store.
|
|
45
|
+
* @param documents Array of `Document` instances to be added to the store.
|
|
46
|
+
* @returns Promise that resolves when all documents have been added.
|
|
47
|
+
*/
|
|
48
|
+
addDocuments(documents: Document[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Method to add vectors to the memory vector store. It creates
|
|
51
|
+
* `MemoryVector` instances for each vector and document pair and adds
|
|
52
|
+
* them to the store.
|
|
53
|
+
* @param vectors Array of vectors to be added to the store.
|
|
54
|
+
* @param documents Array of `Document` instances corresponding to the vectors.
|
|
55
|
+
* @returns Promise that resolves when all vectors have been added.
|
|
56
|
+
*/
|
|
57
|
+
addVectors(vectors: number[][], documents: Document[]): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Method to perform a similarity search in the memory vector store. It
|
|
60
|
+
* calculates the similarity between the query vector and each vector in
|
|
61
|
+
* the store, sorts the results by similarity, and returns the top `k`
|
|
62
|
+
* results along with their scores.
|
|
63
|
+
* @param query Query vector to compare against the vectors in the store.
|
|
64
|
+
* @param k Number of top results to return.
|
|
65
|
+
* @param filter Optional filter function to apply to the vectors before performing the search.
|
|
66
|
+
* @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.
|
|
67
|
+
*/
|
|
68
|
+
similaritySearchVectorWithScore(query: number[], k: number, filter?: this["FilterType"]): Promise<[Document, number][]>;
|
|
69
|
+
/**
|
|
70
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
71
|
+
* texts. It creates a `Document` for each text and metadata pair, and
|
|
72
|
+
* adds them to the store.
|
|
73
|
+
* @param texts Array of texts to be added to the store.
|
|
74
|
+
* @param metadatas Array or single object of metadata corresponding to the texts.
|
|
75
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the texts.
|
|
76
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
77
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
78
|
+
*/
|
|
79
|
+
static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
80
|
+
/**
|
|
81
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
82
|
+
* `Document` instances. It adds the documents to the store.
|
|
83
|
+
* @param docs Array of `Document` instances to be added to the store.
|
|
84
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
85
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
86
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
87
|
+
*/
|
|
88
|
+
static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
89
|
+
/**
|
|
90
|
+
* Static method to create a `FakeVectorStore` instance from an existing
|
|
91
|
+
* index. It creates a new `FakeVectorStore` instance without adding any
|
|
92
|
+
* documents or vectors.
|
|
93
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
94
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
95
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
96
|
+
*/
|
|
97
|
+
static fromExistingIndex(embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { FakeVectorStore, FakeVectorStoreArgs };
|
|
101
|
+
//# sourceMappingURL=vectorstores.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectorstores.d.ts","names":["Document","EmbeddingsInterface","VectorStore","cosine","MemoryVector","Record","FakeVectorStoreArgs","FakeVectorStore","similarity","Promise"],"sources":["../../../src/utils/testing/vectorstores.d.ts"],"sourcesContent":["import { Document } from \"../../documents/document.js\";\nimport { EmbeddingsInterface } from \"../../embeddings.js\";\nimport { VectorStore } from \"../../vectorstores.js\";\nimport { cosine } from \"../ml-distance/similarities.js\";\n/**\n * Interface representing a vector in memory. It includes the content\n * (text), the corresponding embedding (vector), and any associated\n * metadata.\n */\ninterface MemoryVector {\n content: string;\n embedding: number[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n}\n/**\n * Interface for the arguments that can be passed to the\n * `FakeVectorStore` constructor. It includes an optional `similarity`\n * function.\n */\nexport interface FakeVectorStoreArgs {\n similarity?: typeof cosine;\n}\n/**\n * Class that extends `VectorStore` to store vectors in memory. Provides\n * methods for adding documents, performing similarity searches, and\n * creating instances from texts, documents, or an existing index.\n */\nexport declare class FakeVectorStore extends VectorStore {\n FilterType: (doc: Document) => boolean;\n memoryVectors: MemoryVector[];\n similarity: typeof cosine;\n _vectorstoreType(): string;\n constructor(embeddings: EmbeddingsInterface, { similarity, ...rest }?: FakeVectorStoreArgs);\n /**\n * Method to add documents to the memory vector store. It extracts the\n * text from each document, generates embeddings for them, and adds the\n * resulting vectors to the store.\n * @param documents Array of `Document` instances to be added to the store.\n * @returns Promise that resolves when all documents have been added.\n */\n addDocuments(documents: Document[]): Promise<void>;\n /**\n * Method to add vectors to the memory vector store. It creates\n * `MemoryVector` instances for each vector and document pair and adds\n * them to the store.\n * @param vectors Array of vectors to be added to the store.\n * @param documents Array of `Document` instances corresponding to the vectors.\n * @returns Promise that resolves when all vectors have been added.\n */\n addVectors(vectors: number[][], documents: Document[]): Promise<void>;\n /**\n * Method to perform a similarity search in the memory vector store. It\n * calculates the similarity between the query vector and each vector in\n * the store, sorts the results by similarity, and returns the top `k`\n * results along with their scores.\n * @param query Query vector to compare against the vectors in the store.\n * @param k Number of top results to return.\n * @param filter Optional filter function to apply to the vectors before performing the search.\n * @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.\n */\n similaritySearchVectorWithScore(query: number[], k: number, filter?: this[\"FilterType\"]): Promise<[Document, number][]>;\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * texts. It creates a `Document` for each text and metadata pair, and\n * adds them to the store.\n * @param texts Array of texts to be added to the store.\n * @param metadatas Array or single object of metadata corresponding to the texts.\n * @param embeddings `Embeddings` instance used to generate embeddings for the texts.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromTexts(texts: string[], metadatas: object[] | object, embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * `Document` instances. It adds the documents to the store.\n * @param docs Array of `Document` instances to be added to the store.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromDocuments(docs: Document[], embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n /**\n * Static method to create a `FakeVectorStore` instance from an existing\n * index. It creates a new `FakeVectorStore` instance without adding any\n * documents or vectors.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static fromExistingIndex(embeddings: EmbeddingsInterface, dbConfig?: FakeVectorStoreArgs): Promise<FakeVectorStore>;\n}\nexport {};\n"],"mappings":";;;;;;;;;AAGwD;AAiBxD;AAQA;UAnBUI,YAAAA,CAmB0B;EAAA,OACdJ,EAAAA,MAAAA;EAAQ,SACXI,EAAAA,MAAAA,EAAAA;EAAY;EACF,QAEDH,EApBdI,MAoBcJ,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA;;;;;;;AA4B2ED,UAzCtFM,mBAAAA,CAyCsFN;EAAQ,UAAjBS,CAAAA,EAAAA,OAxCtEN,MAwCsEM;;;;;;;AAoBPH,cArDlEC,eAAAA,SAAwBL,WAAAA,CAqD0CI;EAAmB,UAAWC,EAAAA,CAAAA,GAAAA,EApD/FP,QAoD+FO,EAAAA,GAAAA,OAAAA;EAAe,aAAvBE,EAnD1FL,YAmD0FK,EAAAA;EAAO,UAS3ER,EAAAA,OA3DlBE,MA2DkBF;EAAmB,gBAAaK,CAAAA,CAAAA,EAAAA,MAAAA;EAAmB,WAAWC,CAAAA,UAAAA,EAzD3EN,mBAyD2EM,EAAAA;IAAAA,UAAAA;IAAAA,GAAAA;EAAAA,CAAAA,CAAAA,EAzD5BD,mBAyD4BC;EAAe;;AA9D9D;;;;;0BAa5BP,aAAaS;;;;;;;;;6CASMT,aAAaS;;;;;;;;;;;4FAWkCA,SAAST;;;;;;;;;;;8EAWvBC,gCAAgCK,sBAAsBG,QAAQF;;;;;;;;;6BAS/GP,wBAAwBC,gCAAgCK,sBAAsBG,QAAQF;;;;;;;;;uCAS5EN,gCAAgCK,sBAAsBG,QAAQF"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { VectorStore } from "../../vectorstores.js";
|
|
2
|
+
import { Document } from "../../documents/document.js";
|
|
3
|
+
import { cosine } from "../ml-distance/similarities.js";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/testing/vectorstores.ts
|
|
6
|
+
/**
|
|
7
|
+
* Class that extends `VectorStore` to store vectors in memory. Provides
|
|
8
|
+
* methods for adding documents, performing similarity searches, and
|
|
9
|
+
* creating instances from texts, documents, or an existing index.
|
|
10
|
+
*/
|
|
11
|
+
var FakeVectorStore = class FakeVectorStore extends VectorStore {
|
|
12
|
+
memoryVectors = [];
|
|
13
|
+
similarity;
|
|
14
|
+
_vectorstoreType() {
|
|
15
|
+
return "memory";
|
|
16
|
+
}
|
|
17
|
+
constructor(embeddings, { similarity,...rest } = {}) {
|
|
18
|
+
super(embeddings, rest);
|
|
19
|
+
this.similarity = similarity ?? cosine;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Method to add documents to the memory vector store. It extracts the
|
|
23
|
+
* text from each document, generates embeddings for them, and adds the
|
|
24
|
+
* resulting vectors to the store.
|
|
25
|
+
* @param documents Array of `Document` instances to be added to the store.
|
|
26
|
+
* @returns Promise that resolves when all documents have been added.
|
|
27
|
+
*/
|
|
28
|
+
async addDocuments(documents) {
|
|
29
|
+
const texts = documents.map(({ pageContent }) => pageContent);
|
|
30
|
+
return this.addVectors(await this.embeddings.embedDocuments(texts), documents);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Method to add vectors to the memory vector store. It creates
|
|
34
|
+
* `MemoryVector` instances for each vector and document pair and adds
|
|
35
|
+
* them to the store.
|
|
36
|
+
* @param vectors Array of vectors to be added to the store.
|
|
37
|
+
* @param documents Array of `Document` instances corresponding to the vectors.
|
|
38
|
+
* @returns Promise that resolves when all vectors have been added.
|
|
39
|
+
*/
|
|
40
|
+
async addVectors(vectors, documents) {
|
|
41
|
+
const memoryVectors = vectors.map((embedding, idx) => ({
|
|
42
|
+
content: documents[idx].pageContent,
|
|
43
|
+
embedding,
|
|
44
|
+
metadata: documents[idx].metadata
|
|
45
|
+
}));
|
|
46
|
+
this.memoryVectors = this.memoryVectors.concat(memoryVectors);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Method to perform a similarity search in the memory vector store. It
|
|
50
|
+
* calculates the similarity between the query vector and each vector in
|
|
51
|
+
* the store, sorts the results by similarity, and returns the top `k`
|
|
52
|
+
* results along with their scores.
|
|
53
|
+
* @param query Query vector to compare against the vectors in the store.
|
|
54
|
+
* @param k Number of top results to return.
|
|
55
|
+
* @param filter Optional filter function to apply to the vectors before performing the search.
|
|
56
|
+
* @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.
|
|
57
|
+
*/
|
|
58
|
+
async similaritySearchVectorWithScore(query, k, filter) {
|
|
59
|
+
const filterFunction = (memoryVector) => {
|
|
60
|
+
if (!filter) return true;
|
|
61
|
+
const doc = new Document({
|
|
62
|
+
metadata: memoryVector.metadata,
|
|
63
|
+
pageContent: memoryVector.content
|
|
64
|
+
});
|
|
65
|
+
return filter(doc);
|
|
66
|
+
};
|
|
67
|
+
const filteredMemoryVectors = this.memoryVectors.filter(filterFunction);
|
|
68
|
+
const searches = filteredMemoryVectors.map((vector, index) => ({
|
|
69
|
+
similarity: this.similarity(query, vector.embedding),
|
|
70
|
+
index
|
|
71
|
+
})).sort((a, b) => a.similarity > b.similarity ? -1 : 0).slice(0, k);
|
|
72
|
+
const result = searches.map((search) => [new Document({
|
|
73
|
+
metadata: filteredMemoryVectors[search.index].metadata,
|
|
74
|
+
pageContent: filteredMemoryVectors[search.index].content
|
|
75
|
+
}), search.similarity]);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
80
|
+
* texts. It creates a `Document` for each text and metadata pair, and
|
|
81
|
+
* adds them to the store.
|
|
82
|
+
* @param texts Array of texts to be added to the store.
|
|
83
|
+
* @param metadatas Array or single object of metadata corresponding to the texts.
|
|
84
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the texts.
|
|
85
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
86
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
87
|
+
*/
|
|
88
|
+
static async fromTexts(texts, metadatas, embeddings, dbConfig) {
|
|
89
|
+
const docs = [];
|
|
90
|
+
for (let i = 0; i < texts.length; i += 1) {
|
|
91
|
+
const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;
|
|
92
|
+
const newDoc = new Document({
|
|
93
|
+
pageContent: texts[i],
|
|
94
|
+
metadata
|
|
95
|
+
});
|
|
96
|
+
docs.push(newDoc);
|
|
97
|
+
}
|
|
98
|
+
return FakeVectorStore.fromDocuments(docs, embeddings, dbConfig);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Static method to create a `FakeVectorStore` instance from an array of
|
|
102
|
+
* `Document` instances. It adds the documents to the store.
|
|
103
|
+
* @param docs Array of `Document` instances to be added to the store.
|
|
104
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
105
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
106
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
107
|
+
*/
|
|
108
|
+
static async fromDocuments(docs, embeddings, dbConfig) {
|
|
109
|
+
const instance = new this(embeddings, dbConfig);
|
|
110
|
+
await instance.addDocuments(docs);
|
|
111
|
+
return instance;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Static method to create a `FakeVectorStore` instance from an existing
|
|
115
|
+
* index. It creates a new `FakeVectorStore` instance without adding any
|
|
116
|
+
* documents or vectors.
|
|
117
|
+
* @param embeddings `Embeddings` instance used to generate embeddings for the documents.
|
|
118
|
+
* @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.
|
|
119
|
+
* @returns Promise that resolves with a new `FakeVectorStore` instance.
|
|
120
|
+
*/
|
|
121
|
+
static async fromExistingIndex(embeddings, dbConfig) {
|
|
122
|
+
const instance = new this(embeddings, dbConfig);
|
|
123
|
+
return instance;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { FakeVectorStore };
|
|
129
|
+
//# sourceMappingURL=vectorstores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vectorstores.js","names":["embeddings: EmbeddingsInterface","documents: Document[]","vectors: number[][]","query: number[]","k: number","filter?: this[\"FilterType\"]","memoryVector: MemoryVector","result: [Document, number][]","texts: string[]","metadatas: object[] | object","dbConfig?: FakeVectorStoreArgs","docs: Document[]"],"sources":["../../../src/utils/testing/vectorstores.ts"],"sourcesContent":["import { Document } from \"../../documents/document.js\";\nimport { EmbeddingsInterface } from \"../../embeddings.js\";\nimport { VectorStore } from \"../../vectorstores.js\";\nimport { cosine } from \"../ml-distance/similarities.js\";\n\n/**\n * Interface representing a vector in memory. It includes the content\n * (text), the corresponding embedding (vector), and any associated\n * metadata.\n */\ninterface MemoryVector {\n content: string;\n embedding: number[];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n metadata: Record<string, any>;\n}\n\n/**\n * Interface for the arguments that can be passed to the\n * `FakeVectorStore` constructor. It includes an optional `similarity`\n * function.\n */\nexport interface FakeVectorStoreArgs {\n similarity?: typeof cosine;\n}\n\n/**\n * Class that extends `VectorStore` to store vectors in memory. Provides\n * methods for adding documents, performing similarity searches, and\n * creating instances from texts, documents, or an existing index.\n */\nexport class FakeVectorStore extends VectorStore {\n declare FilterType: (doc: Document) => boolean;\n\n memoryVectors: MemoryVector[] = [];\n\n similarity: typeof cosine;\n\n _vectorstoreType(): string {\n return \"memory\";\n }\n\n constructor(\n embeddings: EmbeddingsInterface,\n { similarity, ...rest }: FakeVectorStoreArgs = {}\n ) {\n super(embeddings, rest);\n\n this.similarity = similarity ?? cosine;\n }\n\n /**\n * Method to add documents to the memory vector store. It extracts the\n * text from each document, generates embeddings for them, and adds the\n * resulting vectors to the store.\n * @param documents Array of `Document` instances to be added to the store.\n * @returns Promise that resolves when all documents have been added.\n */\n async addDocuments(documents: Document[]): Promise<void> {\n const texts = documents.map(({ pageContent }) => pageContent);\n return this.addVectors(\n await this.embeddings.embedDocuments(texts),\n documents\n );\n }\n\n /**\n * Method to add vectors to the memory vector store. It creates\n * `MemoryVector` instances for each vector and document pair and adds\n * them to the store.\n * @param vectors Array of vectors to be added to the store.\n * @param documents Array of `Document` instances corresponding to the vectors.\n * @returns Promise that resolves when all vectors have been added.\n */\n async addVectors(vectors: number[][], documents: Document[]): Promise<void> {\n const memoryVectors = vectors.map((embedding, idx) => ({\n content: documents[idx].pageContent,\n embedding,\n metadata: documents[idx].metadata,\n }));\n\n this.memoryVectors = this.memoryVectors.concat(memoryVectors);\n }\n\n /**\n * Method to perform a similarity search in the memory vector store. It\n * calculates the similarity between the query vector and each vector in\n * the store, sorts the results by similarity, and returns the top `k`\n * results along with their scores.\n * @param query Query vector to compare against the vectors in the store.\n * @param k Number of top results to return.\n * @param filter Optional filter function to apply to the vectors before performing the search.\n * @returns Promise that resolves with an array of tuples, each containing a `Document` and its similarity score.\n */\n async similaritySearchVectorWithScore(\n query: number[],\n k: number,\n filter?: this[\"FilterType\"]\n ): Promise<[Document, number][]> {\n const filterFunction = (memoryVector: MemoryVector) => {\n if (!filter) {\n return true;\n }\n\n const doc = new Document({\n metadata: memoryVector.metadata,\n pageContent: memoryVector.content,\n });\n return filter(doc);\n };\n const filteredMemoryVectors = this.memoryVectors.filter(filterFunction);\n const searches = filteredMemoryVectors\n .map((vector, index) => ({\n similarity: this.similarity(query, vector.embedding),\n index,\n }))\n .sort((a, b) => (a.similarity > b.similarity ? -1 : 0))\n .slice(0, k);\n\n const result: [Document, number][] = searches.map((search) => [\n new Document({\n metadata: filteredMemoryVectors[search.index].metadata,\n pageContent: filteredMemoryVectors[search.index].content,\n }),\n search.similarity,\n ]);\n\n return result;\n }\n\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * texts. It creates a `Document` for each text and metadata pair, and\n * adds them to the store.\n * @param texts Array of texts to be added to the store.\n * @param metadatas Array or single object of metadata corresponding to the texts.\n * @param embeddings `Embeddings` instance used to generate embeddings for the texts.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static async fromTexts(\n texts: string[],\n metadatas: object[] | object,\n embeddings: EmbeddingsInterface,\n dbConfig?: FakeVectorStoreArgs\n ): Promise<FakeVectorStore> {\n const docs: Document[] = [];\n for (let i = 0; i < texts.length; i += 1) {\n const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;\n const newDoc = new Document({\n pageContent: texts[i],\n metadata,\n });\n docs.push(newDoc);\n }\n return FakeVectorStore.fromDocuments(docs, embeddings, dbConfig);\n }\n\n /**\n * Static method to create a `FakeVectorStore` instance from an array of\n * `Document` instances. It adds the documents to the store.\n * @param docs Array of `Document` instances to be added to the store.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static async fromDocuments(\n docs: Document[],\n embeddings: EmbeddingsInterface,\n dbConfig?: FakeVectorStoreArgs\n ): Promise<FakeVectorStore> {\n const instance = new this(embeddings, dbConfig);\n await instance.addDocuments(docs);\n return instance;\n }\n\n /**\n * Static method to create a `FakeVectorStore` instance from an existing\n * index. It creates a new `FakeVectorStore` instance without adding any\n * documents or vectors.\n * @param embeddings `Embeddings` instance used to generate embeddings for the documents.\n * @param dbConfig Optional `FakeVectorStoreArgs` to configure the `FakeVectorStore` instance.\n * @returns Promise that resolves with a new `FakeVectorStore` instance.\n */\n static async fromExistingIndex(\n embeddings: EmbeddingsInterface,\n dbConfig?: FakeVectorStoreArgs\n ): Promise<FakeVectorStore> {\n const instance = new this(embeddings, dbConfig);\n return instance;\n }\n}\n"],"mappings":";;;;;;;;;;AA+BA,IAAa,kBAAb,MAAa,wBAAwB,YAAY;CAG/C,gBAAgC,CAAE;CAElC;CAEA,mBAA2B;AACzB,SAAO;CACR;CAED,YACEA,YACA,EAAE,WAAY,GAAG,MAA2B,GAAG,CAAE,GACjD;EACA,MAAM,YAAY,KAAK;EAEvB,KAAK,aAAa,cAAc;CACjC;;;;;;;;CASD,MAAM,aAAaC,WAAsC;EACvD,MAAM,QAAQ,UAAU,IAAI,CAAC,EAAE,aAAa,KAAK,YAAY;AAC7D,SAAO,KAAK,WACV,MAAM,KAAK,WAAW,eAAe,MAAM,EAC3C,UACD;CACF;;;;;;;;;CAUD,MAAM,WAAWC,SAAqBD,WAAsC;EAC1E,MAAM,gBAAgB,QAAQ,IAAI,CAAC,WAAW,SAAS;GACrD,SAAS,UAAU,KAAK;GACxB;GACA,UAAU,UAAU,KAAK;EAC1B,GAAE;EAEH,KAAK,gBAAgB,KAAK,cAAc,OAAO,cAAc;CAC9D;;;;;;;;;;;CAYD,MAAM,gCACJE,OACAC,GACAC,QAC+B;EAC/B,MAAM,iBAAiB,CAACC,iBAA+B;AACrD,OAAI,CAAC,OACH,QAAO;GAGT,MAAM,MAAM,IAAI,SAAS;IACvB,UAAU,aAAa;IACvB,aAAa,aAAa;GAC3B;AACD,UAAO,OAAO,IAAI;EACnB;EACD,MAAM,wBAAwB,KAAK,cAAc,OAAO,eAAe;EACvE,MAAM,WAAW,sBACd,IAAI,CAAC,QAAQ,WAAW;GACvB,YAAY,KAAK,WAAW,OAAO,OAAO,UAAU;GACpD;EACD,GAAE,CACF,KAAK,CAAC,GAAG,MAAO,EAAE,aAAa,EAAE,aAAa,KAAK,EAAG,CACtD,MAAM,GAAG,EAAE;EAEd,MAAMC,SAA+B,SAAS,IAAI,CAAC,WAAW,CAC5D,IAAI,SAAS;GACX,UAAU,sBAAsB,OAAO,OAAO;GAC9C,aAAa,sBAAsB,OAAO,OAAO;EAClD,IACD,OAAO,UACR,EAAC;AAEF,SAAO;CACR;;;;;;;;;;;CAYD,aAAa,UACXC,OACAC,WACAT,YACAU,UAC0B;EAC1B,MAAMC,OAAmB,CAAE;AAC3B,OAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,GAAG;GACxC,MAAM,WAAW,MAAM,QAAQ,UAAU,GAAG,UAAU,KAAK;GAC3D,MAAM,SAAS,IAAI,SAAS;IAC1B,aAAa,MAAM;IACnB;GACD;GACD,KAAK,KAAK,OAAO;EAClB;AACD,SAAO,gBAAgB,cAAc,MAAM,YAAY,SAAS;CACjE;;;;;;;;;CAUD,aAAa,cACXA,MACAX,YACAU,UAC0B;EAC1B,MAAM,WAAW,IAAI,KAAK,YAAY;EACtC,MAAM,SAAS,aAAa,KAAK;AACjC,SAAO;CACR;;;;;;;;;CAUD,aAAa,kBACXV,YACAU,UAC0B;EAC1B,MAAM,WAAW,IAAI,KAAK,YAAY;AACtC,SAAO;CACR;AACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/zod-to-json-schema/Options.ts
|
|
3
|
+
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
name: void 0,
|
|
6
|
+
$refStrategy: "root",
|
|
7
|
+
basePath: ["#"],
|
|
8
|
+
effectStrategy: "input",
|
|
9
|
+
pipeStrategy: "all",
|
|
10
|
+
dateStrategy: "format:date-time",
|
|
11
|
+
mapStrategy: "entries",
|
|
12
|
+
removeAdditionalStrategy: "passthrough",
|
|
13
|
+
allowedAdditionalProperties: true,
|
|
14
|
+
rejectedAdditionalProperties: false,
|
|
15
|
+
definitionPath: "definitions",
|
|
16
|
+
target: "jsonSchema7",
|
|
17
|
+
strictUnions: false,
|
|
18
|
+
definitions: {},
|
|
19
|
+
errorMessages: false,
|
|
20
|
+
markdownDescription: false,
|
|
21
|
+
patternStrategy: "escape",
|
|
22
|
+
applyRegexFlags: false,
|
|
23
|
+
emailStrategy: "format:email",
|
|
24
|
+
base64Strategy: "contentEncoding:base64",
|
|
25
|
+
nameStrategy: "ref",
|
|
26
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
27
|
+
};
|
|
28
|
+
const getDefaultOptions = (options) => typeof options === "string" ? {
|
|
29
|
+
...defaultOptions,
|
|
30
|
+
name: options
|
|
31
|
+
} : {
|
|
32
|
+
...defaultOptions,
|
|
33
|
+
...options
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.defaultOptions = defaultOptions;
|
|
38
|
+
exports.getDefaultOptions = getDefaultOptions;
|
|
39
|
+
exports.ignoreOverride = ignoreOverride;
|
|
40
|
+
//# sourceMappingURL=Options.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Options.cjs","names":["defaultOptions: Options","options: Partial<Options<Target>> | string | undefined"],"sources":["../../../src/utils/zod-to-json-schema/Options.ts"],"sourcesContent":["import { ZodSchema, ZodTypeDef } from \"zod/v3\";\nimport { Refs, Seen } from \"./Refs\";\nimport { JsonSchema7Type } from \"./parseTypes\";\n\nexport type Targets =\n | \"jsonSchema7\"\n | \"jsonSchema2019-09\"\n | \"openApi3\"\n | \"openAi\";\n\nexport type DateStrategy =\n | \"format:date-time\"\n | \"format:date\"\n | \"string\"\n | \"integer\";\n\nexport const ignoreOverride = Symbol(\n \"Let zodToJsonSchema decide on which parser to use\"\n);\n\nexport type OverrideCallback = (\n def: ZodTypeDef,\n refs: Refs,\n seen: Seen | undefined,\n forceResolution?: boolean\n) => JsonSchema7Type | undefined | typeof ignoreOverride;\n\nexport type PostProcessCallback = (\n jsonSchema: JsonSchema7Type | undefined,\n def: ZodTypeDef,\n refs: Refs\n) => JsonSchema7Type | undefined;\n\nexport const jsonDescription: PostProcessCallback = (jsonSchema, def) => {\n if (def.description) {\n try {\n return {\n ...jsonSchema,\n ...JSON.parse(def.description),\n };\n } catch {}\n }\n\n return jsonSchema;\n};\n\nexport type Options<Target extends Targets = \"jsonSchema7\"> = {\n name: string | undefined;\n $refStrategy: \"root\" | \"relative\" | \"none\" | \"seen\";\n basePath: string[];\n effectStrategy: \"input\" | \"any\";\n pipeStrategy: \"input\" | \"output\" | \"all\";\n dateStrategy: DateStrategy | DateStrategy[];\n mapStrategy: \"entries\" | \"record\";\n removeAdditionalStrategy: \"passthrough\" | \"strict\";\n allowedAdditionalProperties: true | undefined;\n rejectedAdditionalProperties: false | undefined;\n target: Target;\n strictUnions: boolean;\n definitionPath: string;\n definitions: Record<string, ZodSchema>;\n errorMessages: boolean;\n markdownDescription: boolean;\n patternStrategy: \"escape\" | \"preserve\";\n applyRegexFlags: boolean;\n emailStrategy: \"format:email\" | \"format:idn-email\" | \"pattern:zod\";\n base64Strategy: \"format:binary\" | \"contentEncoding:base64\" | \"pattern:zod\";\n nameStrategy: \"ref\" | \"title\";\n override?: OverrideCallback;\n postProcess?: PostProcessCallback;\n openAiAnyTypeName: string;\n};\n\nexport const defaultOptions: Options = {\n name: undefined,\n $refStrategy: \"root\",\n basePath: [\"#\"],\n effectStrategy: \"input\",\n pipeStrategy: \"all\",\n dateStrategy: \"format:date-time\",\n mapStrategy: \"entries\",\n removeAdditionalStrategy: \"passthrough\",\n allowedAdditionalProperties: true,\n rejectedAdditionalProperties: false,\n definitionPath: \"definitions\",\n target: \"jsonSchema7\",\n strictUnions: false,\n definitions: {},\n errorMessages: false,\n markdownDescription: false,\n patternStrategy: \"escape\",\n applyRegexFlags: false,\n emailStrategy: \"format:email\",\n base64Strategy: \"contentEncoding:base64\",\n nameStrategy: \"ref\",\n openAiAnyTypeName: \"OpenAiAnyType\",\n};\n\nexport const getDefaultOptions = <Target extends Targets>(\n options: Partial<Options<Target>> | string | undefined\n) =>\n (typeof options === \"string\"\n ? {\n ...defaultOptions,\n name: options,\n }\n : {\n ...defaultOptions,\n ...options,\n }) as Options<Target>;\n"],"mappings":";;AAgBA,MAAa,iBAAiB,OAC5B,oDACD;AAuDD,MAAaA,iBAA0B;CACrC,MAAM;CACN,cAAc;CACd,UAAU,CAAC,GAAI;CACf,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,aAAa;CACb,0BAA0B;CAC1B,6BAA6B;CAC7B,8BAA8B;CAC9B,gBAAgB;CAChB,QAAQ;CACR,cAAc;CACd,aAAa,CAAE;CACf,eAAe;CACf,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,cAAc;CACd,mBAAmB;AACpB;AAED,MAAa,oBAAoB,CAC/BC,YAEC,OAAO,YAAY,WAChB;CACE,GAAG;CACH,MAAM;AACP,IACD;CACE,GAAG;CACH,GAAG;AACJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/utils/zod-to-json-schema/Options.ts
|
|
2
|
+
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
name: void 0,
|
|
5
|
+
$refStrategy: "root",
|
|
6
|
+
basePath: ["#"],
|
|
7
|
+
effectStrategy: "input",
|
|
8
|
+
pipeStrategy: "all",
|
|
9
|
+
dateStrategy: "format:date-time",
|
|
10
|
+
mapStrategy: "entries",
|
|
11
|
+
removeAdditionalStrategy: "passthrough",
|
|
12
|
+
allowedAdditionalProperties: true,
|
|
13
|
+
rejectedAdditionalProperties: false,
|
|
14
|
+
definitionPath: "definitions",
|
|
15
|
+
target: "jsonSchema7",
|
|
16
|
+
strictUnions: false,
|
|
17
|
+
definitions: {},
|
|
18
|
+
errorMessages: false,
|
|
19
|
+
markdownDescription: false,
|
|
20
|
+
patternStrategy: "escape",
|
|
21
|
+
applyRegexFlags: false,
|
|
22
|
+
emailStrategy: "format:email",
|
|
23
|
+
base64Strategy: "contentEncoding:base64",
|
|
24
|
+
nameStrategy: "ref",
|
|
25
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
26
|
+
};
|
|
27
|
+
const getDefaultOptions = (options) => typeof options === "string" ? {
|
|
28
|
+
...defaultOptions,
|
|
29
|
+
name: options
|
|
30
|
+
} : {
|
|
31
|
+
...defaultOptions,
|
|
32
|
+
...options
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { defaultOptions, getDefaultOptions, ignoreOverride };
|
|
37
|
+
//# sourceMappingURL=Options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Options.js","names":["defaultOptions: Options","options: Partial<Options<Target>> | string | undefined"],"sources":["../../../src/utils/zod-to-json-schema/Options.ts"],"sourcesContent":["import { ZodSchema, ZodTypeDef } from \"zod/v3\";\nimport { Refs, Seen } from \"./Refs\";\nimport { JsonSchema7Type } from \"./parseTypes\";\n\nexport type Targets =\n | \"jsonSchema7\"\n | \"jsonSchema2019-09\"\n | \"openApi3\"\n | \"openAi\";\n\nexport type DateStrategy =\n | \"format:date-time\"\n | \"format:date\"\n | \"string\"\n | \"integer\";\n\nexport const ignoreOverride = Symbol(\n \"Let zodToJsonSchema decide on which parser to use\"\n);\n\nexport type OverrideCallback = (\n def: ZodTypeDef,\n refs: Refs,\n seen: Seen | undefined,\n forceResolution?: boolean\n) => JsonSchema7Type | undefined | typeof ignoreOverride;\n\nexport type PostProcessCallback = (\n jsonSchema: JsonSchema7Type | undefined,\n def: ZodTypeDef,\n refs: Refs\n) => JsonSchema7Type | undefined;\n\nexport const jsonDescription: PostProcessCallback = (jsonSchema, def) => {\n if (def.description) {\n try {\n return {\n ...jsonSchema,\n ...JSON.parse(def.description),\n };\n } catch {}\n }\n\n return jsonSchema;\n};\n\nexport type Options<Target extends Targets = \"jsonSchema7\"> = {\n name: string | undefined;\n $refStrategy: \"root\" | \"relative\" | \"none\" | \"seen\";\n basePath: string[];\n effectStrategy: \"input\" | \"any\";\n pipeStrategy: \"input\" | \"output\" | \"all\";\n dateStrategy: DateStrategy | DateStrategy[];\n mapStrategy: \"entries\" | \"record\";\n removeAdditionalStrategy: \"passthrough\" | \"strict\";\n allowedAdditionalProperties: true | undefined;\n rejectedAdditionalProperties: false | undefined;\n target: Target;\n strictUnions: boolean;\n definitionPath: string;\n definitions: Record<string, ZodSchema>;\n errorMessages: boolean;\n markdownDescription: boolean;\n patternStrategy: \"escape\" | \"preserve\";\n applyRegexFlags: boolean;\n emailStrategy: \"format:email\" | \"format:idn-email\" | \"pattern:zod\";\n base64Strategy: \"format:binary\" | \"contentEncoding:base64\" | \"pattern:zod\";\n nameStrategy: \"ref\" | \"title\";\n override?: OverrideCallback;\n postProcess?: PostProcessCallback;\n openAiAnyTypeName: string;\n};\n\nexport const defaultOptions: Options = {\n name: undefined,\n $refStrategy: \"root\",\n basePath: [\"#\"],\n effectStrategy: \"input\",\n pipeStrategy: \"all\",\n dateStrategy: \"format:date-time\",\n mapStrategy: \"entries\",\n removeAdditionalStrategy: \"passthrough\",\n allowedAdditionalProperties: true,\n rejectedAdditionalProperties: false,\n definitionPath: \"definitions\",\n target: \"jsonSchema7\",\n strictUnions: false,\n definitions: {},\n errorMessages: false,\n markdownDescription: false,\n patternStrategy: \"escape\",\n applyRegexFlags: false,\n emailStrategy: \"format:email\",\n base64Strategy: \"contentEncoding:base64\",\n nameStrategy: \"ref\",\n openAiAnyTypeName: \"OpenAiAnyType\",\n};\n\nexport const getDefaultOptions = <Target extends Targets>(\n options: Partial<Options<Target>> | string | undefined\n) =>\n (typeof options === \"string\"\n ? {\n ...defaultOptions,\n name: options,\n }\n : {\n ...defaultOptions,\n ...options,\n }) as Options<Target>;\n"],"mappings":";AAgBA,MAAa,iBAAiB,OAC5B,oDACD;AAuDD,MAAaA,iBAA0B;CACrC,MAAM;CACN,cAAc;CACd,UAAU,CAAC,GAAI;CACf,gBAAgB;CAChB,cAAc;CACd,cAAc;CACd,aAAa;CACb,0BAA0B;CAC1B,6BAA6B;CAC7B,8BAA8B;CAC9B,gBAAgB;CAChB,QAAQ;CACR,cAAc;CACd,aAAa,CAAE;CACf,eAAe;CACf,qBAAqB;CACrB,iBAAiB;CACjB,iBAAiB;CACjB,eAAe;CACf,gBAAgB;CAChB,cAAc;CACd,mBAAmB;AACpB;AAED,MAAa,oBAAoB,CAC/BC,YAEC,OAAO,YAAY,WAChB;CACE,GAAG;CACH,MAAM;AACP,IACD;CACE,GAAG;CACH,GAAG;AACJ"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_Options = require('./Options.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/zod-to-json-schema/Refs.ts
|
|
4
|
+
const getRefs = (options) => {
|
|
5
|
+
const _options = require_Options.getDefaultOptions(options);
|
|
6
|
+
const currentPath = _options.name !== void 0 ? [
|
|
7
|
+
..._options.basePath,
|
|
8
|
+
_options.definitionPath,
|
|
9
|
+
_options.name
|
|
10
|
+
] : _options.basePath;
|
|
11
|
+
return {
|
|
12
|
+
..._options,
|
|
13
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
14
|
+
currentPath,
|
|
15
|
+
propertyPath: void 0,
|
|
16
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [def._def, {
|
|
17
|
+
def: def._def,
|
|
18
|
+
path: [
|
|
19
|
+
..._options.basePath,
|
|
20
|
+
_options.definitionPath,
|
|
21
|
+
name
|
|
22
|
+
],
|
|
23
|
+
jsonSchema: void 0
|
|
24
|
+
}]))
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.getRefs = getRefs;
|
|
30
|
+
//# sourceMappingURL=Refs.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Refs.cjs","names":["options?: string | Partial<Options<Targets>>","getDefaultOptions"],"sources":["../../../src/utils/zod-to-json-schema/Refs.ts"],"sourcesContent":["import { ZodTypeDef } from \"zod/v3\";\nimport { getDefaultOptions, Options, Targets } from \"./Options.js\";\nimport { JsonSchema7Type } from \"./parseTypes.js\";\n\nexport type Refs = {\n seen: Map<ZodTypeDef, Seen>;\n currentPath: string[];\n propertyPath: string[] | undefined;\n flags: { hasReferencedOpenAiAnyType: boolean };\n} & Options<Targets>;\n\nexport type Seen = {\n def: ZodTypeDef;\n path: string[];\n jsonSchema: JsonSchema7Type | undefined;\n};\n\nexport const getRefs = (options?: string | Partial<Options<Targets>>): Refs => {\n const _options = getDefaultOptions(options);\n const currentPath =\n _options.name !== undefined\n ? [..._options.basePath, _options.definitionPath, _options.name]\n : _options.basePath;\n return {\n ..._options,\n flags: { hasReferencedOpenAiAnyType: false },\n currentPath: currentPath,\n propertyPath: undefined,\n seen: new Map(\n Object.entries(_options.definitions).map(([name, def]) => [\n def._def,\n {\n def: def._def,\n path: [..._options.basePath, _options.definitionPath, name],\n // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.\n jsonSchema: undefined,\n },\n ])\n ),\n };\n};\n"],"mappings":";;;AAiBA,MAAa,UAAU,CAACA,YAAuD;CAC7E,MAAM,WAAWC,kCAAkB,QAAQ;CAC3C,MAAM,cACJ,SAAS,SAAS,SACd;EAAC,GAAG,SAAS;EAAU,SAAS;EAAgB,SAAS;CAAK,IAC9D,SAAS;AACf,QAAO;EACL,GAAG;EACH,OAAO,EAAE,4BAA4B,MAAO;EAC/B;EACb,cAAc;EACd,MAAM,IAAI,IACR,OAAO,QAAQ,SAAS,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CACxD,IAAI,MACJ;GACE,KAAK,IAAI;GACT,MAAM;IAAC,GAAG,SAAS;IAAU,SAAS;IAAgB;GAAK;GAE3D,YAAY;EACb,CACF,EAAC;CAEL;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getDefaultOptions } from "./Options.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/zod-to-json-schema/Refs.ts
|
|
4
|
+
const getRefs = (options) => {
|
|
5
|
+
const _options = getDefaultOptions(options);
|
|
6
|
+
const currentPath = _options.name !== void 0 ? [
|
|
7
|
+
..._options.basePath,
|
|
8
|
+
_options.definitionPath,
|
|
9
|
+
_options.name
|
|
10
|
+
] : _options.basePath;
|
|
11
|
+
return {
|
|
12
|
+
..._options,
|
|
13
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
14
|
+
currentPath,
|
|
15
|
+
propertyPath: void 0,
|
|
16
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [def._def, {
|
|
17
|
+
def: def._def,
|
|
18
|
+
path: [
|
|
19
|
+
..._options.basePath,
|
|
20
|
+
_options.definitionPath,
|
|
21
|
+
name
|
|
22
|
+
],
|
|
23
|
+
jsonSchema: void 0
|
|
24
|
+
}]))
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getRefs };
|
|
30
|
+
//# sourceMappingURL=Refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Refs.js","names":["options?: string | Partial<Options<Targets>>"],"sources":["../../../src/utils/zod-to-json-schema/Refs.ts"],"sourcesContent":["import { ZodTypeDef } from \"zod/v3\";\nimport { getDefaultOptions, Options, Targets } from \"./Options.js\";\nimport { JsonSchema7Type } from \"./parseTypes.js\";\n\nexport type Refs = {\n seen: Map<ZodTypeDef, Seen>;\n currentPath: string[];\n propertyPath: string[] | undefined;\n flags: { hasReferencedOpenAiAnyType: boolean };\n} & Options<Targets>;\n\nexport type Seen = {\n def: ZodTypeDef;\n path: string[];\n jsonSchema: JsonSchema7Type | undefined;\n};\n\nexport const getRefs = (options?: string | Partial<Options<Targets>>): Refs => {\n const _options = getDefaultOptions(options);\n const currentPath =\n _options.name !== undefined\n ? [..._options.basePath, _options.definitionPath, _options.name]\n : _options.basePath;\n return {\n ..._options,\n flags: { hasReferencedOpenAiAnyType: false },\n currentPath: currentPath,\n propertyPath: undefined,\n seen: new Map(\n Object.entries(_options.definitions).map(([name, def]) => [\n def._def,\n {\n def: def._def,\n path: [..._options.basePath, _options.definitionPath, name],\n // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.\n jsonSchema: undefined,\n },\n ])\n ),\n };\n};\n"],"mappings":";;;AAiBA,MAAa,UAAU,CAACA,YAAuD;CAC7E,MAAM,WAAW,kBAAkB,QAAQ;CAC3C,MAAM,cACJ,SAAS,SAAS,SACd;EAAC,GAAG,SAAS;EAAU,SAAS;EAAgB,SAAS;CAAK,IAC9D,SAAS;AACf,QAAO;EACL,GAAG;EACH,OAAO,EAAE,4BAA4B,MAAO;EAC/B;EACb,cAAc;EACd,MAAM,IAAI,IACR,OAAO,QAAQ,SAAS,YAAY,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CACxD,IAAI,MACJ;GACE,KAAK,IAAI;GACT,MAAM;IAAC,GAAG,SAAS;IAAU,SAAS;IAAgB;GAAK;GAE3D,YAAY;EACb,CACF,EAAC;CAEL;AACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/utils/zod-to-json-schema/errorMessages.ts
|
|
3
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
4
|
+
if (!refs?.errorMessages) return;
|
|
5
|
+
if (errorMessage) res.errorMessage = {
|
|
6
|
+
...res.errorMessage,
|
|
7
|
+
[key]: errorMessage
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
11
|
+
res[key] = value;
|
|
12
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.addErrorMessage = addErrorMessage;
|
|
17
|
+
exports.setResponseValueAndErrors = setResponseValueAndErrors;
|
|
18
|
+
//# sourceMappingURL=errorMessages.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.cjs","names":["res: T","key: keyof T","errorMessage: string | undefined","refs: Refs","res: Json7Type","key: Key","value: Json7Type[Key]"],"sources":["../../../src/utils/zod-to-json-schema/errorMessages.ts"],"sourcesContent":["import { JsonSchema7TypeUnion } from \"./parseTypes.js\";\nimport { Refs } from \"./Refs.js\";\n\nexport type ErrorMessages<\n T extends JsonSchema7TypeUnion | { format: string } | { pattern: string },\n OmitProperties extends string = \"\",\n> = Partial<\n Omit<{ [key in keyof T]: string }, OmitProperties | \"type\" | \"errorMessages\">\n>;\n\nexport function addErrorMessage<\n T extends { errorMessage?: ErrorMessages<any> },\n>(res: T, key: keyof T, errorMessage: string | undefined, refs: Refs) {\n if (!refs?.errorMessages) return;\n if (errorMessage) {\n res.errorMessage = {\n ...res.errorMessage,\n [key]: errorMessage,\n };\n }\n}\n\nexport function setResponseValueAndErrors<\n Json7Type extends JsonSchema7TypeUnion & {\n errorMessage?: ErrorMessages<Json7Type>;\n },\n Key extends keyof Omit<Json7Type, \"errorMessage\">,\n>(\n res: Json7Type,\n key: Key,\n value: Json7Type[Key],\n errorMessage: string | undefined,\n refs: Refs,\n) {\n res[key] = value;\n addErrorMessage(res, key, errorMessage, refs);\n}\n"],"mappings":";;AAUA,SAAgB,gBAEdA,KAAQC,KAAcC,cAAkCC,MAAY;AACpE,KAAI,CAAC,MAAM,cAAe;AAC1B,KAAI,cACF,IAAI,eAAe;EACjB,GAAG,IAAI;GACN,MAAM;CACR;AAEJ;AAED,SAAgB,0BAMdC,KACAC,KACAC,OACAJ,cACAC,MACA;CACA,IAAI,OAAO;CACX,gBAAgB,KAAK,KAAK,cAAc,KAAK;AAC9C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JsonSchema7TypeUnion } from "./parseTypes.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/zod-to-json-schema/errorMessages.d.ts
|
|
4
|
+
type ErrorMessages<T extends JsonSchema7TypeUnion | {
|
|
5
|
+
format: string;
|
|
6
|
+
} | {
|
|
7
|
+
pattern: string;
|
|
8
|
+
}, OmitProperties extends string = ""> = Partial<Omit<{ [key in keyof T]: string }, OmitProperties | "type" | "errorMessages">>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ErrorMessages };
|
|
11
|
+
//# sourceMappingURL=errorMessages.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.d.cts","names":["JsonSchema7TypeUnion","Refs","ErrorMessages","T","OmitProperties","Omit","Partial","addErrorMessage","setResponseValueAndErrors","Json7Type","Key"],"sources":["../../../src/utils/zod-to-json-schema/errorMessages.d.ts"],"sourcesContent":["import { JsonSchema7TypeUnion } from \"./parseTypes.js\";\nimport { Refs } from \"./Refs.js\";\nexport type ErrorMessages<T extends JsonSchema7TypeUnion | {\n format: string;\n} | {\n pattern: string;\n}, OmitProperties extends string = \"\"> = Partial<Omit<{\n [key in keyof T]: string;\n}, OmitProperties | \"type\" | \"errorMessages\">>;\nexport declare function addErrorMessage<T extends {\n errorMessage?: ErrorMessages<any>;\n}>(res: T, key: keyof T, errorMessage: string | undefined, refs: Refs): void;\nexport declare function setResponseValueAndErrors<Json7Type extends JsonSchema7TypeUnion & {\n errorMessage?: ErrorMessages<Json7Type>;\n}, Key extends keyof Omit<Json7Type, \"errorMessage\">>(res: Json7Type, key: Key, value: Json7Type[Key], errorMessage: string | undefined, refs: Refs): void;\n"],"mappings":";;;KAEYE,wBAAwBF;EAAxBE,MAAAA,EAAAA,MAAAA;CAAa,GAAA;EAAA,OAAWF,EAAAA,MAAAA;CAAoB,EAAA,uBAKtCG,MAAAA,GAAAA,EAAAA,CAAAA,GADuBG,OACvBH,CAD+BE,IAC/BF,CAAAA,UACfC,MADeD,CACfC,GAAAA,MAAAA,EAAc,EAAdA,cAF8CC,GAAAA,MAAAA,GAAAA,eAAAA,CAAAA,CAAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JsonSchema7TypeUnion } from "./parseTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/zod-to-json-schema/errorMessages.d.ts
|
|
4
|
+
type ErrorMessages<T extends JsonSchema7TypeUnion | {
|
|
5
|
+
format: string;
|
|
6
|
+
} | {
|
|
7
|
+
pattern: string;
|
|
8
|
+
}, OmitProperties extends string = ""> = Partial<Omit<{ [key in keyof T]: string }, OmitProperties | "type" | "errorMessages">>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ErrorMessages };
|
|
11
|
+
//# sourceMappingURL=errorMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.d.ts","names":["JsonSchema7TypeUnion","Refs","ErrorMessages","T","OmitProperties","Omit","Partial","addErrorMessage","setResponseValueAndErrors","Json7Type","Key"],"sources":["../../../src/utils/zod-to-json-schema/errorMessages.d.ts"],"sourcesContent":["import { JsonSchema7TypeUnion } from \"./parseTypes.js\";\nimport { Refs } from \"./Refs.js\";\nexport type ErrorMessages<T extends JsonSchema7TypeUnion | {\n format: string;\n} | {\n pattern: string;\n}, OmitProperties extends string = \"\"> = Partial<Omit<{\n [key in keyof T]: string;\n}, OmitProperties | \"type\" | \"errorMessages\">>;\nexport declare function addErrorMessage<T extends {\n errorMessage?: ErrorMessages<any>;\n}>(res: T, key: keyof T, errorMessage: string | undefined, refs: Refs): void;\nexport declare function setResponseValueAndErrors<Json7Type extends JsonSchema7TypeUnion & {\n errorMessage?: ErrorMessages<Json7Type>;\n}, Key extends keyof Omit<Json7Type, \"errorMessage\">>(res: Json7Type, key: Key, value: Json7Type[Key], errorMessage: string | undefined, refs: Refs): void;\n"],"mappings":";;;KAEYE,wBAAwBF;EAAxBE,MAAAA,EAAAA,MAAAA;CAAa,GAAA;EAAA,OAAWF,EAAAA,MAAAA;CAAoB,EAAA,uBAKtCG,MAAAA,GAAAA,EAAAA,CAAAA,GADuBG,OACvBH,CAD+BE,IAC/BF,CAAAA,UACfC,MADeD,CACfC,GAAAA,MAAAA,EAAc,EAAdA,cAF8CC,GAAAA,MAAAA,GAAAA,eAAAA,CAAAA,CAAAA"}
|