Skip to content

Commit

Permalink
Merge pull request #11 from Azure-Samples/serdar-changes
Browse files Browse the repository at this point in the history
Finalize the searcher and update readme accordingly
  • Loading branch information
serdarmicrosoft authored Nov 22, 2024
2 parents 3f00e51 + 039a490 commit 8456902
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 45 deletions.
36 changes: 0 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,6 @@ The steps below guides you to deploy the Azure services necessary for this solut
```
This will provision Azure resources and deploy this sample to those resources, including Azure Database for PostgreSQL Flexible Server, Azure OpenAI service, and Azure App Service.

5. Provide Azure ML Endpoint and Key

You will be asked for 2 values, the `"azureMLEndpointKey"` and `"azureMLScoringEndpoint"`

Use the values obtained during the Prerequisite Steps above.

6. Run Post Provision SQL Script for GraphRAG

First, gather the PostgreSQL Username that was generated during provision time, use the following command using azd. Keep note of this Username:

```bash
azd env get-value SERVICE_WEB_IDENTITY_NAME
```

Then, open your favorite PostgreSQL client tool, such as pgAdmin, and run the following script. Be sure to replace `{Username}` with the Username obtained in the step above:

```pgsql
CREATE EXTENSION IF NOT EXISTS age;
SET search_path = ag_catalog, "$user", public;
SELECT * FROM cypher('case_graph', $$
MATCH ()-[r:CITES]->()
RETURN COUNT(r) AS cites_count
$$) AS (cites_count agtype);
SELECT * FROM cypher('case_graph', $$
MATCH ()-[r:CITES]->()
RETURN COUNT(r) AS cites_count
$$) AS (cites_count agtype);
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA case_graph TO "{Username}"
```

This should finalize your PostgreSQL instance for the Apache AGE Graph extension and legal citation data that was loaded.

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
Expand Down
10 changes: 1 addition & 9 deletions src/backend/fastapi_app/postgres_searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def search(

token_file = Path(__file__).parent / "postgres_token.txt"

if token_file.exists():
if token_file.exists() and retrieval_mode == RetrievalMode.GRAPHRAG:
try:
script_path = Path(__file__).parent / "setup_postgres_age.py"

Expand All @@ -70,18 +70,10 @@ async def search(
subprocess.run(["python", str(script_path)], check=True)
logger.info("setup_postgres_age.py completed successfully.")

if token_file.exists():
try:
token_file.unlink()
logger.info(f"Deleted token file: {token_file}")
except Exception as del_err:
logger.error(f"Failed to delete token file: {del_err}")
except subprocess.CalledProcessError as e:
logger.error(f"Error occurred while running setup_postgres_age.py: {e}")
raise
except Exception as e:
logger.error(f"Unexpected error: {e}")
raise

await self.db_session.execute(text('SET search_path = ag_catalog, "$user", public;'))

Expand Down

0 comments on commit 8456902

Please sign in to comment.