Skip to content

Commit

Permalink
[rag] get_langchain_retriever supports local path (#3140)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [x] **The pull request does not introduce [breaking changes].**
- [x] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [x] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [x] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
jingyizhu99 authored May 8, 2024
1 parent 31e3ae5 commit 68f929a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/promptflow-rag/promptflow/rag/_get_langchain_retriever.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
from pathlib import Path
from azureml.rag.mlindex import MLIndex
from promptflow.rag.constants._common import STORAGE_URI_TO_MLINDEX_PATH_FORMAT
import re
import yaml


def get_langchain_retriever_from_index(path: str):
if not re.match(STORAGE_URI_TO_MLINDEX_PATH_FORMAT, path):
raise ValueError(
"Path to MLIndex file doesn't have the correct format."
)
return MLIndex(path).as_langchain_retriever()
if re.match(STORAGE_URI_TO_MLINDEX_PATH_FORMAT, path):
return MLIndex(path).as_langchain_retriever()

# local path
mlindex_path = str(Path(path) / "MLIndex") if not path.endswith("MLIndex") else path
with open(mlindex_path, "r") as f:
config = yaml.safe_load(f)
return MLIndex(mlindex_config=config).as_langchain_retriever()
2 changes: 1 addition & 1 deletion src/promptflow-rag/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
azureml-rag[cognitive_search,document_parsing,langchain]
azureml-rag[azure,cognitive_search,document_parsing,langchain]
openai

0 comments on commit 68f929a

Please sign in to comment.