diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.And.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.And.ts new file mode 100644 index 0000000..312184b --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.And.ts @@ -0,0 +1,40 @@ +/** + * Basic example to demonstrate how to retrieve memories with filters. + * + * - And: This filter is used to retrieve memories that match all the filters. + * - Eq: This filter is used to retrieve memories that match the exact value. + * + * In this example, we retrieve memories with the following filters: + * - company: Langbase + * - category: docs + * + * We expect to get all chunks of memory from the Langbase Docs memory that have the company Langbase and the category docs. + * + */ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: ["And", [ + ["company", "Eq", "Langbase"], + ["category", "Eq", "docs"] + ]] + }, + ], + query: "What are pipes in Langbase Docs?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.Eq.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.Eq.ts new file mode 100644 index 0000000..94afd18 --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.Eq.ts @@ -0,0 +1,35 @@ +/** + * Basic example to demonstrate how to retrieve memories with filters. + * + * - Eq: This filter is used to retrieve memories that match the exact value. + * + * In this example, we retrieve memories with the following filters: + * - company: Langbase + * + * We expect to get all chunks of memory from the Langbase Docs memory that have the company Langbase. + * + */ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: ["company", "Eq", "Langbase"], + }, + ], + query: "What is Langbase?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.In.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.In.ts new file mode 100644 index 0000000..58e2114 --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.In.ts @@ -0,0 +1,35 @@ +/** + * Basic example to demonstrate how to retrieve memories with filters. + * + * - In: This filter is used to retrieve memories that match any of the value/values in the array. + * + * In this example, we retrieve memories with the following filters: + * - company: Langbase or Google + * + * We expect to get all chunks of memory from the Langbase Docs memory that have the company Langbase or Google. + * + */ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: ["company", "In", ["Langbase","Google"]], + }, + ], + query: "What are pipes in Langbase?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.NotEq.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.NotEq.ts new file mode 100644 index 0000000..c98c476 --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.NotEq.ts @@ -0,0 +1,35 @@ +/** + * Basic example to demonstrate how to retrieve memories with filters. + * + * - NotEq: This filter is used to retrieve memories that do not match the exact value. + * + * In this example, we retrieve memories with the following filters: + * - company: Langbase + * + * We expect to get all chunks of memory from the Langbase Docs memory that do not have the company Langbase. + * + */ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: ["company", "NotEq", "Google"], + }, + ], + query: "What is Langbase?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.NotIn.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.NotIn.ts new file mode 100644 index 0000000..85e3703 --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.NotIn.ts @@ -0,0 +1,35 @@ +/** + * Basic example to demonstrate how to retrieve memories with filters. + * + * - NotIn: This filter is used to retrieve memories that do not match any of the value/values in the array. + * + * In this example, we retrieve memories with the following filters: + * - company: Google + * + * We expect to get all chunks of memory from the Langbase Docs memory that do not have the company Google. + * + */ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: ["company", "NotIn", "Google"], + }, + ], + query: "What are pipes in Langbase?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/examples/memory/memory.retrieve.filters.advanced.ts b/examples/nodejs/examples/memory/memory.retrieve.filters.advanced.ts new file mode 100644 index 0000000..731c606 --- /dev/null +++ b/examples/nodejs/examples/memory/memory.retrieve.filters.advanced.ts @@ -0,0 +1,50 @@ +/** + * Advanced example to demonstrate how to retrieve memories with filters. + * + * - And: This filter is used to retrieve memories that match all the filters. + * - Or: This filter is used to retrieve memories that match any of the filters. + * - In: This filter is used to retrieve memories that match any of the value/values in the array. + * - Eq: This filter is used to retrieve memories that match the exact value. + * + * In this example, we retrieve memories with the following filters: + * - company: Langbase + * - category: docs or examples + * - primitive: Chunk or Threads + * + * We expect to get all chunks of memory from the Langbase Docs memory + * that have the company Langbase, the category docs or examples, and the primitive can be Chunk or Threads. + * +*/ + +import 'dotenv/config'; +import {Langbase} from 'langbase'; + +const langbase = new Langbase({ + apiKey: process.env.LANGBASE_API_KEY!, +}); + +async function main() { + const response = await langbase.memories.retrieve({ + memory: [ + { + name: "langbase-docs", + filters: [ + "And", [ + ["company", "Eq", "Langbase"], + ["Or", [ + ["category", "Eq", "docs"], + ["category", "Eq", "examples"] + ]], + ["primitive", "In", ["Chunk", "Threads"]] + ] + ] + } + ], + query: "What are primitives in Langbase?", + topK: 5 + }); + + console.log(response); +} + +main(); diff --git a/examples/nodejs/package.json b/examples/nodejs/package.json index 46b7d59..539386d 100644 --- a/examples/nodejs/package.json +++ b/examples/nodejs/package.json @@ -13,6 +13,12 @@ "memory.list": "npx tsx ./examples/memory/memory.list.ts", "memory.delete": "npx tsx ./examples/memory/memory.delete.ts", "memory.retrieve": "npx tsx ./examples/memory/memory.retrieve.ts", + "memory.retrieve.filters.In": "npx tsx ./examples/memory/memory.retrieve.filters.In.ts", + "memory.retrieve.filters.NotIn": "npx tsx ./examples/memory/memory.retrieve.filters.NotIn.ts", + "memory.retrieve.filters.Eq": "npx tsx ./examples/memory/memory.retrieve.filters.Eq.ts", + "memory.retrieve.filters.NotEq": "npx tsx ./examples/memory/memory.retrieve.filters.NotEq.ts", + "memory.retrieve.filters.Or": "npx tsx ./examples/memory/memory.retrieve.filters.Or.ts", + "memory.retrieve.filters.advanced": "npx tsx ./examples/memory/memory.retrieve.filters.advanced.ts", "memory.docs.list": "npx tsx ./examples/memory/memory.docs.list.ts", "memory.docs.delete": "npx tsx ./examples/memory/memory.docs.delete.ts", "memory.docs.upload": "npx tsx ./examples/memory/memory.docs.upload.ts",