---
title: CnosDB
---

> [CnosDB](https://github.com/cnosdb/cnosdb)는 고성능, 높은 압축률, 뛰어난 사용 편의성을 갖춘 오픈소스 분산 시계열 데이터베이스입니다.

## Installation and Setup

```python
pip install cnos-connector

CnosDB에 연결하기

SQLDatabase.from_cnosdb() 메서드를 사용하여 CnosDB에 연결할 수 있습니다.

Syntax

def SQLDatabase.from_cnosdb(url: str = "127.0.0.1:8902",
                              user: str = "root",
                              password: str = "",
                              tenant: str = "cnosdb",
                              database: str = "public")
Args:
  1. url (str): CnosDB 서비스의 HTTP 연결 호스트 이름과 포트 번호입니다. “http://” 또는 “https://“를 제외하며, 기본값은 “127.0.0.1:8902”입니다.
  2. user (str): CnosDB 서비스에 연결하는 데 사용되는 사용자 이름이며, 기본값은 “root”입니다.
  3. password (str): CnosDB 서비스에 연결하는 사용자의 비밀번호이며, 기본값은 ""입니다.
  4. tenant (str): CnosDB 서비스에 연결하는 데 사용되는 테넌트 이름이며, 기본값은 “cnosdb”입니다.
  5. database (str): CnosDB 테넌트의 데이터베이스 이름입니다.

Examples

# Connecting to CnosDB with SQLDatabase Wrapper
from langchain_community.utilities import SQLDatabase

db = SQLDatabase.from_cnosdb()
# Creating a OpenAI Chat LLM Wrapper
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(temperature=0, model_name="gpt-3.5-turbo")

SQL Database Chain

이 예제는 CnosDB에 대한 질문에 답변하기 위해 SQL Chain을 사용하는 방법을 보여줍니다.
from langchain_community.utilities import SQLDatabaseChain

db_chain = SQLDatabaseChain.from_llm(llm, db, verbose=True)

db_chain.run(
    "What is the average temperature of air at station XiaoMaiDao between October 19, 2022 and Occtober 20, 2022?"
)
> Entering new  chain...
What is the average temperature of air at station XiaoMaiDao between October 19, 2022 and Occtober 20, 2022?
SQLQuery:SELECT AVG(temperature) FROM air WHERE station = 'XiaoMaiDao' AND time >= '2022-10-19' AND time < '2022-10-20'
SQLResult: [(68.0,)]
Answer:The average temperature of air at station XiaoMaiDao between October 19, 2022 and October 20, 2022 is 68.0.
> Finished chain.

SQL Database Agent

이 예제는 CnosDB에 대한 질문에 답변하기 위해 SQL Database Agent를 사용하는 방법을 보여줍니다.
from langchain.agents import create_sql_agent
from langchain_community.agent_toolkits import SQLDatabaseToolkit

toolkit = SQLDatabaseToolkit(db=db, llm=llm)
agent = create_sql_agent(llm=llm, toolkit=toolkit, verbose=True)
agent.run(
    "What is the average temperature of air at station XiaoMaiDao between October 19, 2022 and Occtober 20, 2022?"
)
> Entering new  chain...
Action: sql_db_list_tables
Action Input: ""
Observation: air
Thought:The "air" table seems relevant to the question. I should query the schema of the "air" table to see what columns are available.
Action: sql_db_schema
Action Input: "air"
Observation:
CREATE TABLE air (
	pressure FLOAT,
	station STRING,
	temperature FLOAT,
	time TIMESTAMP,
	visibility FLOAT
)

/*
3 rows from air table:
pressure	station	temperature	time	visibility
75.0	XiaoMaiDao	67.0	2022-10-19T03:40:00	54.0
77.0	XiaoMaiDao	69.0	2022-10-19T04:40:00	56.0
76.0	XiaoMaiDao	68.0	2022-10-19T05:40:00	55.0
*/
Thought:The "temperature" column in the "air" table is relevant to the question. I can query the average temperature between the specified dates.
Action: sql_db_query
Action Input: "SELECT AVG(temperature) FROM air WHERE station = 'XiaoMaiDao' AND time >= '2022-10-19' AND time &lt;= '2022-10-20'"
Observation: [(68.0,)]
Thought:The average temperature of air at station XiaoMaiDao between October 19, 2022 and October 20, 2022 is 68.0.
Final Answer: 68.0

> Finished chain.

---

<Callout icon="pen-to-square" iconType="regular">
    [Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/cnosdb.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
    [Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for    real-time answers.
</Tip>
I