langchain 0.0.191 → 0.0.193

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.
Files changed (502) hide show
  1. package/cache/file_system.cjs +1 -0
  2. package/cache/file_system.d.ts +1 -0
  3. package/cache/file_system.js +1 -0
  4. package/dist/agents/agent.cjs +24 -0
  5. package/dist/agents/agent.d.ts +24 -0
  6. package/dist/agents/agent.js +24 -0
  7. package/dist/agents/chat/outputParser.cjs +32 -0
  8. package/dist/agents/chat/outputParser.d.ts +32 -0
  9. package/dist/agents/chat/outputParser.js +32 -0
  10. package/dist/agents/executor.cjs +14 -0
  11. package/dist/agents/executor.d.ts +14 -0
  12. package/dist/agents/executor.js +14 -0
  13. package/dist/agents/mrkl/index.cjs +21 -0
  14. package/dist/agents/mrkl/index.d.ts +21 -0
  15. package/dist/agents/mrkl/index.js +21 -0
  16. package/dist/agents/openai/output_parser.cjs +65 -0
  17. package/dist/agents/openai/output_parser.d.ts +65 -0
  18. package/dist/agents/openai/output_parser.js +65 -0
  19. package/dist/agents/react/output_parser.cjs +16 -0
  20. package/dist/agents/react/output_parser.d.ts +16 -0
  21. package/dist/agents/react/output_parser.js +16 -0
  22. package/dist/agents/structured_chat/outputParser.cjs +12 -0
  23. package/dist/agents/structured_chat/outputParser.d.ts +12 -0
  24. package/dist/agents/structured_chat/outputParser.js +12 -0
  25. package/dist/agents/toolkits/aws_sfn.cjs +20 -0
  26. package/dist/agents/toolkits/aws_sfn.d.ts +20 -0
  27. package/dist/agents/toolkits/aws_sfn.js +20 -0
  28. package/dist/agents/toolkits/json/json.cjs +8 -0
  29. package/dist/agents/toolkits/json/json.d.ts +8 -0
  30. package/dist/agents/toolkits/json/json.js +8 -0
  31. package/dist/agents/toolkits/openapi/openapi.cjs +18 -0
  32. package/dist/agents/toolkits/openapi/openapi.d.ts +18 -0
  33. package/dist/agents/toolkits/openapi/openapi.js +18 -0
  34. package/dist/agents/toolkits/sql/sql.cjs +8 -0
  35. package/dist/agents/toolkits/sql/sql.d.ts +8 -0
  36. package/dist/agents/toolkits/sql/sql.js +8 -0
  37. package/dist/agents/toolkits/vectorstore/vectorstore.cjs +16 -0
  38. package/dist/agents/toolkits/vectorstore/vectorstore.d.ts +16 -0
  39. package/dist/agents/toolkits/vectorstore/vectorstore.js +16 -0
  40. package/dist/agents/toolkits/zapier/zapier.cjs +10 -0
  41. package/dist/agents/toolkits/zapier/zapier.d.ts +10 -0
  42. package/dist/agents/toolkits/zapier/zapier.js +10 -0
  43. package/dist/agents/xml/output_parser.cjs +21 -0
  44. package/dist/agents/xml/output_parser.d.ts +21 -0
  45. package/dist/agents/xml/output_parser.js +21 -0
  46. package/dist/cache/cloudflare_kv.cjs +13 -0
  47. package/dist/cache/cloudflare_kv.d.ts +13 -0
  48. package/dist/cache/cloudflare_kv.js +13 -0
  49. package/dist/cache/file_system.cjs +73 -0
  50. package/dist/cache/file_system.d.ts +33 -0
  51. package/dist/cache/file_system.js +66 -0
  52. package/dist/cache/ioredis.cjs +13 -0
  53. package/dist/cache/ioredis.d.ts +13 -0
  54. package/dist/cache/ioredis.js +13 -0
  55. package/dist/cache/momento.cjs +19 -0
  56. package/dist/cache/momento.d.ts +19 -0
  57. package/dist/cache/momento.js +19 -0
  58. package/dist/cache/redis.cjs +10 -0
  59. package/dist/cache/redis.d.ts +10 -0
  60. package/dist/cache/redis.js +10 -0
  61. package/dist/cache/upstash_redis.cjs +15 -0
  62. package/dist/cache/upstash_redis.d.ts +15 -0
  63. package/dist/cache/upstash_redis.js +15 -0
  64. package/dist/callbacks/handlers/console.cjs +10 -0
  65. package/dist/callbacks/handlers/console.d.ts +10 -0
  66. package/dist/callbacks/handlers/console.js +10 -0
  67. package/dist/callbacks/manager.cjs +49 -0
  68. package/dist/callbacks/manager.d.ts +49 -0
  69. package/dist/callbacks/manager.js +49 -0
  70. package/dist/chains/analyze_documents_chain.cjs +18 -0
  71. package/dist/chains/analyze_documents_chain.d.ts +18 -0
  72. package/dist/chains/analyze_documents_chain.js +18 -0
  73. package/dist/chains/constitutional_ai/constitutional_chain.cjs +21 -0
  74. package/dist/chains/constitutional_ai/constitutional_chain.d.ts +21 -0
  75. package/dist/chains/constitutional_ai/constitutional_chain.js +21 -0
  76. package/dist/chains/constitutional_ai/constitutional_principle.cjs +21 -0
  77. package/dist/chains/constitutional_ai/constitutional_principle.d.ts +21 -0
  78. package/dist/chains/constitutional_ai/constitutional_principle.js +21 -0
  79. package/dist/chains/conversation.cjs +13 -0
  80. package/dist/chains/conversation.d.ts +13 -0
  81. package/dist/chains/conversation.js +13 -0
  82. package/dist/chains/conversational_retrieval_chain.cjs +29 -0
  83. package/dist/chains/conversational_retrieval_chain.d.ts +29 -0
  84. package/dist/chains/conversational_retrieval_chain.js +29 -0
  85. package/dist/chains/graph_qa/cypher.cjs +10 -0
  86. package/dist/chains/graph_qa/cypher.d.ts +10 -0
  87. package/dist/chains/graph_qa/cypher.js +10 -0
  88. package/dist/chains/openai_moderation.cjs +28 -0
  89. package/dist/chains/openai_moderation.d.ts +28 -0
  90. package/dist/chains/openai_moderation.js +28 -0
  91. package/dist/chains/retrieval_qa.cjs +21 -0
  92. package/dist/chains/retrieval_qa.d.ts +21 -0
  93. package/dist/chains/retrieval_qa.js +21 -0
  94. package/dist/chains/router/multi_prompt.cjs +19 -0
  95. package/dist/chains/router/multi_prompt.d.ts +19 -0
  96. package/dist/chains/router/multi_prompt.js +19 -0
  97. package/dist/chains/router/multi_retrieval_qa.cjs +29 -0
  98. package/dist/chains/router/multi_retrieval_qa.d.ts +29 -0
  99. package/dist/chains/router/multi_retrieval_qa.js +29 -0
  100. package/dist/chains/sequential_chain.cjs +43 -0
  101. package/dist/chains/sequential_chain.d.ts +43 -0
  102. package/dist/chains/sequential_chain.js +43 -0
  103. package/dist/chains/sql_db/sql_db_chain.cjs +9 -0
  104. package/dist/chains/sql_db/sql_db_chain.d.ts +9 -0
  105. package/dist/chains/sql_db/sql_db_chain.js +9 -0
  106. package/dist/chat_models/anthropic.cjs +9 -1
  107. package/dist/chat_models/anthropic.d.ts +9 -1
  108. package/dist/chat_models/anthropic.js +9 -1
  109. package/dist/chat_models/baiduwenxin.cjs +20 -0
  110. package/dist/chat_models/baiduwenxin.d.ts +20 -0
  111. package/dist/chat_models/baiduwenxin.js +20 -0
  112. package/dist/chat_models/base.cjs +2 -0
  113. package/dist/chat_models/base.d.ts +1 -1
  114. package/dist/chat_models/base.js +2 -0
  115. package/dist/chat_models/bedrock/index.cjs +11 -0
  116. package/dist/chat_models/bedrock/index.d.ts +11 -0
  117. package/dist/chat_models/bedrock/index.js +11 -0
  118. package/dist/chat_models/bedrock/web.cjs +10 -1
  119. package/dist/chat_models/bedrock/web.d.ts +9 -0
  120. package/dist/chat_models/bedrock/web.js +10 -1
  121. package/dist/chat_models/cloudflare_workersai.cjs +15 -0
  122. package/dist/chat_models/cloudflare_workersai.d.ts +15 -0
  123. package/dist/chat_models/cloudflare_workersai.js +15 -0
  124. package/dist/chat_models/fake.cjs +16 -0
  125. package/dist/chat_models/fake.d.ts +16 -0
  126. package/dist/chat_models/fake.js +16 -0
  127. package/dist/chat_models/fireworks.cjs +10 -0
  128. package/dist/chat_models/fireworks.d.ts +10 -0
  129. package/dist/chat_models/fireworks.js +10 -0
  130. package/dist/chat_models/googlepalm.cjs +24 -0
  131. package/dist/chat_models/googlepalm.d.ts +24 -0
  132. package/dist/chat_models/googlepalm.js +24 -0
  133. package/dist/chat_models/googlevertexai/index.cjs +7 -0
  134. package/dist/chat_models/googlevertexai/index.d.ts +7 -0
  135. package/dist/chat_models/googlevertexai/index.js +7 -0
  136. package/dist/chat_models/googlevertexai/web.cjs +9 -0
  137. package/dist/chat_models/googlevertexai/web.d.ts +9 -0
  138. package/dist/chat_models/googlevertexai/web.js +9 -0
  139. package/dist/chat_models/iflytek_xinghuo/index.cjs +8 -0
  140. package/dist/chat_models/iflytek_xinghuo/index.d.ts +8 -0
  141. package/dist/chat_models/iflytek_xinghuo/index.js +8 -0
  142. package/dist/chat_models/iflytek_xinghuo/web.cjs +8 -0
  143. package/dist/chat_models/iflytek_xinghuo/web.d.ts +8 -0
  144. package/dist/chat_models/iflytek_xinghuo/web.js +8 -0
  145. package/dist/chat_models/llama_cpp.cjs +17 -0
  146. package/dist/chat_models/llama_cpp.d.ts +17 -0
  147. package/dist/chat_models/llama_cpp.js +17 -0
  148. package/dist/chat_models/minimax.cjs +27 -0
  149. package/dist/chat_models/minimax.d.ts +27 -0
  150. package/dist/chat_models/minimax.js +27 -0
  151. package/dist/chat_models/ollama.cjs +24 -0
  152. package/dist/chat_models/ollama.d.ts +24 -0
  153. package/dist/chat_models/ollama.js +24 -0
  154. package/dist/chat_models/openai.cjs +15 -0
  155. package/dist/chat_models/openai.d.ts +15 -0
  156. package/dist/chat_models/openai.js +15 -0
  157. package/dist/chat_models/yandex.cjs +14 -0
  158. package/dist/chat_models/yandex.d.ts +14 -0
  159. package/dist/chat_models/yandex.js +14 -0
  160. package/dist/document_loaders/fs/directory.cjs +14 -0
  161. package/dist/document_loaders/fs/directory.d.ts +14 -0
  162. package/dist/document_loaders/fs/directory.js +14 -0
  163. package/dist/document_loaders/fs/openai_whisper_audio.cjs +10 -0
  164. package/dist/document_loaders/fs/openai_whisper_audio.d.ts +10 -0
  165. package/dist/document_loaders/fs/openai_whisper_audio.js +10 -0
  166. package/dist/document_loaders/fs/pdf.cjs +15 -2
  167. package/dist/document_loaders/fs/pdf.d.ts +9 -1
  168. package/dist/document_loaders/fs/pdf.js +15 -2
  169. package/dist/document_loaders/fs/srt.cjs +6 -0
  170. package/dist/document_loaders/fs/srt.d.ts +6 -0
  171. package/dist/document_loaders/fs/srt.js +6 -0
  172. package/dist/document_loaders/fs/text.cjs +5 -0
  173. package/dist/document_loaders/fs/text.d.ts +5 -0
  174. package/dist/document_loaders/fs/text.js +5 -0
  175. package/dist/document_loaders/fs/unstructured.cjs +7 -0
  176. package/dist/document_loaders/fs/unstructured.d.ts +7 -0
  177. package/dist/document_loaders/fs/unstructured.js +7 -0
  178. package/dist/document_loaders/web/apify_dataset.cjs +26 -2
  179. package/dist/document_loaders/web/apify_dataset.d.ts +25 -1
  180. package/dist/document_loaders/web/apify_dataset.js +26 -2
  181. package/dist/document_loaders/web/assemblyai.cjs +24 -0
  182. package/dist/document_loaders/web/assemblyai.d.ts +24 -0
  183. package/dist/document_loaders/web/assemblyai.js +24 -0
  184. package/dist/document_loaders/web/azure_blob_storage_file.cjs +11 -0
  185. package/dist/document_loaders/web/azure_blob_storage_file.d.ts +11 -0
  186. package/dist/document_loaders/web/azure_blob_storage_file.js +11 -0
  187. package/dist/document_loaders/web/cheerio.cjs +6 -0
  188. package/dist/document_loaders/web/cheerio.d.ts +6 -0
  189. package/dist/document_loaders/web/cheerio.js +6 -0
  190. package/dist/document_loaders/web/college_confidential.cjs +6 -0
  191. package/dist/document_loaders/web/college_confidential.d.ts +6 -0
  192. package/dist/document_loaders/web/college_confidential.js +6 -0
  193. package/dist/document_loaders/web/confluence.cjs +11 -0
  194. package/dist/document_loaders/web/confluence.d.ts +11 -0
  195. package/dist/document_loaders/web/confluence.js +11 -0
  196. package/dist/document_loaders/web/figma.cjs +9 -0
  197. package/dist/document_loaders/web/figma.d.ts +9 -0
  198. package/dist/document_loaders/web/figma.js +9 -0
  199. package/dist/document_loaders/web/notionapi.cjs +16 -0
  200. package/dist/document_loaders/web/notionapi.d.ts +16 -0
  201. package/dist/document_loaders/web/notionapi.js +16 -0
  202. package/dist/document_loaders/web/notiondb.cjs +11 -1
  203. package/dist/document_loaders/web/notiondb.d.ts +11 -1
  204. package/dist/document_loaders/web/notiondb.js +11 -1
  205. package/dist/document_loaders/web/pdf.cjs +15 -2
  206. package/dist/document_loaders/web/pdf.d.ts +9 -1
  207. package/dist/document_loaders/web/pdf.js +15 -2
  208. package/dist/document_loaders/web/puppeteer.cjs +12 -0
  209. package/dist/document_loaders/web/puppeteer.d.ts +12 -0
  210. package/dist/document_loaders/web/puppeteer.js +12 -0
  211. package/dist/document_loaders/web/s3.cjs +17 -0
  212. package/dist/document_loaders/web/s3.d.ts +17 -0
  213. package/dist/document_loaders/web/s3.js +17 -0
  214. package/dist/document_loaders/web/searchapi.cjs +9 -0
  215. package/dist/document_loaders/web/searchapi.d.ts +9 -0
  216. package/dist/document_loaders/web/searchapi.js +9 -0
  217. package/dist/document_loaders/web/serpapi.cjs +5 -0
  218. package/dist/document_loaders/web/serpapi.d.ts +5 -0
  219. package/dist/document_loaders/web/serpapi.js +5 -0
  220. package/dist/document_loaders/web/sonix_audio.cjs +12 -0
  221. package/dist/document_loaders/web/sonix_audio.d.ts +12 -0
  222. package/dist/document_loaders/web/sonix_audio.js +12 -0
  223. package/dist/document_loaders/web/sort_xyz_blockchain.cjs +22 -0
  224. package/dist/document_loaders/web/sort_xyz_blockchain.d.ts +22 -0
  225. package/dist/document_loaders/web/sort_xyz_blockchain.js +22 -0
  226. package/dist/document_loaders/web/youtube.cjs +9 -0
  227. package/dist/document_loaders/web/youtube.d.ts +9 -0
  228. package/dist/document_loaders/web/youtube.js +9 -0
  229. package/dist/document_transformers/html_to_text.cjs +18 -0
  230. package/dist/document_transformers/html_to_text.d.ts +18 -0
  231. package/dist/document_transformers/html_to_text.js +18 -0
  232. package/dist/document_transformers/mozilla_readability.cjs +18 -0
  233. package/dist/document_transformers/mozilla_readability.d.ts +18 -0
  234. package/dist/document_transformers/mozilla_readability.js +18 -0
  235. package/dist/embeddings/bedrock.cjs +17 -0
  236. package/dist/embeddings/bedrock.d.ts +17 -0
  237. package/dist/embeddings/bedrock.js +17 -0
  238. package/dist/embeddings/cache_backed.cjs +37 -0
  239. package/dist/embeddings/cache_backed.d.ts +37 -0
  240. package/dist/embeddings/cache_backed.js +37 -0
  241. package/dist/embeddings/cohere.cjs +10 -0
  242. package/dist/embeddings/cohere.d.ts +10 -0
  243. package/dist/embeddings/cohere.js +10 -0
  244. package/dist/embeddings/googlepalm.cjs +17 -0
  245. package/dist/embeddings/googlepalm.d.ts +17 -0
  246. package/dist/embeddings/googlepalm.js +17 -0
  247. package/dist/embeddings/googlevertexai.cjs +8 -0
  248. package/dist/embeddings/googlevertexai.d.ts +8 -0
  249. package/dist/embeddings/googlevertexai.js +8 -0
  250. package/dist/embeddings/hf_transformers.cjs +18 -0
  251. package/dist/embeddings/hf_transformers.d.ts +18 -0
  252. package/dist/embeddings/hf_transformers.js +18 -0
  253. package/dist/embeddings/llama_cpp.cjs +16 -0
  254. package/dist/embeddings/llama_cpp.d.ts +16 -0
  255. package/dist/embeddings/llama_cpp.js +16 -0
  256. package/dist/embeddings/minimax.cjs +15 -0
  257. package/dist/embeddings/minimax.d.ts +15 -0
  258. package/dist/embeddings/minimax.js +15 -0
  259. package/dist/embeddings/openai.cjs +10 -0
  260. package/dist/embeddings/openai.d.ts +10 -0
  261. package/dist/embeddings/openai.js +10 -0
  262. package/dist/embeddings/tensorflow.cjs +16 -0
  263. package/dist/embeddings/tensorflow.d.ts +16 -0
  264. package/dist/embeddings/tensorflow.js +16 -0
  265. package/dist/experimental/autogpt/agent.cjs +21 -0
  266. package/dist/experimental/autogpt/agent.d.ts +21 -0
  267. package/dist/experimental/autogpt/agent.js +21 -0
  268. package/dist/experimental/babyagi/agent.cjs +12 -0
  269. package/dist/experimental/babyagi/agent.d.ts +12 -0
  270. package/dist/experimental/babyagi/agent.js +12 -0
  271. package/dist/experimental/chat_models/ollama_functions.cjs +12 -15
  272. package/dist/experimental/chat_models/ollama_functions.d.ts +3 -4
  273. package/dist/experimental/chat_models/ollama_functions.js +13 -16
  274. package/dist/experimental/generative_agents/generative_agent.cjs +30 -0
  275. package/dist/experimental/generative_agents/generative_agent.d.ts +30 -0
  276. package/dist/experimental/generative_agents/generative_agent.js +30 -0
  277. package/dist/experimental/generative_agents/generative_agent_memory.cjs +18 -0
  278. package/dist/experimental/generative_agents/generative_agent_memory.d.ts +18 -0
  279. package/dist/experimental/generative_agents/generative_agent_memory.js +18 -0
  280. package/dist/llms/base.cjs +3 -1
  281. package/dist/llms/base.d.ts +1 -1
  282. package/dist/llms/base.js +3 -1
  283. package/dist/llms/bedrock/web.cjs +1 -1
  284. package/dist/llms/bedrock/web.js +1 -1
  285. package/dist/llms/cohere.cjs +13 -0
  286. package/dist/llms/cohere.d.ts +13 -0
  287. package/dist/llms/cohere.js +13 -0
  288. package/dist/llms/googlevertexai/index.cjs +12 -0
  289. package/dist/llms/googlevertexai/index.d.ts +12 -0
  290. package/dist/llms/googlevertexai/index.js +12 -0
  291. package/dist/llms/googlevertexai/web.cjs +12 -0
  292. package/dist/llms/googlevertexai/web.d.ts +12 -0
  293. package/dist/llms/googlevertexai/web.js +12 -0
  294. package/dist/llms/hf.cjs +13 -0
  295. package/dist/llms/hf.d.ts +13 -0
  296. package/dist/llms/hf.js +13 -0
  297. package/dist/llms/ollama.cjs +19 -0
  298. package/dist/llms/ollama.d.ts +19 -0
  299. package/dist/llms/ollama.js +19 -0
  300. package/dist/llms/openai-chat.cjs +17 -0
  301. package/dist/llms/openai-chat.d.ts +17 -0
  302. package/dist/llms/openai-chat.js +17 -0
  303. package/dist/llms/openai.cjs +14 -0
  304. package/dist/llms/openai.d.ts +14 -0
  305. package/dist/llms/openai.js +14 -0
  306. package/dist/llms/portkey.cjs +24 -0
  307. package/dist/llms/portkey.d.ts +24 -0
  308. package/dist/llms/portkey.js +24 -0
  309. package/dist/llms/replicate.cjs +11 -0
  310. package/dist/llms/replicate.d.ts +11 -0
  311. package/dist/llms/replicate.js +11 -0
  312. package/dist/load/import_constants.cjs +2 -0
  313. package/dist/load/import_constants.js +2 -0
  314. package/dist/memory/buffer_memory.cjs +24 -0
  315. package/dist/memory/buffer_memory.d.ts +24 -0
  316. package/dist/memory/buffer_memory.js +24 -0
  317. package/dist/memory/buffer_token_memory.cjs +15 -0
  318. package/dist/memory/buffer_token_memory.d.ts +15 -0
  319. package/dist/memory/buffer_token_memory.js +15 -0
  320. package/dist/memory/buffer_window_memory.cjs +23 -0
  321. package/dist/memory/buffer_window_memory.d.ts +23 -0
  322. package/dist/memory/buffer_window_memory.js +23 -0
  323. package/dist/memory/entity_memory.cjs +29 -0
  324. package/dist/memory/entity_memory.d.ts +29 -0
  325. package/dist/memory/entity_memory.js +29 -0
  326. package/dist/memory/summary.cjs +24 -0
  327. package/dist/memory/summary.d.ts +24 -0
  328. package/dist/memory/summary.js +24 -0
  329. package/dist/memory/summary_buffer.cjs +32 -0
  330. package/dist/memory/summary_buffer.d.ts +32 -0
  331. package/dist/memory/summary_buffer.js +32 -0
  332. package/dist/memory/vector_store.cjs +24 -0
  333. package/dist/memory/vector_store.d.ts +24 -0
  334. package/dist/memory/vector_store.js +24 -0
  335. package/dist/memory/zep.cjs +34 -0
  336. package/dist/memory/zep.d.ts +34 -0
  337. package/dist/memory/zep.js +34 -0
  338. package/dist/prompts/chat.cjs +31 -0
  339. package/dist/prompts/chat.d.ts +31 -0
  340. package/dist/prompts/chat.js +31 -0
  341. package/dist/prompts/few_shot.cjs +31 -0
  342. package/dist/prompts/few_shot.d.ts +31 -0
  343. package/dist/prompts/few_shot.js +31 -0
  344. package/dist/prompts/pipeline.cjs +39 -0
  345. package/dist/prompts/pipeline.d.ts +39 -0
  346. package/dist/prompts/pipeline.js +39 -0
  347. package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +36 -0
  348. package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +36 -0
  349. package/dist/prompts/selectors/LengthBasedExampleSelector.js +36 -0
  350. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +25 -0
  351. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +25 -0
  352. package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +25 -0
  353. package/dist/retrievers/amazon_kendra.cjs +16 -0
  354. package/dist/retrievers/amazon_kendra.d.ts +16 -0
  355. package/dist/retrievers/amazon_kendra.js +16 -0
  356. package/dist/retrievers/chaindesk.cjs +11 -0
  357. package/dist/retrievers/chaindesk.d.ts +11 -0
  358. package/dist/retrievers/chaindesk.js +11 -0
  359. package/dist/retrievers/contextual_compression.cjs +10 -0
  360. package/dist/retrievers/contextual_compression.d.ts +10 -0
  361. package/dist/retrievers/contextual_compression.js +10 -0
  362. package/dist/retrievers/document_compressors/embeddings_filter.cjs +13 -0
  363. package/dist/retrievers/document_compressors/embeddings_filter.d.ts +13 -0
  364. package/dist/retrievers/document_compressors/embeddings_filter.js +13 -0
  365. package/dist/retrievers/document_compressors/index.cjs +26 -0
  366. package/dist/retrievers/document_compressors/index.d.ts +26 -0
  367. package/dist/retrievers/document_compressors/index.js +26 -0
  368. package/dist/retrievers/hyde.cjs +19 -0
  369. package/dist/retrievers/hyde.d.ts +19 -0
  370. package/dist/retrievers/hyde.js +19 -0
  371. package/dist/retrievers/metal.cjs +11 -0
  372. package/dist/retrievers/metal.d.ts +11 -0
  373. package/dist/retrievers/metal.js +11 -0
  374. package/dist/retrievers/multi_query.cjs +13 -1
  375. package/dist/retrievers/multi_query.d.ts +13 -0
  376. package/dist/retrievers/multi_query.js +13 -1
  377. package/dist/retrievers/multi_vector.cjs +13 -0
  378. package/dist/retrievers/multi_vector.d.ts +13 -0
  379. package/dist/retrievers/multi_vector.js +13 -0
  380. package/dist/retrievers/parent_document.cjs +21 -0
  381. package/dist/retrievers/parent_document.d.ts +21 -0
  382. package/dist/retrievers/parent_document.js +21 -0
  383. package/dist/retrievers/remote/chatgpt-plugin.cjs +10 -0
  384. package/dist/retrievers/remote/chatgpt-plugin.d.ts +10 -0
  385. package/dist/retrievers/remote/chatgpt-plugin.js +10 -0
  386. package/dist/retrievers/self_query/chroma.cjs +15 -0
  387. package/dist/retrievers/self_query/chroma.d.ts +15 -0
  388. package/dist/retrievers/self_query/chroma.js +15 -0
  389. package/dist/retrievers/self_query/functional.cjs +7 -0
  390. package/dist/retrievers/self_query/functional.d.ts +7 -0
  391. package/dist/retrievers/self_query/functional.js +7 -0
  392. package/dist/retrievers/self_query/index.cjs +13 -0
  393. package/dist/retrievers/self_query/index.d.ts +13 -0
  394. package/dist/retrievers/self_query/index.js +13 -0
  395. package/dist/retrievers/self_query/pinecone.cjs +14 -0
  396. package/dist/retrievers/self_query/pinecone.d.ts +14 -0
  397. package/dist/retrievers/self_query/pinecone.js +14 -0
  398. package/dist/retrievers/self_query/supabase.cjs +14 -0
  399. package/dist/retrievers/self_query/supabase.d.ts +14 -0
  400. package/dist/retrievers/self_query/supabase.js +14 -0
  401. package/dist/retrievers/self_query/weaviate.cjs +14 -0
  402. package/dist/retrievers/self_query/weaviate.d.ts +14 -0
  403. package/dist/retrievers/self_query/weaviate.js +14 -0
  404. package/dist/retrievers/time_weighted.cjs +16 -0
  405. package/dist/retrievers/time_weighted.d.ts +16 -0
  406. package/dist/retrievers/time_weighted.js +16 -0
  407. package/dist/retrievers/vespa.cjs +15 -0
  408. package/dist/retrievers/vespa.d.ts +15 -0
  409. package/dist/retrievers/vespa.js +15 -0
  410. package/dist/retrievers/zep.cjs +10 -0
  411. package/dist/retrievers/zep.d.ts +10 -0
  412. package/dist/retrievers/zep.js +10 -0
  413. package/dist/schema/index.d.ts +8 -6
  414. package/dist/schema/output_parser.cjs +15 -0
  415. package/dist/schema/output_parser.d.ts +15 -0
  416. package/dist/schema/output_parser.js +15 -0
  417. package/dist/schema/runnable/base.cjs +20 -0
  418. package/dist/schema/runnable/base.d.ts +20 -0
  419. package/dist/schema/runnable/base.js +20 -0
  420. package/dist/schema/runnable/branch.cjs +28 -0
  421. package/dist/schema/runnable/branch.d.ts +28 -0
  422. package/dist/schema/runnable/branch.js +28 -0
  423. package/dist/storage/file_system.cjs +21 -0
  424. package/dist/storage/file_system.d.ts +21 -0
  425. package/dist/storage/file_system.js +21 -0
  426. package/dist/storage/in_memory.cjs +15 -0
  427. package/dist/storage/in_memory.d.ts +15 -0
  428. package/dist/storage/in_memory.js +15 -0
  429. package/dist/storage/ioredis.cjs +24 -0
  430. package/dist/storage/ioredis.d.ts +24 -0
  431. package/dist/storage/ioredis.js +24 -0
  432. package/dist/storage/upstash_redis.cjs +19 -0
  433. package/dist/storage/upstash_redis.d.ts +19 -0
  434. package/dist/storage/upstash_redis.js +19 -0
  435. package/dist/storage/vercel_kv.cjs +16 -0
  436. package/dist/storage/vercel_kv.d.ts +16 -0
  437. package/dist/storage/vercel_kv.js +16 -0
  438. package/dist/stores/message/cassandra.cjs +25 -0
  439. package/dist/stores/message/cassandra.d.ts +25 -0
  440. package/dist/stores/message/cassandra.js +25 -0
  441. package/dist/stores/message/cloudflare_d1.cjs +18 -0
  442. package/dist/stores/message/cloudflare_d1.d.ts +18 -0
  443. package/dist/stores/message/cloudflare_d1.js +18 -0
  444. package/dist/stores/message/firestore.cjs +19 -0
  445. package/dist/stores/message/firestore.d.ts +19 -0
  446. package/dist/stores/message/firestore.js +19 -0
  447. package/dist/stores/message/ioredis.cjs +18 -0
  448. package/dist/stores/message/ioredis.d.ts +18 -0
  449. package/dist/stores/message/ioredis.js +18 -0
  450. package/dist/stores/message/momento.cjs +18 -0
  451. package/dist/stores/message/momento.d.ts +18 -0
  452. package/dist/stores/message/momento.js +18 -0
  453. package/dist/stores/message/mongodb.cjs +11 -0
  454. package/dist/stores/message/mongodb.d.ts +11 -0
  455. package/dist/stores/message/mongodb.js +11 -0
  456. package/dist/stores/message/planetscale.cjs +18 -0
  457. package/dist/stores/message/planetscale.d.ts +18 -0
  458. package/dist/stores/message/planetscale.js +18 -0
  459. package/dist/stores/message/redis.cjs +18 -0
  460. package/dist/stores/message/redis.d.ts +18 -0
  461. package/dist/stores/message/redis.js +18 -0
  462. package/dist/stores/message/xata.cjs +23 -0
  463. package/dist/stores/message/xata.d.ts +23 -0
  464. package/dist/stores/message/xata.js +23 -0
  465. package/dist/tools/calculator.cjs +6 -0
  466. package/dist/tools/calculator.d.ts +6 -0
  467. package/dist/tools/calculator.js +6 -0
  468. package/dist/tools/google_calendar/create.cjs +22 -0
  469. package/dist/tools/google_calendar/create.d.ts +22 -0
  470. package/dist/tools/google_calendar/create.js +22 -0
  471. package/dist/tools/google_calendar/view.cjs +20 -0
  472. package/dist/tools/google_calendar/view.d.ts +20 -0
  473. package/dist/tools/google_calendar/view.js +20 -0
  474. package/dist/tools/searchapi.cjs +27 -0
  475. package/dist/tools/searchapi.d.ts +27 -0
  476. package/dist/tools/searchapi.js +27 -0
  477. package/dist/tools/searxng_search.cjs +20 -1
  478. package/dist/tools/searxng_search.d.ts +20 -1
  479. package/dist/tools/searxng_search.js +20 -1
  480. package/dist/tools/webbrowser.cjs +8 -0
  481. package/dist/tools/webbrowser.d.ts +8 -0
  482. package/dist/tools/webbrowser.js +8 -0
  483. package/dist/tools/wikipedia_query_run.cjs +8 -0
  484. package/dist/tools/wikipedia_query_run.d.ts +8 -0
  485. package/dist/tools/wikipedia_query_run.js +8 -0
  486. package/dist/tools/wolframalpha.cjs +9 -0
  487. package/dist/tools/wolframalpha.d.ts +9 -0
  488. package/dist/tools/wolframalpha.js +9 -0
  489. package/dist/util/googlevertexai-connection.cjs +3 -9
  490. package/dist/util/googlevertexai-connection.js +3 -9
  491. package/dist/vectorstores/opensearch.cjs +2 -1
  492. package/dist/vectorstores/opensearch.js +2 -1
  493. package/dist/vectorstores/prisma.cjs +20 -2
  494. package/dist/vectorstores/prisma.d.ts +4 -0
  495. package/dist/vectorstores/prisma.js +20 -2
  496. package/dist/vectorstores/rockset.cjs +353 -0
  497. package/dist/vectorstores/rockset.d.ts +202 -0
  498. package/dist/vectorstores/rockset.js +347 -0
  499. package/package.json +24 -5
  500. package/vectorstores/rockset.cjs +1 -0
  501. package/vectorstores/rockset.d.ts +1 -0
  502. package/vectorstores/rockset.js +1 -0
