langchain 0.2.18 → 0.3.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/openai_functions/index.cjs +2 -2
- package/dist/agents/openai_functions/index.js +2 -2
- package/dist/chains/combine_documents/stuff.cjs +2 -2
- package/dist/chains/combine_documents/stuff.js +2 -2
- package/dist/chains/openai_functions/openapi.cjs +3 -1
- package/dist/chains/openai_functions/openapi.js +3 -1
- package/dist/load/import_constants.cjs +2 -39
- package/dist/load/import_constants.js +2 -39
- package/dist/load/import_map.cjs +2 -3
- package/dist/load/import_map.d.ts +0 -1
- package/dist/load/import_map.js +0 -1
- package/dist/smith/config.d.ts +1 -5
- package/package.json +31 -854
- package/dist/document_loaders/fs/chatgpt.cjs +0 -90
- package/dist/document_loaders/fs/chatgpt.d.ts +0 -8
- package/dist/document_loaders/fs/chatgpt.js +0 -86
- package/dist/document_loaders/fs/csv.cjs +0 -73
- package/dist/document_loaders/fs/csv.d.ts +0 -65
- package/dist/document_loaders/fs/csv.js +0 -69
- package/dist/document_loaders/fs/docx.cjs +0 -58
- package/dist/document_loaders/fs/docx.d.ts +0 -25
- package/dist/document_loaders/fs/docx.js +0 -54
- package/dist/document_loaders/fs/epub.cjs +0 -103
- package/dist/document_loaders/fs/epub.d.ts +0 -33
- package/dist/document_loaders/fs/epub.js +0 -99
- package/dist/document_loaders/fs/notion.cjs +0 -26
- package/dist/document_loaders/fs/notion.d.ts +0 -12
- package/dist/document_loaders/fs/notion.js +0 -22
- package/dist/document_loaders/fs/obsidian.cjs +0 -247
- package/dist/document_loaders/fs/obsidian.d.ts +0 -28
- package/dist/document_loaders/fs/obsidian.js +0 -240
- package/dist/document_loaders/fs/openai_whisper_audio.cjs +0 -49
- package/dist/document_loaders/fs/openai_whisper_audio.d.ts +0 -23
- package/dist/document_loaders/fs/openai_whisper_audio.js +0 -45
- package/dist/document_loaders/fs/pdf.cjs +0 -148
- package/dist/document_loaders/fs/pdf.d.ts +0 -49
- package/dist/document_loaders/fs/pdf.js +0 -144
- package/dist/document_loaders/fs/pptx.cjs +0 -46
- package/dist/document_loaders/fs/pptx.d.ts +0 -25
- package/dist/document_loaders/fs/pptx.js +0 -42
- package/dist/document_loaders/fs/srt.cjs +0 -57
- package/dist/document_loaders/fs/srt.d.ts +0 -32
- package/dist/document_loaders/fs/srt.js +0 -50
- package/dist/document_loaders/fs/unstructured.cjs +0 -338
- package/dist/document_loaders/fs/unstructured.d.ts +0 -125
- package/dist/document_loaders/fs/unstructured.js +0 -333
- package/dist/document_loaders/web/apify_dataset.cjs +0 -130
- package/dist/document_loaders/web/apify_dataset.d.ts +0 -85
- package/dist/document_loaders/web/apify_dataset.js +0 -126
- package/dist/document_loaders/web/assemblyai.cjs +0 -200
- package/dist/document_loaders/web/assemblyai.d.ts +0 -95
- package/dist/document_loaders/web/assemblyai.js +0 -193
- package/dist/document_loaders/web/azure_blob_storage_container.cjs +0 -73
- package/dist/document_loaders/web/azure_blob_storage_container.d.ts +0 -46
- package/dist/document_loaders/web/azure_blob_storage_container.js +0 -69
- package/dist/document_loaders/web/azure_blob_storage_file.cjs +0 -124
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +0 -53
- package/dist/document_loaders/web/azure_blob_storage_file.js +0 -97
- package/dist/document_loaders/web/browserbase.cjs +0 -93
- package/dist/document_loaders/web/browserbase.d.ts +0 -48
- package/dist/document_loaders/web/browserbase.js +0 -86
- package/dist/document_loaders/web/cheerio.cjs +0 -118
- package/dist/document_loaders/web/cheerio.d.ts +0 -77
- package/dist/document_loaders/web/cheerio.js +0 -114
- package/dist/document_loaders/web/college_confidential.cjs +0 -41
- package/dist/document_loaders/web/college_confidential.d.ts +0 -25
- package/dist/document_loaders/web/college_confidential.js +0 -37
- package/dist/document_loaders/web/confluence.cjs +0 -190
- package/dist/document_loaders/web/confluence.d.ts +0 -114
- package/dist/document_loaders/web/confluence.js +0 -186
- package/dist/document_loaders/web/couchbase.cjs +0 -95
- package/dist/document_loaders/web/couchbase.d.ts +0 -32
- package/dist/document_loaders/web/couchbase.js +0 -91
- package/dist/document_loaders/web/figma.cjs +0 -102
- package/dist/document_loaders/web/figma.d.ts +0 -82
- package/dist/document_loaders/web/figma.js +0 -98
- package/dist/document_loaders/web/firecrawl.cjs +0 -95
- package/dist/document_loaders/web/firecrawl.d.ts +0 -50
- package/dist/document_loaders/web/firecrawl.js +0 -88
- package/dist/document_loaders/web/gitbook.cjs +0 -110
- package/dist/document_loaders/web/gitbook.d.ts +0 -55
- package/dist/document_loaders/web/gitbook.js +0 -106
- package/dist/document_loaders/web/github.cjs +0 -615
- package/dist/document_loaders/web/github.d.ts +0 -203
- package/dist/document_loaders/web/github.js +0 -608
- package/dist/document_loaders/web/hn.cjs +0 -90
- package/dist/document_loaders/web/hn.d.ts +0 -42
- package/dist/document_loaders/web/hn.js +0 -86
- package/dist/document_loaders/web/imsdb.cjs +0 -44
- package/dist/document_loaders/web/imsdb.d.ts +0 -23
- package/dist/document_loaders/web/imsdb.js +0 -40
- package/dist/document_loaders/web/notionapi.cjs +0 -404
- package/dist/document_loaders/web/notionapi.d.ts +0 -133
- package/dist/document_loaders/web/notionapi.js +0 -392
- package/dist/document_loaders/web/notiondb.cjs +0 -199
- package/dist/document_loaders/web/notiondb.d.ts +0 -56
- package/dist/document_loaders/web/notiondb.js +0 -195
- package/dist/document_loaders/web/pdf.cjs +0 -140
- package/dist/document_loaders/web/pdf.d.ts +0 -35
- package/dist/document_loaders/web/pdf.js +0 -136
- package/dist/document_loaders/web/playwright.cjs +0 -89
- package/dist/document_loaders/web/playwright.d.ts +0 -58
- package/dist/document_loaders/web/playwright.js +0 -85
- package/dist/document_loaders/web/puppeteer.cjs +0 -139
- package/dist/document_loaders/web/puppeteer.d.ts +0 -82
- package/dist/document_loaders/web/puppeteer.js +0 -135
- package/dist/document_loaders/web/recursive_url.cjs +0 -198
- package/dist/document_loaders/web/recursive_url.d.ts +0 -33
- package/dist/document_loaders/web/recursive_url.js +0 -194
- package/dist/document_loaders/web/s3.cjs +0 -164
- package/dist/document_loaders/web/s3.d.ts +0 -78
- package/dist/document_loaders/web/s3.js +0 -137
- package/dist/document_loaders/web/searchapi.cjs +0 -150
- package/dist/document_loaders/web/searchapi.d.ts +0 -76
- package/dist/document_loaders/web/searchapi.js +0 -146
- package/dist/document_loaders/web/serpapi.cjs +0 -127
- package/dist/document_loaders/web/serpapi.d.ts +0 -62
- package/dist/document_loaders/web/serpapi.js +0 -123
- package/dist/document_loaders/web/sitemap.cjs +0 -118
- package/dist/document_loaders/web/sitemap.d.ts +0 -41
- package/dist/document_loaders/web/sitemap.js +0 -114
- package/dist/document_loaders/web/sonix_audio.cjs +0 -68
- package/dist/document_loaders/web/sonix_audio.d.ts +0 -36
- package/dist/document_loaders/web/sonix_audio.js +0 -64
- package/dist/document_loaders/web/sort_xyz_blockchain.cjs +0 -157
- package/dist/document_loaders/web/sort_xyz_blockchain.d.ts +0 -78
- package/dist/document_loaders/web/sort_xyz_blockchain.js +0 -153
- package/dist/document_loaders/web/youtube.cjs +0 -116
- package/dist/document_loaders/web/youtube.d.ts +0 -55
- package/dist/document_loaders/web/youtube.js +0 -112
- package/dist/experimental/tools/pyinterpreter.cjs +0 -248
- package/dist/experimental/tools/pyinterpreter.d.ts +0 -18
- package/dist/experimental/tools/pyinterpreter.js +0 -244
- package/dist/retrievers/self_query/chroma.cjs +0 -48
- package/dist/retrievers/self_query/chroma.d.ts +0 -26
- package/dist/retrievers/self_query/chroma.js +0 -44
- package/dist/retrievers/self_query/pinecone.cjs +0 -47
- package/dist/retrievers/self_query/pinecone.d.ts +0 -26
- package/dist/retrievers/self_query/pinecone.js +0 -43
- package/dist/retrievers/self_query/supabase.cjs +0 -278
- package/dist/retrievers/self_query/supabase.d.ts +0 -109
- package/dist/retrievers/self_query/supabase.js +0 -274
- package/dist/retrievers/self_query/supabase_utils.cjs +0 -264
- package/dist/retrievers/self_query/supabase_utils.d.ts +0 -101
- package/dist/retrievers/self_query/supabase_utils.js +0 -259
- package/dist/retrievers/self_query/vectara.cjs +0 -143
- package/dist/retrievers/self_query/vectara.d.ts +0 -42
- package/dist/retrievers/self_query/vectara.js +0 -139
- package/dist/retrievers/self_query/weaviate.cjs +0 -201
- package/dist/retrievers/self_query/weaviate.d.ts +0 -99
- package/dist/retrievers/self_query/weaviate.js +0 -197
- package/dist/types/assemblyai-types.cjs +0 -2
- package/dist/types/assemblyai-types.d.ts +0 -4
- package/dist/types/assemblyai-types.js +0 -1
- package/document_loaders/fs/chatgpt.cjs +0 -1
- package/document_loaders/fs/chatgpt.d.cts +0 -1
- package/document_loaders/fs/chatgpt.d.ts +0 -1
- package/document_loaders/fs/chatgpt.js +0 -1
- package/document_loaders/fs/csv.cjs +0 -1
- package/document_loaders/fs/csv.d.cts +0 -1
- package/document_loaders/fs/csv.d.ts +0 -1
- package/document_loaders/fs/csv.js +0 -1
- package/document_loaders/fs/docx.cjs +0 -1
- package/document_loaders/fs/docx.d.cts +0 -1
- package/document_loaders/fs/docx.d.ts +0 -1
- package/document_loaders/fs/docx.js +0 -1
- package/document_loaders/fs/epub.cjs +0 -1
- package/document_loaders/fs/epub.d.cts +0 -1
- package/document_loaders/fs/epub.d.ts +0 -1
- package/document_loaders/fs/epub.js +0 -1
- package/document_loaders/fs/notion.cjs +0 -1
- package/document_loaders/fs/notion.d.cts +0 -1
- package/document_loaders/fs/notion.d.ts +0 -1
- package/document_loaders/fs/notion.js +0 -1
- package/document_loaders/fs/obsidian.cjs +0 -1
- package/document_loaders/fs/obsidian.d.cts +0 -1
- package/document_loaders/fs/obsidian.d.ts +0 -1
- package/document_loaders/fs/obsidian.js +0 -1
- package/document_loaders/fs/openai_whisper_audio.cjs +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.cts +0 -1
- package/document_loaders/fs/openai_whisper_audio.d.ts +0 -1
- package/document_loaders/fs/openai_whisper_audio.js +0 -1
- package/document_loaders/fs/pdf.cjs +0 -1
- package/document_loaders/fs/pdf.d.cts +0 -1
- package/document_loaders/fs/pdf.d.ts +0 -1
- package/document_loaders/fs/pdf.js +0 -1
- package/document_loaders/fs/pptx.cjs +0 -1
- package/document_loaders/fs/pptx.d.cts +0 -1
- package/document_loaders/fs/pptx.d.ts +0 -1
- package/document_loaders/fs/pptx.js +0 -1
- package/document_loaders/fs/srt.cjs +0 -1
- package/document_loaders/fs/srt.d.cts +0 -1
- package/document_loaders/fs/srt.d.ts +0 -1
- package/document_loaders/fs/srt.js +0 -1
- package/document_loaders/fs/unstructured.cjs +0 -1
- package/document_loaders/fs/unstructured.d.cts +0 -1
- package/document_loaders/fs/unstructured.d.ts +0 -1
- package/document_loaders/fs/unstructured.js +0 -1
- package/document_loaders/web/apify_dataset.cjs +0 -1
- package/document_loaders/web/apify_dataset.d.cts +0 -1
- package/document_loaders/web/apify_dataset.d.ts +0 -1
- package/document_loaders/web/apify_dataset.js +0 -1
- package/document_loaders/web/assemblyai.cjs +0 -1
- package/document_loaders/web/assemblyai.d.cts +0 -1
- package/document_loaders/web/assemblyai.d.ts +0 -1
- package/document_loaders/web/assemblyai.js +0 -1
- package/document_loaders/web/azure_blob_storage_container.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_container.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_container.js +0 -1
- package/document_loaders/web/azure_blob_storage_file.cjs +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.cts +0 -1
- package/document_loaders/web/azure_blob_storage_file.d.ts +0 -1
- package/document_loaders/web/azure_blob_storage_file.js +0 -1
- package/document_loaders/web/browserbase.cjs +0 -1
- package/document_loaders/web/browserbase.d.cts +0 -1
- package/document_loaders/web/browserbase.d.ts +0 -1
- package/document_loaders/web/browserbase.js +0 -1
- package/document_loaders/web/cheerio.cjs +0 -1
- package/document_loaders/web/cheerio.d.cts +0 -1
- package/document_loaders/web/cheerio.d.ts +0 -1
- package/document_loaders/web/cheerio.js +0 -1
- package/document_loaders/web/college_confidential.cjs +0 -1
- package/document_loaders/web/college_confidential.d.cts +0 -1
- package/document_loaders/web/college_confidential.d.ts +0 -1
- package/document_loaders/web/college_confidential.js +0 -1
- package/document_loaders/web/confluence.cjs +0 -1
- package/document_loaders/web/confluence.d.cts +0 -1
- package/document_loaders/web/confluence.d.ts +0 -1
- package/document_loaders/web/confluence.js +0 -1
- package/document_loaders/web/couchbase.cjs +0 -1
- package/document_loaders/web/couchbase.d.cts +0 -1
- package/document_loaders/web/couchbase.d.ts +0 -1
- package/document_loaders/web/couchbase.js +0 -1
- package/document_loaders/web/figma.cjs +0 -1
- package/document_loaders/web/figma.d.cts +0 -1
- package/document_loaders/web/figma.d.ts +0 -1
- package/document_loaders/web/figma.js +0 -1
- package/document_loaders/web/firecrawl.cjs +0 -1
- package/document_loaders/web/firecrawl.d.cts +0 -1
- package/document_loaders/web/firecrawl.d.ts +0 -1
- package/document_loaders/web/firecrawl.js +0 -1
- package/document_loaders/web/gitbook.cjs +0 -1
- package/document_loaders/web/gitbook.d.cts +0 -1
- package/document_loaders/web/gitbook.d.ts +0 -1
- package/document_loaders/web/gitbook.js +0 -1
- package/document_loaders/web/github.cjs +0 -1
- package/document_loaders/web/github.d.cts +0 -1
- package/document_loaders/web/github.d.ts +0 -1
- package/document_loaders/web/github.js +0 -1
- package/document_loaders/web/hn.cjs +0 -1
- package/document_loaders/web/hn.d.cts +0 -1
- package/document_loaders/web/hn.d.ts +0 -1
- package/document_loaders/web/hn.js +0 -1
- package/document_loaders/web/imsdb.cjs +0 -1
- package/document_loaders/web/imsdb.d.cts +0 -1
- package/document_loaders/web/imsdb.d.ts +0 -1
- package/document_loaders/web/imsdb.js +0 -1
- package/document_loaders/web/notionapi.cjs +0 -1
- package/document_loaders/web/notionapi.d.cts +0 -1
- package/document_loaders/web/notionapi.d.ts +0 -1
- package/document_loaders/web/notionapi.js +0 -1
- package/document_loaders/web/notiondb.cjs +0 -1
- package/document_loaders/web/notiondb.d.cts +0 -1
- package/document_loaders/web/notiondb.d.ts +0 -1
- package/document_loaders/web/notiondb.js +0 -1
- package/document_loaders/web/pdf.cjs +0 -1
- package/document_loaders/web/pdf.d.cts +0 -1
- package/document_loaders/web/pdf.d.ts +0 -1
- package/document_loaders/web/pdf.js +0 -1
- package/document_loaders/web/playwright.cjs +0 -1
- package/document_loaders/web/playwright.d.cts +0 -1
- package/document_loaders/web/playwright.d.ts +0 -1
- package/document_loaders/web/playwright.js +0 -1
- package/document_loaders/web/puppeteer.cjs +0 -1
- package/document_loaders/web/puppeteer.d.cts +0 -1
- package/document_loaders/web/puppeteer.d.ts +0 -1
- package/document_loaders/web/puppeteer.js +0 -1
- package/document_loaders/web/recursive_url.cjs +0 -1
- package/document_loaders/web/recursive_url.d.cts +0 -1
- package/document_loaders/web/recursive_url.d.ts +0 -1
- package/document_loaders/web/recursive_url.js +0 -1
- package/document_loaders/web/s3.cjs +0 -1
- package/document_loaders/web/s3.d.cts +0 -1
- package/document_loaders/web/s3.d.ts +0 -1
- package/document_loaders/web/s3.js +0 -1
- package/document_loaders/web/searchapi.cjs +0 -1
- package/document_loaders/web/searchapi.d.cts +0 -1
- package/document_loaders/web/searchapi.d.ts +0 -1
- package/document_loaders/web/searchapi.js +0 -1
- package/document_loaders/web/serpapi.cjs +0 -1
- package/document_loaders/web/serpapi.d.cts +0 -1
- package/document_loaders/web/serpapi.d.ts +0 -1
- package/document_loaders/web/serpapi.js +0 -1
- package/document_loaders/web/sitemap.cjs +0 -1
- package/document_loaders/web/sitemap.d.cts +0 -1
- package/document_loaders/web/sitemap.d.ts +0 -1
- package/document_loaders/web/sitemap.js +0 -1
- package/document_loaders/web/sonix_audio.cjs +0 -1
- package/document_loaders/web/sonix_audio.d.cts +0 -1
- package/document_loaders/web/sonix_audio.d.ts +0 -1
- package/document_loaders/web/sonix_audio.js +0 -1
- package/document_loaders/web/sort_xyz_blockchain.cjs +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.cts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.d.ts +0 -1
- package/document_loaders/web/sort_xyz_blockchain.js +0 -1
- package/document_loaders/web/youtube.cjs +0 -1
- package/document_loaders/web/youtube.d.cts +0 -1
- package/document_loaders/web/youtube.d.ts +0 -1
- package/document_loaders/web/youtube.js +0 -1
- package/experimental/tools/pyinterpreter.cjs +0 -1
- package/experimental/tools/pyinterpreter.d.cts +0 -1
- package/experimental/tools/pyinterpreter.d.ts +0 -1
- package/experimental/tools/pyinterpreter.js +0 -1
- package/memory/index.cjs +0 -1
- package/memory/index.d.cts +0 -1
- package/memory/index.d.ts +0 -1
- package/memory/index.js +0 -1
- package/retrievers/self_query/chroma.cjs +0 -1
- package/retrievers/self_query/chroma.d.cts +0 -1
- package/retrievers/self_query/chroma.d.ts +0 -1
- package/retrievers/self_query/chroma.js +0 -1
- package/retrievers/self_query/pinecone.cjs +0 -1
- package/retrievers/self_query/pinecone.d.cts +0 -1
- package/retrievers/self_query/pinecone.d.ts +0 -1
- package/retrievers/self_query/pinecone.js +0 -1
- package/retrievers/self_query/supabase.cjs +0 -1
- package/retrievers/self_query/supabase.d.cts +0 -1
- package/retrievers/self_query/supabase.d.ts +0 -1
- package/retrievers/self_query/supabase.js +0 -1
- package/retrievers/self_query/vectara.cjs +0 -1
- package/retrievers/self_query/vectara.d.cts +0 -1
- package/retrievers/self_query/vectara.d.ts +0 -1
- package/retrievers/self_query/vectara.js +0 -1
- package/retrievers/self_query/weaviate.cjs +0 -1
- package/retrievers/self_query/weaviate.d.cts +0 -1
- package/retrievers/self_query/weaviate.d.ts +0 -1
- package/retrievers/self_query/weaviate.js +0 -1
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.VectaraTranslator = void 0;
|
|
5
|
-
const structured_query_1 = require("@langchain/core/structured_query");
|
|
6
|
-
const entrypoint_deprecation_js_1 = require("../../util/entrypoint_deprecation.cjs");
|
|
7
|
-
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion020MigrationWarning)({
|
|
8
|
-
oldEntrypointName: "retrievers/self_query/vectara",
|
|
9
|
-
newEntrypointName: "structured_query/vectara",
|
|
10
|
-
newPackageName: "@langchain/community",
|
|
11
|
-
});
|
|
12
|
-
function processValue(value) {
|
|
13
|
-
/** Convert a value to a string and add single quotes if it is a string. */
|
|
14
|
-
if (typeof value === "string") {
|
|
15
|
-
return `'${value}'`;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
return String(value);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
class VectaraTranslator extends structured_query_1.BaseTranslator {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
Object.defineProperty(this, "allowedOperators", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: [structured_query_1.Operators.and, structured_query_1.Operators.or]
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(this, "allowedComparators", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: [
|
|
35
|
-
structured_query_1.Comparators.eq,
|
|
36
|
-
structured_query_1.Comparators.ne,
|
|
37
|
-
structured_query_1.Comparators.lt,
|
|
38
|
-
structured_query_1.Comparators.lte,
|
|
39
|
-
structured_query_1.Comparators.gt,
|
|
40
|
-
structured_query_1.Comparators.gte,
|
|
41
|
-
]
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
formatFunction(func) {
|
|
45
|
-
if (func in structured_query_1.Comparators) {
|
|
46
|
-
if (this.allowedComparators.length > 0 &&
|
|
47
|
-
this.allowedComparators.indexOf(func) === -1) {
|
|
48
|
-
throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (func in structured_query_1.Operators) {
|
|
52
|
-
if (this.allowedOperators.length > 0 &&
|
|
53
|
-
this.allowedOperators.indexOf(func) === -1) {
|
|
54
|
-
throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
throw new Error("Unknown comparator or operator");
|
|
59
|
-
}
|
|
60
|
-
const mapDict = {
|
|
61
|
-
and: " and ",
|
|
62
|
-
or: " or ",
|
|
63
|
-
eq: "=",
|
|
64
|
-
ne: "!=",
|
|
65
|
-
lt: "<",
|
|
66
|
-
lte: "<=",
|
|
67
|
-
gt: ">",
|
|
68
|
-
gte: ">=",
|
|
69
|
-
};
|
|
70
|
-
return mapDict[func];
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Visits an operation and returns a VectaraOperationResult. The
|
|
74
|
-
* operation's arguments are visited and the operator is formatted.
|
|
75
|
-
* @param operation The operation to visit.
|
|
76
|
-
* @returns A VectaraOperationResult.
|
|
77
|
-
*/
|
|
78
|
-
visitOperation(operation) {
|
|
79
|
-
const args = operation.args?.map((arg) => arg.accept(this));
|
|
80
|
-
const operator = this.formatFunction(operation.operator);
|
|
81
|
-
return `( ${args.join(operator)} )`;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
85
|
-
* comparison's value is checked for type and the comparator is formatted.
|
|
86
|
-
* Throws an error if the value type is not supported.
|
|
87
|
-
* @param comparison The comparison to visit.
|
|
88
|
-
* @returns A VectaraComparisonResult.
|
|
89
|
-
*/
|
|
90
|
-
visitComparison(comparison) {
|
|
91
|
-
const comparator = this.formatFunction(comparison.comparator);
|
|
92
|
-
return `( doc.${comparison.attribute} ${comparator} ${processValue(comparison.value)} )`;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
96
|
-
* If the query has a filter, it is visited.
|
|
97
|
-
* @param query The structured query to visit.
|
|
98
|
-
* @returns A VectaraStructuredQueryResult.
|
|
99
|
-
*/
|
|
100
|
-
visitStructuredQuery(query) {
|
|
101
|
-
let nextArg = {};
|
|
102
|
-
if (query.filter) {
|
|
103
|
-
nextArg = {
|
|
104
|
-
filter: { filter: query.filter.accept(this) },
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return nextArg;
|
|
108
|
-
}
|
|
109
|
-
mergeFilters(defaultFilter, generatedFilter, mergeType = "and", forceDefaultFilter = false) {
|
|
110
|
-
if ((0, structured_query_1.isFilterEmpty)(defaultFilter) && (0, structured_query_1.isFilterEmpty)(generatedFilter)) {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
if ((0, structured_query_1.isFilterEmpty)(defaultFilter) || mergeType === "replace") {
|
|
114
|
-
if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
|
|
115
|
-
return undefined;
|
|
116
|
-
}
|
|
117
|
-
return generatedFilter;
|
|
118
|
-
}
|
|
119
|
-
if ((0, structured_query_1.isFilterEmpty)(generatedFilter)) {
|
|
120
|
-
if (forceDefaultFilter) {
|
|
121
|
-
return defaultFilter;
|
|
122
|
-
}
|
|
123
|
-
if (mergeType === "and") {
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|
|
126
|
-
return defaultFilter;
|
|
127
|
-
}
|
|
128
|
-
if (mergeType === "and") {
|
|
129
|
-
return {
|
|
130
|
-
filter: `${defaultFilter} and ${generatedFilter}`,
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
else if (mergeType === "or") {
|
|
134
|
-
return {
|
|
135
|
-
filter: `${defaultFilter} or ${generatedFilter}`,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
throw new Error("Unknown merge type");
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
exports.VectaraTranslator = VectaraTranslator;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { BaseTranslator, Comparator, Comparison, Operation, Operator, StructuredQuery } from "@langchain/core/structured_query";
|
|
2
|
-
import { VectorStore } from "@langchain/core/vectorstores";
|
|
3
|
-
export type VectaraVisitorResult = VectaraOperationResult | VectaraComparisonResult | VectaraVisitorStructuredQueryResult;
|
|
4
|
-
export type VectaraOperationResult = String;
|
|
5
|
-
export type VectaraComparisonResult = String;
|
|
6
|
-
export type VectaraVisitorStructuredQueryResult = {
|
|
7
|
-
filter?: {
|
|
8
|
-
filter?: VectaraOperationResult | VectaraComparisonResult;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
type VectaraFilter = any;
|
|
12
|
-
export declare class VectaraTranslator<T extends VectorStore> extends BaseTranslator<T> {
|
|
13
|
-
VisitOperationOutput: VectaraOperationResult;
|
|
14
|
-
VisitComparisonOutput: VectaraComparisonResult;
|
|
15
|
-
allowedOperators: Operator[];
|
|
16
|
-
allowedComparators: Comparator[];
|
|
17
|
-
formatFunction(func: Operator | Comparator): string;
|
|
18
|
-
/**
|
|
19
|
-
* Visits an operation and returns a VectaraOperationResult. The
|
|
20
|
-
* operation's arguments are visited and the operator is formatted.
|
|
21
|
-
* @param operation The operation to visit.
|
|
22
|
-
* @returns A VectaraOperationResult.
|
|
23
|
-
*/
|
|
24
|
-
visitOperation(operation: Operation): this["VisitOperationOutput"];
|
|
25
|
-
/**
|
|
26
|
-
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
27
|
-
* comparison's value is checked for type and the comparator is formatted.
|
|
28
|
-
* Throws an error if the value type is not supported.
|
|
29
|
-
* @param comparison The comparison to visit.
|
|
30
|
-
* @returns A VectaraComparisonResult.
|
|
31
|
-
*/
|
|
32
|
-
visitComparison(comparison: Comparison): this["VisitComparisonOutput"];
|
|
33
|
-
/**
|
|
34
|
-
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
35
|
-
* If the query has a filter, it is visited.
|
|
36
|
-
* @param query The structured query to visit.
|
|
37
|
-
* @returns A VectaraStructuredQueryResult.
|
|
38
|
-
*/
|
|
39
|
-
visitStructuredQuery(query: StructuredQuery): this["VisitStructuredQueryOutput"];
|
|
40
|
-
mergeFilters(defaultFilter: VectaraFilter | undefined, generatedFilter: VectaraFilter | undefined, mergeType?: string, forceDefaultFilter?: boolean): VectaraFilter | undefined;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { BaseTranslator, isFilterEmpty, Comparators, Operators, } from "@langchain/core/structured_query";
|
|
3
|
-
import { logVersion020MigrationWarning } from "../../util/entrypoint_deprecation.js";
|
|
4
|
-
/* #__PURE__ */ logVersion020MigrationWarning({
|
|
5
|
-
oldEntrypointName: "retrievers/self_query/vectara",
|
|
6
|
-
newEntrypointName: "structured_query/vectara",
|
|
7
|
-
newPackageName: "@langchain/community",
|
|
8
|
-
});
|
|
9
|
-
function processValue(value) {
|
|
10
|
-
/** Convert a value to a string and add single quotes if it is a string. */
|
|
11
|
-
if (typeof value === "string") {
|
|
12
|
-
return `'${value}'`;
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return String(value);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class VectaraTranslator extends BaseTranslator {
|
|
19
|
-
constructor() {
|
|
20
|
-
super(...arguments);
|
|
21
|
-
Object.defineProperty(this, "allowedOperators", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: [Operators.and, Operators.or]
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "allowedComparators", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: [
|
|
32
|
-
Comparators.eq,
|
|
33
|
-
Comparators.ne,
|
|
34
|
-
Comparators.lt,
|
|
35
|
-
Comparators.lte,
|
|
36
|
-
Comparators.gt,
|
|
37
|
-
Comparators.gte,
|
|
38
|
-
]
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
formatFunction(func) {
|
|
42
|
-
if (func in Comparators) {
|
|
43
|
-
if (this.allowedComparators.length > 0 &&
|
|
44
|
-
this.allowedComparators.indexOf(func) === -1) {
|
|
45
|
-
throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else if (func in Operators) {
|
|
49
|
-
if (this.allowedOperators.length > 0 &&
|
|
50
|
-
this.allowedOperators.indexOf(func) === -1) {
|
|
51
|
-
throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new Error("Unknown comparator or operator");
|
|
56
|
-
}
|
|
57
|
-
const mapDict = {
|
|
58
|
-
and: " and ",
|
|
59
|
-
or: " or ",
|
|
60
|
-
eq: "=",
|
|
61
|
-
ne: "!=",
|
|
62
|
-
lt: "<",
|
|
63
|
-
lte: "<=",
|
|
64
|
-
gt: ">",
|
|
65
|
-
gte: ">=",
|
|
66
|
-
};
|
|
67
|
-
return mapDict[func];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Visits an operation and returns a VectaraOperationResult. The
|
|
71
|
-
* operation's arguments are visited and the operator is formatted.
|
|
72
|
-
* @param operation The operation to visit.
|
|
73
|
-
* @returns A VectaraOperationResult.
|
|
74
|
-
*/
|
|
75
|
-
visitOperation(operation) {
|
|
76
|
-
const args = operation.args?.map((arg) => arg.accept(this));
|
|
77
|
-
const operator = this.formatFunction(operation.operator);
|
|
78
|
-
return `( ${args.join(operator)} )`;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Visits a comparison and returns a VectaraComparisonResult. The
|
|
82
|
-
* comparison's value is checked for type and the comparator is formatted.
|
|
83
|
-
* Throws an error if the value type is not supported.
|
|
84
|
-
* @param comparison The comparison to visit.
|
|
85
|
-
* @returns A VectaraComparisonResult.
|
|
86
|
-
*/
|
|
87
|
-
visitComparison(comparison) {
|
|
88
|
-
const comparator = this.formatFunction(comparison.comparator);
|
|
89
|
-
return `( doc.${comparison.attribute} ${comparator} ${processValue(comparison.value)} )`;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Visits a structured query and returns a VectaraStructuredQueryResult.
|
|
93
|
-
* If the query has a filter, it is visited.
|
|
94
|
-
* @param query The structured query to visit.
|
|
95
|
-
* @returns A VectaraStructuredQueryResult.
|
|
96
|
-
*/
|
|
97
|
-
visitStructuredQuery(query) {
|
|
98
|
-
let nextArg = {};
|
|
99
|
-
if (query.filter) {
|
|
100
|
-
nextArg = {
|
|
101
|
-
filter: { filter: query.filter.accept(this) },
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
return nextArg;
|
|
105
|
-
}
|
|
106
|
-
mergeFilters(defaultFilter, generatedFilter, mergeType = "and", forceDefaultFilter = false) {
|
|
107
|
-
if (isFilterEmpty(defaultFilter) && isFilterEmpty(generatedFilter)) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
if (isFilterEmpty(defaultFilter) || mergeType === "replace") {
|
|
111
|
-
if (isFilterEmpty(generatedFilter)) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
return generatedFilter;
|
|
115
|
-
}
|
|
116
|
-
if (isFilterEmpty(generatedFilter)) {
|
|
117
|
-
if (forceDefaultFilter) {
|
|
118
|
-
return defaultFilter;
|
|
119
|
-
}
|
|
120
|
-
if (mergeType === "and") {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
return defaultFilter;
|
|
124
|
-
}
|
|
125
|
-
if (mergeType === "and") {
|
|
126
|
-
return {
|
|
127
|
-
filter: `${defaultFilter} and ${generatedFilter}`,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
else if (mergeType === "or") {
|
|
131
|
-
return {
|
|
132
|
-
filter: `${defaultFilter} or ${generatedFilter}`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
throw new Error("Unknown merge type");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.WeaviateTranslator = void 0;
|
|
5
|
-
const structured_query_1 = require("@langchain/core/structured_query");
|
|
6
|
-
const entrypoint_deprecation_js_1 = require("../../util/entrypoint_deprecation.cjs");
|
|
7
|
-
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion020MigrationWarning)({
|
|
8
|
-
oldEntrypointName: "retrievers/self_query/weaviate",
|
|
9
|
-
newEntrypointName: "",
|
|
10
|
-
newPackageName: "@langchain/weaviate",
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* A class that translates or converts data into a format that can be used
|
|
14
|
-
* with Weaviate, a vector search engine. It extends the `BaseTranslator`
|
|
15
|
-
* class and provides specific implementation for Weaviate.
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const selfQueryRetriever = new SelfQueryRetriever({
|
|
19
|
-
* llm: new ChatOpenAI(),
|
|
20
|
-
* vectorStore: new WeaviateStore(),
|
|
21
|
-
* documentContents: "Brief summary of a movie",
|
|
22
|
-
* attributeInfo: [],
|
|
23
|
-
* structuredQueryTranslator: new WeaviateTranslator(),
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
|
|
27
|
-
* "Which movies are rated higher than 8.5?",
|
|
28
|
-
* );
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
class WeaviateTranslator extends structured_query_1.BaseTranslator {
|
|
32
|
-
constructor() {
|
|
33
|
-
super(...arguments);
|
|
34
|
-
Object.defineProperty(this, "allowedOperators", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: [structured_query_1.Operators.and, structured_query_1.Operators.or]
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(this, "allowedComparators", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
configurable: true,
|
|
43
|
-
writable: true,
|
|
44
|
-
value: [
|
|
45
|
-
structured_query_1.Comparators.eq,
|
|
46
|
-
structured_query_1.Comparators.ne,
|
|
47
|
-
structured_query_1.Comparators.lt,
|
|
48
|
-
structured_query_1.Comparators.lte,
|
|
49
|
-
structured_query_1.Comparators.gt,
|
|
50
|
-
structured_query_1.Comparators.gte,
|
|
51
|
-
]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Formats the given function into a string representation. Throws an
|
|
56
|
-
* error if the function is not a known comparator or operator, or if it
|
|
57
|
-
* is not allowed.
|
|
58
|
-
* @param func The function to format, which can be an Operator or Comparator.
|
|
59
|
-
* @returns A string representation of the function.
|
|
60
|
-
*/
|
|
61
|
-
formatFunction(func) {
|
|
62
|
-
if (func in structured_query_1.Comparators) {
|
|
63
|
-
if (this.allowedComparators.length > 0 &&
|
|
64
|
-
this.allowedComparators.indexOf(func) === -1) {
|
|
65
|
-
throw new Error(`Comparator ${func} not allowed. Allowed operators: ${this.allowedComparators.join(", ")}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else if (func in structured_query_1.Operators) {
|
|
69
|
-
if (this.allowedOperators.length > 0 &&
|
|
70
|
-
this.allowedOperators.indexOf(func) === -1) {
|
|
71
|
-
throw new Error(`Operator ${func} not allowed. Allowed operators: ${this.allowedOperators.join(", ")}`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
throw new Error("Unknown comparator or operator");
|
|
76
|
-
}
|
|
77
|
-
const dict = {
|
|
78
|
-
and: "And",
|
|
79
|
-
or: "Or",
|
|
80
|
-
eq: "Equal",
|
|
81
|
-
ne: "NotEqual",
|
|
82
|
-
lt: "LessThan",
|
|
83
|
-
lte: "LessThanEqual",
|
|
84
|
-
gt: "GreaterThan",
|
|
85
|
-
gte: "GreaterThanEqual",
|
|
86
|
-
};
|
|
87
|
-
return dict[func];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Visits an operation and returns a WeaviateOperationResult. The
|
|
91
|
-
* operation's arguments are visited and the operator is formatted.
|
|
92
|
-
* @param operation The operation to visit.
|
|
93
|
-
* @returns A WeaviateOperationResult.
|
|
94
|
-
*/
|
|
95
|
-
visitOperation(operation) {
|
|
96
|
-
const args = operation.args?.map((arg) => arg.accept(this));
|
|
97
|
-
return {
|
|
98
|
-
operator: this.formatFunction(operation.operator),
|
|
99
|
-
operands: args,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Visits a comparison and returns a WeaviateComparisonResult. The
|
|
104
|
-
* comparison's value is checked for type and the comparator is formatted.
|
|
105
|
-
* Throws an error if the value type is not supported.
|
|
106
|
-
* @param comparison The comparison to visit.
|
|
107
|
-
* @returns A WeaviateComparisonResult.
|
|
108
|
-
*/
|
|
109
|
-
visitComparison(comparison) {
|
|
110
|
-
if ((0, structured_query_1.isString)(comparison.value)) {
|
|
111
|
-
return {
|
|
112
|
-
path: [comparison.attribute],
|
|
113
|
-
operator: this.formatFunction(comparison.comparator),
|
|
114
|
-
valueText: comparison.value,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
if ((0, structured_query_1.isInt)(comparison.value)) {
|
|
118
|
-
return {
|
|
119
|
-
path: [comparison.attribute],
|
|
120
|
-
operator: this.formatFunction(comparison.comparator),
|
|
121
|
-
valueInt: parseInt(comparison.value, 10),
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
if ((0, structured_query_1.isFloat)(comparison.value)) {
|
|
125
|
-
return {
|
|
126
|
-
path: [comparison.attribute],
|
|
127
|
-
operator: this.formatFunction(comparison.comparator),
|
|
128
|
-
valueNumber: parseFloat(comparison.value),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
throw new Error("Value type is not supported");
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Visits a structured query and returns a WeaviateStructuredQueryResult.
|
|
135
|
-
* If the query has a filter, it is visited.
|
|
136
|
-
* @param query The structured query to visit.
|
|
137
|
-
* @returns A WeaviateStructuredQueryResult.
|
|
138
|
-
*/
|
|
139
|
-
visitStructuredQuery(query) {
|
|
140
|
-
let nextArg = {};
|
|
141
|
-
if (query.filter) {
|
|
142
|
-
nextArg = {
|
|
143
|
-
filter: { where: query.filter.accept(this) },
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return nextArg;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Merges two filters into one. If both filters are empty, returns
|
|
150
|
-
* undefined. If one filter is empty or the merge type is 'replace',
|
|
151
|
-
* returns the other filter. If the merge type is 'and' or 'or', returns a
|
|
152
|
-
* new filter with the merged results. Throws an error for unknown merge
|
|
153
|
-
* types.
|
|
154
|
-
* @param defaultFilter The default filter to merge.
|
|
155
|
-
* @param generatedFilter The generated filter to merge.
|
|
156
|
-
* @param mergeType The type of merge to perform. Can be 'and', 'or', or 'replace'. Defaults to 'and'.
|
|
157
|
-
* @returns A merged WeaviateFilter, or undefined if both filters are empty.
|
|
158
|
-
*/
|
|
159
|
-
mergeFilters(defaultFilter, generatedFilter, mergeType = "and") {
|
|
160
|
-
if ((0, structured_query_1.isFilterEmpty)(defaultFilter?.where) &&
|
|
161
|
-
(0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
if ((0, structured_query_1.isFilterEmpty)(defaultFilter?.where) || mergeType === "replace") {
|
|
165
|
-
if ((0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
return generatedFilter;
|
|
169
|
-
}
|
|
170
|
-
if ((0, structured_query_1.isFilterEmpty)(generatedFilter?.where)) {
|
|
171
|
-
if (mergeType === "and") {
|
|
172
|
-
return undefined;
|
|
173
|
-
}
|
|
174
|
-
return defaultFilter;
|
|
175
|
-
}
|
|
176
|
-
const merged = {
|
|
177
|
-
operator: "And",
|
|
178
|
-
operands: [
|
|
179
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
180
|
-
defaultFilter.where,
|
|
181
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
182
|
-
generatedFilter.where,
|
|
183
|
-
],
|
|
184
|
-
};
|
|
185
|
-
if (mergeType === "and") {
|
|
186
|
-
return {
|
|
187
|
-
where: merged,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
else if (mergeType === "or") {
|
|
191
|
-
merged.operator = "Or";
|
|
192
|
-
return {
|
|
193
|
-
where: merged,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
throw new Error("Unknown merge type");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
exports.WeaviateTranslator = WeaviateTranslator;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { BaseTranslator, Comparator, Comparison, Operation, Operator, StructuredQuery } from "@langchain/core/structured_query";
|
|
2
|
-
import { VectorStore } from "@langchain/core/vectorstores";
|
|
3
|
-
type WeaviateOperatorValues = {
|
|
4
|
-
valueText: string;
|
|
5
|
-
valueInt: number;
|
|
6
|
-
valueNumber: number;
|
|
7
|
-
valueBoolean: boolean;
|
|
8
|
-
};
|
|
9
|
-
type WeaviateFilter = any;
|
|
10
|
-
type WeaviateOperatorKeys = keyof WeaviateOperatorValues;
|
|
11
|
-
type ExclusiveOperatorValue = {
|
|
12
|
-
[L in WeaviateOperatorKeys]: {
|
|
13
|
-
[key in L]: WeaviateOperatorValues[key];
|
|
14
|
-
} & Omit<{
|
|
15
|
-
[key in WeaviateOperatorKeys]?: never;
|
|
16
|
-
}, L>;
|
|
17
|
-
}[WeaviateOperatorKeys];
|
|
18
|
-
export type WeaviateVisitorResult = WeaviateOperationResult | WeaviateComparisonResult | WeaviateStructuredQueryResult;
|
|
19
|
-
export type WeaviateOperationResult = {
|
|
20
|
-
operator: string;
|
|
21
|
-
operands: WeaviateVisitorResult[];
|
|
22
|
-
};
|
|
23
|
-
export type WeaviateComparisonResult = {
|
|
24
|
-
path: [string];
|
|
25
|
-
operator: string;
|
|
26
|
-
} & ExclusiveOperatorValue;
|
|
27
|
-
export type WeaviateStructuredQueryResult = {
|
|
28
|
-
filter?: {
|
|
29
|
-
where?: WeaviateComparisonResult | WeaviateOperationResult;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* A class that translates or converts data into a format that can be used
|
|
34
|
-
* with Weaviate, a vector search engine. It extends the `BaseTranslator`
|
|
35
|
-
* class and provides specific implementation for Weaviate.
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const selfQueryRetriever = new SelfQueryRetriever({
|
|
39
|
-
* llm: new ChatOpenAI(),
|
|
40
|
-
* vectorStore: new WeaviateStore(),
|
|
41
|
-
* documentContents: "Brief summary of a movie",
|
|
42
|
-
* attributeInfo: [],
|
|
43
|
-
* structuredQueryTranslator: new WeaviateTranslator(),
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* const relevantDocuments = await selfQueryRetriever.getRelevantDocuments(
|
|
47
|
-
* "Which movies are rated higher than 8.5?",
|
|
48
|
-
* );
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare class WeaviateTranslator<T extends VectorStore> extends BaseTranslator<T> {
|
|
52
|
-
VisitOperationOutput: WeaviateOperationResult;
|
|
53
|
-
VisitComparisonOutput: WeaviateComparisonResult;
|
|
54
|
-
allowedOperators: Operator[];
|
|
55
|
-
allowedComparators: Comparator[];
|
|
56
|
-
/**
|
|
57
|
-
* Formats the given function into a string representation. Throws an
|
|
58
|
-
* error if the function is not a known comparator or operator, or if it
|
|
59
|
-
* is not allowed.
|
|
60
|
-
* @param func The function to format, which can be an Operator or Comparator.
|
|
61
|
-
* @returns A string representation of the function.
|
|
62
|
-
*/
|
|
63
|
-
formatFunction(func: Operator | Comparator): string;
|
|
64
|
-
/**
|
|
65
|
-
* Visits an operation and returns a WeaviateOperationResult. The
|
|
66
|
-
* operation's arguments are visited and the operator is formatted.
|
|
67
|
-
* @param operation The operation to visit.
|
|
68
|
-
* @returns A WeaviateOperationResult.
|
|
69
|
-
*/
|
|
70
|
-
visitOperation(operation: Operation): this["VisitOperationOutput"];
|
|
71
|
-
/**
|
|
72
|
-
* Visits a comparison and returns a WeaviateComparisonResult. The
|
|
73
|
-
* comparison's value is checked for type and the comparator is formatted.
|
|
74
|
-
* Throws an error if the value type is not supported.
|
|
75
|
-
* @param comparison The comparison to visit.
|
|
76
|
-
* @returns A WeaviateComparisonResult.
|
|
77
|
-
*/
|
|
78
|
-
visitComparison(comparison: Comparison): this["VisitComparisonOutput"];
|
|
79
|
-
/**
|
|
80
|
-
* Visits a structured query and returns a WeaviateStructuredQueryResult.
|
|
81
|
-
* If the query has a filter, it is visited.
|
|
82
|
-
* @param query The structured query to visit.
|
|
83
|
-
* @returns A WeaviateStructuredQueryResult.
|
|
84
|
-
*/
|
|
85
|
-
visitStructuredQuery(query: StructuredQuery): this["VisitStructuredQueryOutput"];
|
|
86
|
-
/**
|
|
87
|
-
* Merges two filters into one. If both filters are empty, returns
|
|
88
|
-
* undefined. If one filter is empty or the merge type is 'replace',
|
|
89
|
-
* returns the other filter. If the merge type is 'and' or 'or', returns a
|
|
90
|
-
* new filter with the merged results. Throws an error for unknown merge
|
|
91
|
-
* types.
|
|
92
|
-
* @param defaultFilter The default filter to merge.
|
|
93
|
-
* @param generatedFilter The generated filter to merge.
|
|
94
|
-
* @param mergeType The type of merge to perform. Can be 'and', 'or', or 'replace'. Defaults to 'and'.
|
|
95
|
-
* @returns A merged WeaviateFilter, or undefined if both filters are empty.
|
|
96
|
-
*/
|
|
97
|
-
mergeFilters(defaultFilter: WeaviateFilter | undefined, generatedFilter: WeaviateFilter | undefined, mergeType?: string): WeaviateFilter | undefined;
|
|
98
|
-
}
|
|
99
|
-
export {};
|