From bedde2bf2063c52c2f9426b303c51e2ddcc253b1 Mon Sep 17 00:00:00 2001
From: Huu Le <39040748+leehuwuj@users.noreply.github.com>
Date: Thu, 29 Aug 2024 15:46:31 +0700
Subject: [PATCH] Use is_empty filter (#263)

---
 .changeset/four-impalas-pay.md                              | 5 +++++
 .../components/vectordbs/python/llamacloud/query_filter.py  | 6 +++---
 .../vectordbs/typescript/llamacloud/queryFilter.ts          | 4 ++--
 3 files changed, 10 insertions(+), 5 deletions(-)
 create mode 100644 .changeset/four-impalas-pay.md

diff --git a/.changeset/four-impalas-pay.md b/.changeset/four-impalas-pay.md
new file mode 100644
index 00000000..802f6e8b
--- /dev/null
+++ b/.changeset/four-impalas-pay.md
@@ -0,0 +1,5 @@
+---
+"create-llama": patch
+---
+
+Use is_empty filter for private files in LlamaCloud Index
diff --git a/templates/components/vectordbs/python/llamacloud/query_filter.py b/templates/components/vectordbs/python/llamacloud/query_filter.py
index b9a5ca40..fdaabd6a 100644
--- a/templates/components/vectordbs/python/llamacloud/query_filter.py
+++ b/templates/components/vectordbs/python/llamacloud/query_filter.py
@@ -5,11 +5,11 @@ def generate_filters(doc_ids):
     """
     Generate public/private document filters based on the doc_ids and the vector store.
     """
-    # Using "nin" filter to include the documents don't have the "private" key because they're uploaded in LlamaCloud UI
+    # Using "is_empty" filter to include the documents don't have the "private" key because they're uploaded in LlamaCloud UI
     public_doc_filter = MetadataFilter(
         key="private",
-        value=["true"],
-        operator="nin",  # type: ignore
+        value=None,
+        operator="is_empty",  # type: ignore
     )
     selected_doc_filter = MetadataFilter(
         key="file_id",  # Note: LLamaCloud uses "file_id" to reference private document ids as "doc_id" is a restricted field in LlamaCloud
diff --git a/templates/components/vectordbs/typescript/llamacloud/queryFilter.ts b/templates/components/vectordbs/typescript/llamacloud/queryFilter.ts
index 359e7f9f..c3ed6e3e 100644
--- a/templates/components/vectordbs/typescript/llamacloud/queryFilter.ts
+++ b/templates/components/vectordbs/typescript/llamacloud/queryFilter.ts
@@ -4,8 +4,8 @@ export function generateFilters(documentIds: string[]): MetadataFilters {
   // public documents don't have the "private" field or it's set to "false"
   const publicDocumentsFilter: MetadataFilter = {
     key: "private",
-    value: ["true"],
-    operator: "nin",
+    value: null,
+    operator: "is_empty",
   };
 
   // if no documentIds are provided, only retrieve information from public documents
-- 
GitLab