{"id":25538636,"url":"https://github.com/mindsdb/langchain-minds","last_synced_at":"2026-01-31T15:30:16.877Z","repository":{"id":269568168,"uuid":"907808336","full_name":"mindsdb/langchain-minds","owner":"mindsdb","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-27T15:53:27.000Z","size":191,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-13T11:05:48.294Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mindsdb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-24T12:45:34.000Z","updated_at":"2025-01-27T15:53:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"17d8a2c1-54f8-4ba5-943d-8ce4fa471a97","html_url":"https://github.com/mindsdb/langchain-minds","commit_stats":null,"previous_names":["minurapunchihewa/langchain-minds"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindsdb%2Flangchain-minds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindsdb%2Flangchain-minds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindsdb%2Flangchain-minds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindsdb%2Flangchain-minds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mindsdb","download_url":"https://codeload.github.com/mindsdb/langchain-minds/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239780387,"owners_count":19695792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-20T05:20:57.519Z","updated_at":"2026-01-31T15:30:16.800Z","avatar_url":"https://github.com/mindsdb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# langchain-minds\n\nThis package contains the LangChain adapter for [Minds](https://mindsdb.com/minds).\n\n## Installation\n\n```bash\npip install -U langchain-minds\n```\n\n## Setup\n\nLogin to your Minds account at https://mdb.ai and obtain an API key and set it as an environment variable.\n\n```bash\nexport MINDS_API_KEY=\u003cYOUR_API_KEY\u003e\n```\n\nSet the password for our demo database as an environment variable.\n\n```bash\nexport POSTGRES_PASSWORD=demo_password\n```\n\nOR\n\n```python\nimport getpass\nimport os\n\nif not os.environ.get(\"MINDS_API_KEY\"):\n    os.environ[\"MINDS_API_KEY\"] = getpass.getpass(\"MINDS API key:\\n\")\n\nif not os.environ.get(\"POSTGRES_PASSWORD\"):\n    os.environ[\"POSTGRES_PASSWORD\"] = getpass.getpass(\"Postgres password:\\n\")\n```\n\n## Usage\n\nThe `AIMindTool` can be used to configure and query a [range of data sources](https://docs.mdb.ai/docs/data_sources) in plain English.\n\nGiven below is an example that demonstrates how to configure our demo PostgreSQL database, which contains house sales data, and find out how many three-bedroom houses were sold in 2008.\n\n### Instantiation\n\n```python\nfrom langchain_minds import AIMindDataSource, AIMindEnvVar, AIMindAPIWrapper, AIMindTool\n\n\n# Create a data source that your Mind will have access to.\n# This will create a new data source using the connection data provided with the given name.\n# To configure additional data sources, simply create additional instances of\n# AIMindDataSource and pass it to the wrapper below.\ndatasource = AIMindDataSource(\n    name=\"demo_datasource\",\n    description=\"house sales data\",\n    engine=\"postgres\",\n    connection_data={\n        \"user\": 'demo_user',\n        \"password\": AIMindEnvVar(\n            'POSTGRES_PASSWORD',\n            is_secret=True\n        ), # Use an environment variable for the password.\n        \"host\": \"samples.mindsdb.com\",\n        \"port\": 5432,\n        \"database\": \"demo\",\n        \"schema\": \"demo_data\"\n    },\n    tables=['house_sales']\n)\n\n# NOTE: Feel free to use the above connection data as is!\n# It's our demo database open to the public.\n\n# To re-use an existing data source, simply provide the name of the data source\n# without any other parameters.\n# datasource = AIMindDataSource(\n#     name=\"demo_datasource\",\n# )\n\n# Create the wrapper for the Minds API by giving the Mind a name and passing in the\n# data sources created above.\n# This will create a new Mind with the given name and access to the data sources.\napi_wrapper = AIMindAPIWrapper(\n    name=\"demo_mind\",\n    datasources=[datasource]\n)\n\n# To re-use an existing Mind, simply provide the name of the Mind without any data sources.\n# aimind_tool = AIMindAPIWrapper(\n#     name=\"demo_mind\",\n# )\n\n# Create the tool by simply passing in the API wrapper from before.\nai_minds_tool = AIMindTool(\n    api_wrapper=api_wrapper\n)\n```\n\n### Invocation\n\n```python\n# Invoke the tool by asking a question in plain English.\nai_minds_tool.invoke({\"query\": \"How many three-bedroom houses were sold in 2008?\"})\n\u003e\u003e 'The number of three-bedroom houses sold in 2008 was 8.'\n```\n\n## Usage with an Agent\n\nGiven below is an example that uses the `AIMindTool` configured above and a tool that searches the web (`BraveSearch`) to find the total number of houses sold in 2008 and compare the average prices of these houses to the average house price in the US today.\n\n```python\nfrom langchain import hub\nfrom langchain.agents import AgentExecutor, create_tool_calling_agent\nfrom langchain_community.tools import BraveSearch\nfrom langchain_openai import ChatOpenAI\n\n\nllm = ChatOpenAI(model=\"gpt-3.5-turbo-0125\", temperature=0)\n\nsearch = BraveSearch.from_api_key(api_key=BRAVE_SEARCH_API_KEY, search_kwargs={\"count\": 3})\n\ntools = [search, database]\n\nprompt = hub.pull(\"hwchase17/openai-functions-agent\")\n\nagent = create_tool_calling_agent(llm, tools, prompt)\n\nagent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)\n\nagent_executor.invoke(\n    {\n        \"input\": \"According to the data in my database, how many houses in total were sold in 2008?\"\n        \"Compare the average price of the houses that were sold to the approximate average house price today in the US.\"\n    }\n)\n\u003e\u003e Entering new AgentExecutor chain...\n\u003e\u003e\n\u003e\u003e Invoking: `ai_mind` with `{'query': 'How many houses were sold in 2008 and what was the average price of those houses?'}`\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e In 2008, a total of 28 houses were sold. The average price of these houses was approximately 484,930.14.\n\u003e\u003e Invoking: `brave_search` with `{'query': 'approximate average house price in the US today'}`\n\u003e\u003e\n\u003e\u003e\n\u003e\u003e [{\"title\": \"Average House Price by State in 2024 | The Motley Fool\", \"link\": \"https://www.fool.com/the-ascent/research/\u003e\u003e average-house-price-state/\", \"snippet\": \"The average house price in the United States as of the third quarter of 2024 is \u003e\u003e \u003cstrong\u003e$420,400\u003c/strong\u003e. See how states compare here.\"}, {\"title\": \"Average new home sales price in the U.S. 2023 | Statista\", \u003e\u003e \"link\": \"https://www.statista.com/statistics/240991/average-sales-prices-of-new-homes-sold-in-the-us/\", \"snippet\": \"After a dramatic \u003e\u003e increase in 2022, the average sales price of a new home in the United States dropped slightly in 2023 from 540,000 to \u003cstrong\u003e511,\u003e\u003e 100 U.S.\u003c/strong\u003e\"}, {\"title\": \"Median Home Price By State: How Much Houses Cost | Bankrate\", \"link\": \"https://www.bankrate.com/\u003e\u003e real-estate/median-home-price/\", \"snippet\": \"Another useful guideline that can help is the 28 percent rule: Many experts advise \u003e\u003e limiting your housing expenses to \u003cstrong\u003eno more than 28 percent of your income\u003c/strong\u003e. If you earn $7,000 per month, for \u003e\u003e example, that means keeping your total housing costs at $1,960 or less.\"}]The approximate average house price in the US today is \u003e\u003e $420,400.\n\u003e\u003e\n\u003e\u003e Comparing this to the average price of houses sold in 2008, which was approximately $484,930.14, we can see that the average house \u003e\u003e price in 2008 was higher than the approximate average house price today in the US.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindsdb%2Flangchain-minds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmindsdb%2Flangchain-minds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindsdb%2Flangchain-minds/lists"}