-
Notifications
You must be signed in to change notification settings - Fork 8
👌 IMPROVE: memory example with filters #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
saqibameen
merged 6 commits into
CommandCodeAI:main
from
arre-ankit:ankit/memory-retrive-filters-examples
Mar 27, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6002e3
👌 IMPROVE: memory example with filters
arre-ankit b8bc15a
🐛 FIX: package.json
arre-ankit 20c2220
🐛 FIX: comments for filter examples
arre-ankit 4276b14
🐛 FIX: formatting issue
arre-ankit 146c7ee
🐛 FIX: formatting issue
arre-ankit 3eee906
🐛 FIX: package.json
arre-ankit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
examples/nodejs/examples/memory/memory.retrieve.filters.And.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
35
examples/nodejs/examples/memory/memory.retrieve.filters.Eq.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
35
examples/nodejs/examples/memory/memory.retrieve.filters.In.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
35
examples/nodejs/examples/memory/memory.retrieve.filters.NotEq.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
35
examples/nodejs/examples/memory/memory.retrieve.filters.NotIn.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
50 changes: 50 additions & 0 deletions
50
examples/nodejs/examples/memory/memory.retrieve.filters.advanced.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.