Skip to content
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

Exclude access control metadata keys from LLMs and embeddings - SharePoint Reader #13184

Merged
merged 6 commits into from
Apr 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ def _download_files_from_sharepoint(
recursive,
)

def _exclude_access_control_metadata(
self, documents: List[Document]
) -> List[Document]:
"""
Excludes the access control metadata from the documents for embedding and LLM calls.

Args:
documents (List[Document]): A list of documents.

Returns:
List[Document]: A list of documents with access control metadata excluded.
"""
for doc in documents:
access_control_keys = [
key for key in doc.metadata if key.startswith("allowed_")
]

doc.excluded_embed_metadata_keys.extend(access_control_keys)
doc.excluded_llm_metadata_keys.extend(access_control_keys)

return documents

def _load_documents_with_metadata(
self,
files_metadata: Dict[str, Any],
Expand Down Expand Up @@ -448,7 +470,10 @@ def get_metadata(filename: str) -> Any:
file_metadata=get_metadata,
recursive=recursive,
)
return simple_loader.load_data()
docs = simple_loader.load_data()
if self.attach_permission_metadata:
docs = self._exclude_access_control_metadata(docs)
return docs

def load_data(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ license = "MIT"
maintainers = ["arun-soliton"]
name = "llama-index-readers-microsoft-sharepoint"
readme = "README.md"
version = "0.2.1"
version = "0.2.2"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Loading