langchain 0.2.17 → 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/executor.cjs +11 -0
- package/dist/agents/executor.d.ts +2 -0
- package/dist/agents/executor.js +11 -0
- package/dist/agents/openai_functions/index.cjs +2 -2
- package/dist/agents/openai_functions/index.js +2 -2
- package/dist/agents/react/output_parser.cjs +3 -2
- package/dist/agents/react/output_parser.js +3 -2
- package/dist/chains/combine_documents/stuff.cjs +2 -2
- package/dist/chains/combine_documents/stuff.js +2 -2
- package/dist/chains/conversational_retrieval_chain.cjs +1 -1
- package/dist/chains/conversational_retrieval_chain.d.ts +1 -1
- package/dist/chains/conversational_retrieval_chain.js +1 -1
- package/dist/chains/llm_chain.cjs +1 -1
- package/dist/chains/llm_chain.d.ts +1 -1
- package/dist/chains/llm_chain.js +1 -1
- package/dist/chains/openai_functions/openapi.cjs +3 -1
- package/dist/chains/openai_functions/openapi.js +3 -1
- package/dist/chains/retrieval_qa.cjs +1 -1
- package/dist/chains/retrieval_qa.d.ts +1 -1
- package/dist/chains/retrieval_qa.js +1 -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 +35 -858
- 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/chrome_ai/app/dist/bundle.cjs +0 -1250
- package/dist/experimental/chrome_ai/app/dist/bundle.d.ts +0 -1
- package/dist/experimental/chrome_ai/app/dist/bundle.js +0 -1249
- 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,259 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import { Comparators, Comparison, Operation, Operators, StructuredQuery, } from "@langchain/core/structured_query";
|
|
3
|
-
/**
|
|
4
|
-
* Utility class used to duplicate parameters for a proxy object,
|
|
5
|
-
* specifically designed to work with `SupabaseFilter` objects. It
|
|
6
|
-
* contains methods to handle different types of operations such as "or",
|
|
7
|
-
* "filter", "in", "contains", "textSearch", "match", "not", and default
|
|
8
|
-
* operations.
|
|
9
|
-
*/
|
|
10
|
-
export class ProxyParamsDuplicator {
|
|
11
|
-
constructor() {
|
|
12
|
-
Object.defineProperty(this, "duplicationAllowedOps", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: [
|
|
17
|
-
"eq",
|
|
18
|
-
"neq",
|
|
19
|
-
"lt",
|
|
20
|
-
"lte",
|
|
21
|
-
"gt",
|
|
22
|
-
"gte",
|
|
23
|
-
"like",
|
|
24
|
-
"ilike",
|
|
25
|
-
"or",
|
|
26
|
-
"in",
|
|
27
|
-
"contains",
|
|
28
|
-
"match",
|
|
29
|
-
"not",
|
|
30
|
-
"textSearch",
|
|
31
|
-
"filter",
|
|
32
|
-
]
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(this, "values", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
configurable: true,
|
|
37
|
-
writable: true,
|
|
38
|
-
value: []
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Creates a proxy handler for a `SupabaseFilter` object. The handler
|
|
43
|
-
* intercepts get operations and applies specific logic based on the
|
|
44
|
-
* property being accessed.
|
|
45
|
-
* @returns A proxy handler for a `SupabaseFilter` object.
|
|
46
|
-
*/
|
|
47
|
-
buildProxyHandler() {
|
|
48
|
-
const proxyHandler = {
|
|
49
|
-
get: (target, prop, receiver) => {
|
|
50
|
-
if (typeof target[prop] === "function") {
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
-
return (...args) => {
|
|
53
|
-
if (this.duplicationAllowedOps.includes(String(prop))) {
|
|
54
|
-
switch (String(prop)) {
|
|
55
|
-
case "or":
|
|
56
|
-
// args[0]: filters, args[1]: { foreignTable }
|
|
57
|
-
this.addOrClause(args[0], args[1]);
|
|
58
|
-
break;
|
|
59
|
-
case "filter":
|
|
60
|
-
// args[0]: column, args[1]: operator, args[2]: value
|
|
61
|
-
this.addFilterClause(args[0], args[1], args[2]);
|
|
62
|
-
break;
|
|
63
|
-
case "in":
|
|
64
|
-
// args[0]: column, args[1]: values
|
|
65
|
-
this.addInClause(args[0], args[1]);
|
|
66
|
-
break;
|
|
67
|
-
case "contains":
|
|
68
|
-
// args[0]: column, args[1]: value
|
|
69
|
-
this.addContainsClause(args[0], args[1]);
|
|
70
|
-
break;
|
|
71
|
-
case "textSearch":
|
|
72
|
-
// args[0]: column, args[1]: query, args[2]: { config, type }
|
|
73
|
-
this.addTextSearchClause(args[0], args[1], args[2]);
|
|
74
|
-
break;
|
|
75
|
-
case "match":
|
|
76
|
-
// args[0]: query
|
|
77
|
-
this.addMatchClause(args[0]);
|
|
78
|
-
break;
|
|
79
|
-
case "not":
|
|
80
|
-
// args[0]: column, args[1]: operator, args[2]: value
|
|
81
|
-
this.addNotClause(args[0], args[1], args[2]);
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
// args[0]: column, args[1]: value
|
|
85
|
-
this.addDefaultOpClause(prop, args[0], args[1]);
|
|
86
|
-
}
|
|
87
|
-
return new Proxy(target, proxyHandler);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error("Filter operation not supported for 'or' mergeFiltersOperator");
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return Reflect.get(target, prop, receiver);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
return proxyHandler;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Removes type annotations from a value string.
|
|
103
|
-
* @param value The value string to clean.
|
|
104
|
-
* @returns The cleaned value string.
|
|
105
|
-
*/
|
|
106
|
-
removeType(value) {
|
|
107
|
-
let cleanedValue = value;
|
|
108
|
-
if (cleanedValue.includes("::float")) {
|
|
109
|
-
cleanedValue = cleanedValue.replace("::float", "");
|
|
110
|
-
}
|
|
111
|
-
if (cleanedValue.includes("::int")) {
|
|
112
|
-
cleanedValue = cleanedValue.replace("::int", "");
|
|
113
|
-
}
|
|
114
|
-
return cleanedValue;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Adds a default operation clause to the values array.
|
|
118
|
-
* @param prop The operation property.
|
|
119
|
-
* @param column The column to apply the operation to.
|
|
120
|
-
* @param value The value for the operation.
|
|
121
|
-
*/
|
|
122
|
-
addDefaultOpClause(prop, column, value) {
|
|
123
|
-
this.values.push([this.removeType(column), `${String(prop)}.${value}`]);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Adds an 'or' clause to the values array.
|
|
127
|
-
* @param filters The filters for the 'or' clause.
|
|
128
|
-
* @param foreignTable Optional foreign table for the 'or' clause.
|
|
129
|
-
*/
|
|
130
|
-
addOrClause(filters, { foreignTable } = {}) {
|
|
131
|
-
const key = foreignTable ? `${foreignTable}.or` : "or";
|
|
132
|
-
this.values.push([this.removeType(key), `(${filters})`]);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Adds a 'filter' clause to the values array.
|
|
136
|
-
* @param column The column to apply the filter to.
|
|
137
|
-
* @param operator The operator for the filter.
|
|
138
|
-
* @param value The value for the filter.
|
|
139
|
-
*/
|
|
140
|
-
addFilterClause(column, operator, value) {
|
|
141
|
-
this.values.push([this.removeType(column), `${operator}.${value}`]);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Adds an 'in' clause to the values array.
|
|
145
|
-
* @param column The column to apply the 'in' clause to.
|
|
146
|
-
* @param values The values for the 'in' clause.
|
|
147
|
-
*/
|
|
148
|
-
addInClause(column, values) {
|
|
149
|
-
const cleanedValues = values
|
|
150
|
-
.map((s) => {
|
|
151
|
-
if (typeof s === "string" && /[,()]/.test(s))
|
|
152
|
-
return `"${s}"`;
|
|
153
|
-
else
|
|
154
|
-
return `${s}`;
|
|
155
|
-
})
|
|
156
|
-
.join(",");
|
|
157
|
-
this.values.push([this.removeType(column), `in.(${cleanedValues})`]);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Adds a 'contains' clause to the values array.
|
|
161
|
-
* @param column The column to apply the 'contains' clause to.
|
|
162
|
-
* @param value The value for the 'contains' clause.
|
|
163
|
-
*/
|
|
164
|
-
addContainsClause(column, value) {
|
|
165
|
-
if (typeof value === "string") {
|
|
166
|
-
this.values.push([this.removeType(column), `cs.${value}`]);
|
|
167
|
-
}
|
|
168
|
-
else if (Array.isArray(value)) {
|
|
169
|
-
this.values.push([this.removeType(column), `cs.{${value.join(",")}}`]);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
this.values.push([
|
|
173
|
-
this.removeType(column),
|
|
174
|
-
`cs.${JSON.stringify(value)}`,
|
|
175
|
-
]);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Adds a 'textSearch' clause to the values array.
|
|
180
|
-
* @param column The column to apply the 'textSearch' clause to.
|
|
181
|
-
* @param query The query for the 'textSearch' clause.
|
|
182
|
-
* @param config Optional configuration for the 'textSearch' clause.
|
|
183
|
-
* @param type Optional type for the 'textSearch' clause.
|
|
184
|
-
*/
|
|
185
|
-
addTextSearchClause(column, query, { config, type, } = {}) {
|
|
186
|
-
let typePart = "";
|
|
187
|
-
if (type === "plain") {
|
|
188
|
-
typePart = "pl";
|
|
189
|
-
}
|
|
190
|
-
else if (type === "phrase") {
|
|
191
|
-
typePart = "ph";
|
|
192
|
-
}
|
|
193
|
-
else if (type === "websearch") {
|
|
194
|
-
typePart = "w";
|
|
195
|
-
}
|
|
196
|
-
const configPart = config === undefined ? "" : `(${config})`;
|
|
197
|
-
this.values.push([
|
|
198
|
-
this.removeType(column),
|
|
199
|
-
`${typePart}fts${configPart}.${query}`,
|
|
200
|
-
]);
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Adds a 'not' clause to the values array.
|
|
204
|
-
* @param column The column to apply the 'not' clause to.
|
|
205
|
-
* @param operator The operator for the 'not' clause.
|
|
206
|
-
* @param value The value for the 'not' clause.
|
|
207
|
-
*/
|
|
208
|
-
addNotClause(column, operator, value) {
|
|
209
|
-
this.values.push([column, `not.${operator}.${value}`]);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Adds a 'match' clause to the values array.
|
|
213
|
-
* @param query The query for the 'match' clause.
|
|
214
|
-
*/
|
|
215
|
-
addMatchClause(query) {
|
|
216
|
-
Object.entries(query).forEach(([column, value]) => {
|
|
217
|
-
this.values.push([column, `eq.${value}`]);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Returns the flattened parameters as a string.
|
|
222
|
-
* @returns The flattened parameters as a string.
|
|
223
|
-
*/
|
|
224
|
-
flattenedParams() {
|
|
225
|
-
const mapped = this.values.map(([k, v]) => `${k}.${v}`);
|
|
226
|
-
if (mapped.length === 1)
|
|
227
|
-
return mapped[0];
|
|
228
|
-
return `and(${mapped.join(",")})`;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Gets flattened parameters from a `SupabaseFilter` and a
|
|
232
|
-
* `SupabaseFilterRPCCall`.
|
|
233
|
-
* @param rpc The `SupabaseFilter` object.
|
|
234
|
-
* @param filter The `SupabaseFilterRPCCall` object.
|
|
235
|
-
* @returns The flattened parameters as a string.
|
|
236
|
-
*/
|
|
237
|
-
static getFlattenedParams(
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
239
|
-
rpc,
|
|
240
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
241
|
-
filter) {
|
|
242
|
-
const proxiedDuplicator = new ProxyParamsDuplicator();
|
|
243
|
-
const proxiedRpc = new Proxy(rpc, proxiedDuplicator.buildProxyHandler());
|
|
244
|
-
void filter(proxiedRpc);
|
|
245
|
-
return proxiedDuplicator.flattenedParams();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Converts a `SupabaseMetadata` object into a `StructuredQuery` object.
|
|
250
|
-
* The function creates a new `StructuredQuery` object and uses the
|
|
251
|
-
* `Operation` and `Comparison` classes to build the query.
|
|
252
|
-
*/
|
|
253
|
-
export function convertObjectFilterToStructuredQuery(
|
|
254
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
255
|
-
objFilter) {
|
|
256
|
-
return new StructuredQuery("", new Operation(Operators.and, Object.entries(objFilter).map(
|
|
257
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
-
([column, value]) => new Comparison(Comparators.eq, column, value))));
|
|
259
|
-
}
|
|
@@ -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
|
-
}
|