@@ -7,6 +7,10 @@ const IdColumnSymbol = Symbol("id");
7
7
  const ContentColumnSymbol = Symbol("content");
8
8
  const OpMap = {
9
9
  equals: "=",
10
+ in: "IN",
11
+ isNull: "IS NULL",
12
+ isNotNull: "IS NOT NULL",
13
+ like: "LIKE",
10
14
  lt: "<",
11
15
  lte: "<=",
12
16
  gt: ">",
@@ -236,9 +240,23 @@ class PrismaVectorStore extends base_js_1.VectorStore {
236
240
  return this.Prisma.join(Object.entries(filter).flatMap(([key, ops]) => Object.entries(ops).map(([opName, value]) => {
237
241
  // column name, operators cannot be parametrised
238
242
  // these fields are thus not escaped by Prisma and can be dangerous if user input is used
243
+ const opNameKey = opName;
239
244
  const colRaw = this.Prisma.raw(`"${key}"`);
240
- const opRaw = this.Prisma.raw(OpMap[opName]);
241
- return this.Prisma.sql `${colRaw} ${opRaw} ${value}`;
245
+ const opRaw = this.Prisma.raw(OpMap[opNameKey]);
246
+ switch (OpMap[opNameKey]) {
247
+ case OpMap.in: {
248
+ if (!Array.isArray(value) ||
249
+ !value.every((v) => typeof v === "string")) {
250
+ throw new Error(`Invalid filter: IN operator requires an array of strings. Received: ${JSON.stringify(value, null, 2)}`);
251
+ }
252
+ return this.Prisma.sql `${colRaw} ${opRaw} (${value.join(",")})`;
253
+ }
254
+ case OpMap.isNull:
255
+ case OpMap.isNotNull:
256
+ return this.Prisma.sql `${colRaw} ${opRaw}`;
257
+ default:
258
+ return this.Prisma.sql `${colRaw} ${opRaw} ${value}`;
259
+ }
242
260
  })), " AND ", " WHERE ");
243
261
  }
244
262
  /**
@@ -32,6 +32,10 @@ type ModelColumns<TModel extends Record<string, unknown>> = {
32
32
  export type PrismaSqlFilter<TModel extends Record<string, unknown>> = {
33
33
  [K in keyof TModel]?: {
34
34
  equals?: TModel[K];
35
+ in?: TModel[K][];
36
+ isNull?: TModel[K];
37
+ isNotNull?: TModel[K];
38
+ like?: TModel[K];
35
39
  lt?: TModel[K];
36
40
  lte?: TModel[K];
37
41
  gt?: TModel[K];
@@ -4,6 +4,10 @@ const IdColumnSymbol = Symbol("id");
4
4
  const ContentColumnSymbol = Symbol("content");
5
5
  const OpMap = {
6
6
  equals: "=",
7
+ in: "IN",
8
+ isNull: "IS NULL",
9
+ isNotNull: "IS NOT NULL",
10
+ like: "LIKE",
7
11
  lt: "<",
8
12
  lte: "<=",
9
13
  gt: ">",
@@ -233,9 +237,23 @@ class PrismaVectorStore extends VectorStore {
233
237
  return this.Prisma.join(Object.entries(filter).flatMap(([key, ops]) => Object.entries(ops).map(([opName, value]) => {
234
238
  // column name, operators cannot be parametrised
235
239
  // these fields are thus not escaped by Prisma and can be dangerous if user input is used
240
+ const opNameKey = opName;
236
241
  const colRaw = this.Prisma.raw(`"${key}"`);
237
- const opRaw = this.Prisma.raw(OpMap[opName]);
238
- return this.Prisma.sql `${colRaw} ${opRaw} ${value}`;
242
+ const opRaw = this.Prisma.raw(OpMap[opNameKey]);
243
+ switch (OpMap[opNameKey]) {
244
+ case OpMap.in: {
245
+ if (!Array.isArray(value) ||
246
+ !value.every((v) => typeof v === "string")) {
247
+ throw new Error(`Invalid filter: IN operator requires an array of strings. Received: ${JSON.stringify(value, null, 2)}`);
248
+ }
249
+ return this.Prisma.sql `${colRaw} ${opRaw} (${value.join(",")})`;
250
+ }
251
+ case OpMap.isNull:
252
+ case OpMap.isNotNull:
253
+ return this.Prisma.sql `${colRaw} ${opRaw}`;
254
+ default:
255
+ return this.Prisma.sql `${colRaw} ${opRaw} ${value}`;
256
+ }
239
257
  })), " AND ", " WHERE ");
240
258
  }
241
259
  /**
@@ -0,0 +1,353 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RocksetStore = exports.SimilarityMetric = exports.RocksetStoreDestroyedError = exports.RocksetStoreError = void 0;
4
+ const api_js_1 = require("@rockset/client/dist/codegen/api.js");
5
+ const base_js_1 = require("./base.cjs");
6
+ const document_js_1 = require("../document.cjs");
7
+ /**
8
+ * Generic Rockset vector storage error
9
+ */
10
+ class RocksetStoreError extends Error {
11
+ /**
12
+ * Constructs a RocksetStoreError
13
+ * @param message The error message
14
+ */
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = this.constructor.name;
18
+ }
19
+ }
20
+ exports.RocksetStoreError = RocksetStoreError;
21
+ /**
22
+ * Error that is thrown when a RocksetStore function is called
23
+ * after `destroy()` is called (meaning the collection would be
24
+ * deleted).
25
+ */
26
+ class RocksetStoreDestroyedError extends RocksetStoreError {
27
+ constructor() {
28
+ super("The Rockset store has been destroyed");
29
+ this.name = this.constructor.name;
30
+ }
31
+ }
32
+ exports.RocksetStoreDestroyedError = RocksetStoreDestroyedError;
33
+ /**
34
+ * Functions to measure vector distance/similarity by.
35
+ * See https://rockset.com/docs/vector-functions/#vector-distance-functions
36
+ * @enum SimilarityMetric
37
+ */
38
+ exports.SimilarityMetric = {
39
+ CosineSimilarity: "COSINE_SIM",
40
+ EuclideanDistance: "EUCLIDEAN_DIST",
41
+ DotProduct: "DOT_PRODUCT",
42
+ };
43
+ /**
44
+ * Exposes Rockset's vector store/search functionality
45
+ */
46
+ class RocksetStore extends base_js_1.VectorStore {
47
+ /**
48
+ * Gets a string representation of the type of this VectorStore
49
+ * @returns {"rockset"}
50
+ */
51
+ _vectorstoreType() {
52
+ return "rockset";
53
+ }
54
+ /**
55
+ * Constructs a new RocksetStore
56
+ * @param {Embeddings} embeddings Object used to embed queries and
57
+ * page content
58
+ * @param {RocksetLibArgs} args
59
+ */
60
+ constructor(embeddings, args) {
61
+ super(embeddings, args);
62
+ Object.defineProperty(this, "client", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ Object.defineProperty(this, "collectionName", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ Object.defineProperty(this, "workspaceName", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
80
+ Object.defineProperty(this, "textKey", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
86
+ Object.defineProperty(this, "embeddingKey", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ Object.defineProperty(this, "filter", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: void 0
97
+ });
98
+ Object.defineProperty(this, "_similarityMetric", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: void 0
103
+ });
104
+ Object.defineProperty(this, "similarityOrder", {
105
+ enumerable: true,
106
+ configurable: true,
107
+ writable: true,
108
+ value: void 0
109
+ });
110
+ Object.defineProperty(this, "destroyed", {
111
+ enumerable: true,
112
+ configurable: true,
113
+ writable: true,
114
+ value: void 0
115
+ });
116
+ this.embeddings = embeddings;
117
+ this.client = args.client;
118
+ this.collectionName = args.collectionName;
119
+ this.workspaceName = args.workspaceName ?? "commons";
120
+ this.textKey = args.textKey ?? "text";
121
+ this.embeddingKey = args.embeddingKey ?? "embedding";
122
+ this.filter = args.filter;
123
+ this.similarityMetric =
124
+ args.similarityMetric ?? exports.SimilarityMetric.CosineSimilarity;
125
+ this.setSimilarityOrder();
126
+ }
127
+ /**
128
+ * Sets the object's similarity order based on what
129
+ * SimilarityMetric is being used
130
+ */
131
+ setSimilarityOrder() {
132
+ this.checkIfDestroyed();
133
+ this.similarityOrder =
134
+ this.similarityMetric === exports.SimilarityMetric.EuclideanDistance
135
+ ? "ASC"
136
+ : "DESC";
137
+ }
138
+ /**
139
+ * Embeds and adds Documents to the store.
140
+ * @param {Documents[]} documents The documents to store
141
+ * @returns {Promise<string[]?>} The _id's of the documents added
142
+ */
143
+ async addDocuments(documents) {
144
+ const texts = documents.map(({ pageContent }) => pageContent);
145
+ return await this.addVectors(await this.embeddings.embedDocuments(texts), documents);
146
+ }
147
+ /**
148
+ * Adds vectors to the store given their corresponding Documents
149
+ * @param {number[][]} vectors The vectors to store
150
+ * @param {Document[]} documents The Documents they represent
151
+ * @return {Promise<string[]?>} The _id's of the added documents
152
+ */
153
+ async addVectors(vectors, documents) {
154
+ this.checkIfDestroyed();
155
+ const rocksetDocs = [];
156
+ for (let i = 0; i < documents.length; i += 1) {
157
+ const currDoc = documents[i];
158
+ const currVector = vectors[i];
159
+ rocksetDocs.push({
160
+ [this.textKey]: currDoc.pageContent,
161
+ [this.embeddingKey]: currVector,
162
+ ...currDoc.metadata,
163
+ });
164
+ }
165
+ return (await this.client.documents.addDocuments(this.workspaceName, this.collectionName, {
166
+ data: rocksetDocs,
167
+ })).data?.map((docStatus) => docStatus._id || "");
168
+ }
169
+ /**
170
+ * Deletes Rockset documements given their _id's
171
+ * @param {string[]} ids The IDS to remove documents with
172
+ */
173
+ async delete(ids) {
174
+ this.checkIfDestroyed();
175
+ await this.client.documents.deleteDocuments(this.workspaceName, this.collectionName, {
176
+ data: ids.map((id) => ({ _id: id })),
177
+ });
178
+ }
179
+ /**
180
+ * Gets the most relevant documents to a query along
181
+ * with their similarity score. The returned documents
182
+ * are ordered by similarity (most similar at the first
183
+ * index)
184
+ * @param {number[]} query The embedded query to search
185
+ * the store by
186
+ * @param {number} k The number of documents to retreive
187
+ * @param {string?} filter The SQL `WHERE` clause to filter by
188
+ */
189
+ async similaritySearchVectorWithScore(query, k, filter) {
190
+ this.checkIfDestroyed();
191
+ if (filter && this.filter) {
192
+ throw new RocksetStoreError("cannot provide both `filter` and `this.filter`");
193
+ }
194
+ const similarityKey = "similarity";
195
+ const _filter = filter ?? this.filter;
196
+ return ((await this.client.queries.query({
197
+ sql: {
198
+ query: `
199
+ SELECT
200
+ * EXCEPT("${this.embeddingKey}"),
201
+ "${this.textKey}",
202
+ ${this.similarityMetric}(:query, "${this.embeddingKey}") AS "${similarityKey}"
203
+ FROM
204
+ "${this.workspaceName}"."${this.collectionName}"
205
+ ${_filter ? `WHERE ${_filter}` : ""}
206
+ ORDER BY
207
+ "${similarityKey}" ${this.similarityOrder}
208
+ LIMIT
209
+ ${k}
210
+ `,
211
+ parameters: [
212
+ {
213
+ name: "query",
214
+ type: "",
215
+ value: `[${query.toString()}]`,
216
+ },
217
+ ],
218
+ },
219
+ })).results?.map((rocksetDoc) => [
220
+ new document_js_1.Document({
221
+ pageContent: rocksetDoc[this.textKey],
222
+ metadata: (({ [this.textKey]: t, [similarityKey]: s, ...rocksetDoc }) => rocksetDoc)(rocksetDoc),
223
+ }),
224
+ rocksetDoc[similarityKey],
225
+ ]) ?? []);
226
+ }
227
+ /**
228
+ * Constructs and returns a RocksetStore object given texts to store.
229
+ * @param {string[]} texts The texts to store
230
+ * @param {object[] | object} metadatas The metadatas that correspond
231
+ * to @param texts
232
+ * @param {Embeddings} embeddings The object used to embed queries
233
+ * and page content
234
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
235
+ * RocksetStore constructor
236
+ * @returns {RocksetStore}
237
+ */
238
+ static async fromTexts(texts, metadatas, embeddings, dbConfig) {
239
+ const docs = [];
240
+ for (let i = 0; i < texts.length; i += 1) {
241
+ const metadata = Array.isArray(metadatas) ? metadatas[i] : metadatas;
242
+ const newDoc = new document_js_1.Document({
243
+ pageContent: texts[i],
244
+ metadata,
245
+ });
246
+ docs.push(newDoc);
247
+ }
248
+ return RocksetStore.fromDocuments(docs, embeddings, dbConfig);
249
+ }
250
+ /**
251
+ * Constructs, adds docs to, and returns a RocksetStore object
252
+ * @param {Document[]} docs The Documents to store
253
+ * @param {Embeddings} embeddings The object used to embed queries
254
+ * and page content
255
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
256
+ * RocksetStore constructor
257
+ * @returns {RocksetStore}
258
+ */
259
+ static async fromDocuments(docs, embeddings, dbConfig) {
260
+ const args = { ...dbConfig, textKey: dbConfig.textKey ?? "text" };
261
+ const instance = new this(embeddings, args);
262
+ await instance.addDocuments(docs);
263
+ return instance;
264
+ }
265
+ /**
266
+ * Checks if a Rockset collection exists.
267
+ * @param {RocksetLibArgs} dbConfig The object containing the collection
268
+ * and workspace names
269
+ * @return {boolean} whether the collection exists
270
+ */
271
+ static async collectionExists(dbConfig) {
272
+ try {
273
+ await dbConfig.client.collections.getCollection(dbConfig.workspaceName ?? "commons", dbConfig.collectionName);
274
+ }
275
+ catch (err) {
276
+ if (err.message_key ===
277
+ "COLLECTION_DOES_NOT_EXIST") {
278
+ return false;
279
+ }
280
+ throw err;
281
+ }
282
+ return true;
283
+ }
284
+ /**
285
+ * Checks whether a Rockset collection is ready to be queried.
286
+ * @param {RocksetLibArgs} dbConfig The object containing the collection
287
+ * name and workspace
288
+ * @return {boolean} whether the collection is ready
289
+ */
290
+ static async collectionReady(dbConfig) {
291
+ return ((await dbConfig.client.collections.getCollection(dbConfig.workspaceName ?? "commons", dbConfig.collectionName)).data?.status === api_js_1.Collection.StatusEnum.READY);
292
+ }
293
+ /**
294
+ * Deletes the collection this RocksetStore uses
295
+ * @param {boolean?} waitUntilDeletion Whether to sleep until the
296
+ * collection is ready to be
297
+ * queried
298
+ */
299
+ async destroy(waitUntilDeletion) {
300
+ await this.client.collections.deleteCollection(this.workspaceName, this.collectionName);
301
+ this.destroyed = true;
302
+ if (waitUntilDeletion) {
303
+ while (await RocksetStore.collectionExists({
304
+ collectionName: this.collectionName,
305
+ client: this.client,
306
+ }))
307
+ ;
308
+ }
309
+ }
310
+ /**
311
+ * Checks if this RocksetStore has been destroyed.
312
+ * @throws {RocksetStoreDestroyederror} if it has.
313
+ */
314
+ checkIfDestroyed() {
315
+ if (this.destroyed) {
316
+ throw new RocksetStoreDestroyedError();
317
+ }
318
+ }
319
+ /**
320
+ * Creates a new Rockset collection and returns a RocksetStore that
321
+ * uses it
322
+ * @param {Embeddings} embeddings Object used to embed queries and
323
+ * page content
324
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
325
+ * RocksetStore constructor
326
+ * @param {CreateCollectionRequest?} collectionOptions The arguments to sent with the
327
+ * HTTP request when creating the
328
+ * collection. Setting a field mapping
329
+ * that `VECTOR_ENFORCE`s is recommended
330
+ * when using this function. See
331
+ * https://rockset.com/docs/vector-functions/#vector_enforce
332
+ * @returns {RocsketStore}
333
+ */
334
+ static async withNewCollection(embeddings, dbConfig, collectionOptions) {
335
+ if (collectionOptions?.name &&
336
+ dbConfig.collectionName !== collectionOptions?.name) {
337
+ throw new RocksetStoreError("`dbConfig.name` and `collectionOptions.name` do not match");
338
+ }
339
+ await dbConfig.client.collections.createCollection(dbConfig.workspaceName ?? "commons", collectionOptions || { name: dbConfig.collectionName });
340
+ while (!(await this.collectionExists(dbConfig)) ||
341
+ !(await this.collectionReady(dbConfig)))
342
+ ;
343
+ return new this(embeddings, dbConfig);
344
+ }
345
+ get similarityMetric() {
346
+ return this._similarityMetric;
347
+ }
348
+ set similarityMetric(metric) {
349
+ this._similarityMetric = metric;
350
+ this.setSimilarityOrder();
351
+ }
352
+ }
353
+ exports.RocksetStore = RocksetStore;
@@ -0,0 +1,202 @@
1
+ import { MainApi } from "@rockset/client";
2
+ import type { CreateCollectionRequest } from "@rockset/client/dist/codegen/api.d.ts";
3
+ import { VectorStore } from "./base.js";
4
+ import { Embeddings } from "../embeddings/base.js";
5
+ import { Document } from "../document.js";
6
+ /**
7
+ * Generic Rockset vector storage error
8
+ */
9
+ export declare class RocksetStoreError extends Error {
10
+ /**
11
+ * Constructs a RocksetStoreError
12
+ * @param message The error message
13
+ */
14
+ constructor(message: string);
15
+ }
16
+ /**
17
+ * Error that is thrown when a RocksetStore function is called
18
+ * after `destroy()` is called (meaning the collection would be
19
+ * deleted).
20
+ */
21
+ export declare class RocksetStoreDestroyedError extends RocksetStoreError {
22
+ constructor();
23
+ }
24
+ /**
25
+ * Functions to measure vector distance/similarity by.
26
+ * See https://rockset.com/docs/vector-functions/#vector-distance-functions
27
+ * @enum SimilarityMetric
28
+ */
29
+ export declare const SimilarityMetric: {
30
+ readonly CosineSimilarity: "COSINE_SIM";
31
+ readonly EuclideanDistance: "EUCLIDEAN_DIST";
32
+ readonly DotProduct: "DOT_PRODUCT";
33
+ };
34
+ export type SimilarityMetric = (typeof SimilarityMetric)[keyof typeof SimilarityMetric];
35
+ /**
36
+ * Vector store arguments
37
+ * @interface RocksetStore
38
+ */
39
+ export interface RocksetLibArgs {
40
+ /**
41
+ * The rockset client object constructed with `rocksetConfigure`
42
+ * @type {MainAPI}
43
+ */
44
+ client: MainApi;
45
+ /**
46
+ * The name of the Rockset collection to store vectors
47
+ * @type {string}
48
+ */
49
+ collectionName: string;
50
+ /**
51
+ * The name of othe Rockset workspace that holds @member collectionName
52
+ * @type {string}
53
+ */
54
+ workspaceName?: string;
55
+ /**
56
+ * The name of the collection column to contain page contnent of documents
57
+ * @type {string}
58
+ */
59
+ textKey?: string;
60
+ /**
61
+ * The name of the collection column to contain vectors
62
+ * @type {string}
63
+ */
64
+ embeddingKey?: string;
65
+ /**
66
+ * The SQL `WHERE` clause to filter by
67
+ * @type {string}
68
+ */
69
+ filter?: string;
70
+ /**
71
+ * The metric used to measure vector relationship
72
+ * @type {SimilarityMetric}
73
+ */
74
+ similarityMetric?: SimilarityMetric;
75
+ }
76
+ /**
77
+ * Exposes Rockset's vector store/search functionality
78
+ */
79
+ export declare class RocksetStore extends VectorStore {
80
+ FilterType: string;
81
+ client: MainApi;
82
+ collectionName: string;
83
+ workspaceName: string;
84
+ textKey: string;
85
+ embeddingKey: string;
86
+ filter?: string;
87
+ private _similarityMetric;
88
+ private similarityOrder;
89
+ private destroyed;
90
+ /**
91
+ * Gets a string representation of the type of this VectorStore
92
+ * @returns {"rockset"}
93
+ */
94
+ _vectorstoreType(): "rockset";
95
+ /**
96
+ * Constructs a new RocksetStore
97
+ * @param {Embeddings} embeddings Object used to embed queries and
98
+ * page content
99
+ * @param {RocksetLibArgs} args
100
+ */
101
+ constructor(embeddings: Embeddings, args: RocksetLibArgs);
102
+ /**
103
+ * Sets the object's similarity order based on what
104
+ * SimilarityMetric is being used
105
+ */
106
+ private setSimilarityOrder;
107
+ /**
108
+ * Embeds and adds Documents to the store.
109
+ * @param {Documents[]} documents The documents to store
110
+ * @returns {Promise<string[]?>} The _id's of the documents added
111
+ */
112
+ addDocuments(documents: Document[]): Promise<string[] | undefined>;
113
+ /**
114
+ * Adds vectors to the store given their corresponding Documents
115
+ * @param {number[][]} vectors The vectors to store
116
+ * @param {Document[]} documents The Documents they represent
117
+ * @return {Promise<string[]?>} The _id's of the added documents
118
+ */
119
+ addVectors(vectors: number[][], documents: Document[]): Promise<string[] | undefined>;
120
+ /**
121
+ * Deletes Rockset documements given their _id's
122
+ * @param {string[]} ids The IDS to remove documents with
123
+ */
124
+ delete(ids: string[]): Promise<void>;
125
+ /**
126
+ * Gets the most relevant documents to a query along
127
+ * with their similarity score. The returned documents
128
+ * are ordered by similarity (most similar at the first
129
+ * index)
130
+ * @param {number[]} query The embedded query to search
131
+ * the store by
132
+ * @param {number} k The number of documents to retreive
133
+ * @param {string?} filter The SQL `WHERE` clause to filter by
134
+ */
135
+ similaritySearchVectorWithScore(query: number[], k: number, filter?: string): Promise<[Document, number][]>;
136
+ /**
137
+ * Constructs and returns a RocksetStore object given texts to store.
138
+ * @param {string[]} texts The texts to store
139
+ * @param {object[] | object} metadatas The metadatas that correspond
140
+ * to @param texts
141
+ * @param {Embeddings} embeddings The object used to embed queries
142
+ * and page content
143
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
144
+ * RocksetStore constructor
145
+ * @returns {RocksetStore}
146
+ */
147
+ static fromTexts(texts: string[], metadatas: object[] | object, embeddings: Embeddings, dbConfig: RocksetLibArgs): Promise<RocksetStore>;
148
+ /**
149
+ * Constructs, adds docs to, and returns a RocksetStore object
150
+ * @param {Document[]} docs The Documents to store
151
+ * @param {Embeddings} embeddings The object used to embed queries
152
+ * and page content
153
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
154
+ * RocksetStore constructor
155
+ * @returns {RocksetStore}
156
+ */
157
+ static fromDocuments(docs: Document[], embeddings: Embeddings, dbConfig: RocksetLibArgs): Promise<RocksetStore>;
158
+ /**
159
+ * Checks if a Rockset collection exists.
160
+ * @param {RocksetLibArgs} dbConfig The object containing the collection
161
+ * and workspace names
162
+ * @return {boolean} whether the collection exists
163
+ */
164
+ private static collectionExists;
165
+ /**
166
+ * Checks whether a Rockset collection is ready to be queried.
167
+ * @param {RocksetLibArgs} dbConfig The object containing the collection
168
+ * name and workspace
169
+ * @return {boolean} whether the collection is ready
170
+ */
171
+ private static collectionReady;
172
+ /**
173
+ * Deletes the collection this RocksetStore uses
174
+ * @param {boolean?} waitUntilDeletion Whether to sleep until the
175
+ * collection is ready to be
176
+ * queried
177
+ */
178
+ destroy(waitUntilDeletion?: boolean): Promise<void>;
179
+ /**
180
+ * Checks if this RocksetStore has been destroyed.
181
+ * @throws {RocksetStoreDestroyederror} if it has.
182
+ */
183
+ private checkIfDestroyed;
184
+ /**
185
+ * Creates a new Rockset collection and returns a RocksetStore that
186
+ * uses it
187
+ * @param {Embeddings} embeddings Object used to embed queries and
188
+ * page content
189
+ * @param {RocksetLibArgs} dbConfig The options to be passed into the
190
+ * RocksetStore constructor
191
+ * @param {CreateCollectionRequest?} collectionOptions The arguments to sent with the
192
+ * HTTP request when creating the
193
+ * collection. Setting a field mapping
194
+ * that `VECTOR_ENFORCE`s is recommended
195
+ * when using this function. See
196
+ * https://rockset.com/docs/vector-functions/#vector_enforce
197
+ * @returns {RocsketStore}
198
+ */
199
+ static withNewCollection(embeddings: Embeddings, dbConfig: RocksetLibArgs, collectionOptions?: CreateCollectionRequest): Promise<RocksetStore>;
200
+ get similarityMetric(): SimilarityMetric;
201
+ set similarityMetric(metric: SimilarityMetric);
202
+ }