Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions examples/nodejs/examples/memory/memory.retrieve.filters.And.ts
Original file line number Diff line number Diff line change
@@ -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();
35 changes: 35 additions & 0 deletions examples/nodejs/examples/memory/memory.retrieve.filters.Eq.ts
Original file line number Diff line number Diff line change
@@ -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();
35 changes: 35 additions & 0 deletions examples/nodejs/examples/memory/memory.retrieve.filters.In.ts
Original file line number Diff line number Diff line change
@@ -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();
35 changes: 35 additions & 0 deletions examples/nodejs/examples/memory/memory.retrieve.filters.NotEq.ts
Original file line number Diff line number Diff line change
@@ -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();
35 changes: 35 additions & 0 deletions examples/nodejs/examples/memory/memory.retrieve.filters.NotIn.ts
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
@@ -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();
6 changes: 6 additions & 0 deletions examples/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading