-
Notifications
You must be signed in to change notification settings - Fork 11
Port to langchain #222
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
base: main
Are you sure you want to change the base?
Port to langchain #222
Changes from all commits
65110de
2ce47f8
5a129ee
5ae1e5f
ecfbac4
4383b18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "permissions": { | ||
| "allow": [ | ||
| "WebFetch(https://docs.langchain.com/*)", | ||
| ], | ||
| "WebFetch(https://docs.langchain.com/*)" | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,14 +83,22 @@ backend/ | |
|
|
||
| ### RAG (Retrieval-Augmented Generation) | ||
|
|
||
| The system uses **Vertex AI RAG (Retrieval-Augmented Generation)**, which combines Google's Vertex AI vector search capabilities with the Gemini 2.5 Pro language model. This is specifically a **grounded generation** approach where the LLM has access to a tool-based retrieval system that searches through a curated corpus of Oregon housing law documents. | ||
| The system uses **LangChain agents** with **Vertex AI RAG** tools for document retrieval. This combines LangChain's agent orchestration with Google's Vertex AI vector search capabilities and Gemini 2.5 Pro language model. | ||
|
|
||
| **RAG Type and Category:** | ||
| **Architecture Type**: Agent-based RAG with tool calling | ||
| - **Framework**: LangChain 1.0.8+ (monolithic package) | ||
| - **LLM Integration**: ChatVertexAI (langchain-google-vertexai 3.0.3+) | ||
| - **Agent Pattern**: `create_tool_calling_agent()` with custom RAG tools | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation Issue: Incorrect agent function name The documentation mentions Please update to match the actual implementation. |
||
| - **Retrieval Method**: Dense vector similarity search with metadata filtering | ||
|
|
||
| - **Architecture Type**: Tool-augmented RAG with function calling | ||
| - **Implementation**: Vertex AI managed RAG service | ||
| - **Retrieval Method**: Dense vector similarity search with semantic matching | ||
| - **Grounding**: Tool-based retrieval integrated directly into Gemini's generation process | ||
| #### Tool-Based Retrieval | ||
|
|
||
| The agent has access to two retrieval tools: | ||
|
|
||
| 1. **City-Specific Law Retrieval**: Searches documents filtered by city and state | ||
| 2. **State-Wide Law Retrieval**: Searches general Oregon laws | ||
|
|
||
| The LLM decides which tool(s) to use based on the user's query and location context. | ||
|
|
||
| #### Data Ingestion Pipeline | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
|
|
||
| [project] | ||
| name = "tenant-first-aid" | ||
| version = "0.2.0" | ||
| version = "0.3.0" | ||
| requires-python = ">=3.12" | ||
| dependencies = [ | ||
| "flask>=3.1.1", | ||
|
|
@@ -19,6 +19,11 @@ dependencies = [ | |
| "python-dotenv", | ||
| "pandas>=2.3.0", | ||
| "vertexai>=1.43.0", | ||
| "langchain>=1.1.0", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dependency Management: Consider version pinning The new LangChain dependencies use minimum version constraints (
Recommendation: "langchain>=1.1.0,<2.0.0",
"langchain-google-vertexai>=3.1.0,<4.0.0",
"langsmith>=0.4.47,<0.5.0",Or use lock files to ensure reproducibility (which you already have with |
||
| "langchain-google-vertexai>=3.1.0", | ||
| "langsmith>=0.4.47", | ||
| "langchain-core>=1.1.0", | ||
| "openevals>=0.1.2", | ||
| ] | ||
|
|
||
| [tool.setuptools.packages.find] | ||
|
|
@@ -36,12 +41,14 @@ dev = [ | |
| "pandas-stubs>=2.2.3.250527", | ||
| "pyrefly>=0.21.0", | ||
| "pytest>=8.4.0", | ||
| "pytest-asyncio>=0.23.0", | ||
| "pytest-cov>=6.1.1", | ||
| "pytest-mock>=3.14.1", | ||
| "ruff>=0.12.0", | ||
| "ty>=0.0.1a11", | ||
| "types-Flask>=1.1.6", | ||
| "types-simplejson>=3.20.0.20250326", | ||
| "httpx>=0.27.0", | ||
| ] | ||
|
|
||
| gen_convo = [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Convert tenant_questions_facts_full.csv to LangSmith evaluation dataset. | ||
| This script uploads test scenarios from the manual evaluation CSV to LangSmith | ||
| for automated evaluation. | ||
| """ | ||
|
|
||
| import ast | ||
| from pathlib import Path | ||
|
|
||
| import pandas as pd | ||
| from langsmith import Client | ||
|
|
||
|
|
||
| def create_langsmith_dataset(): | ||
| """Upload test scenarios to LangSmith for automated evaluation.""" | ||
| client = Client() | ||
|
|
||
| # Read existing test scenarios. | ||
| csv_path = ( | ||
| Path(__file__).parent | ||
| / "generate_conversation" | ||
| / "tenant_questions_facts_full.csv" | ||
| ) | ||
| df = pd.read_csv(csv_path, encoding="cp1252") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Encoding Issue: Hardcoded The CSV is read with
Recommendation: # Try UTF-8 first, fallback to cp1252 if needed
try:
df = pd.read_csv(csv_path, encoding="utf-8")
except UnicodeDecodeError:
df = pd.read_csv(csv_path, encoding="cp1252")Consider converting the source CSV to UTF-8 for consistency. |
||
|
|
||
| # Create dataset in LangSmith. | ||
| dataset = client.create_dataset( | ||
| dataset_name="tenant-legal-qa-scenarios", | ||
| description="Test scenarios for Oregon tenant legal advice chatbot", | ||
| ) | ||
|
|
||
| # Convert each row to LangSmith example. | ||
| for idx, row in df.iterrows(): | ||
| facts = ( | ||
| ast.literal_eval(row["facts"]) | ||
| if isinstance(row["facts"], str) | ||
| else row["facts"] | ||
| ) | ||
| city = row["city"] if not pd.isna(row["city"]) else "null" | ||
|
|
||
| # Each example has inputs and expected metadata. | ||
| client.create_example( | ||
| dataset_id=dataset.id, | ||
| inputs={ | ||
| "first_question": row["first_question"], | ||
| "city": city, | ||
| "state": row["state"], | ||
| "facts": facts, | ||
| }, | ||
| metadata={ | ||
| "scenario_id": idx, | ||
| "city": city, | ||
| "state": row["state"], | ||
| # Tag scenarios for filtering. | ||
| "tags": ["tenant-rights", f"city-{city}", f"state-{row['state']}"], | ||
| }, | ||
| # Optionally include reference conversation for comparison. | ||
| outputs={"reference_conversation": row.get("Original conversation", None)}, | ||
| ) | ||
|
|
||
| print(f"Created dataset '{dataset.name}' with {len(df)} scenarios") | ||
| return dataset | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| create_langsmith_dataset() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Addition: Clear LangChain architecture documentation
Excellent documentation of the new architecture! The environment variables section is particularly helpful.
Minor suggestion: Consider adding a section about running the evaluation suite locally, since it's a key part of the quality assurance process: