Skip to content

Commit

Permalink
Merge pull request #138 from vanna-ai/vannadb
Browse files Browse the repository at this point in the history
Use Vanna-Hosted Vector Database with any LLMs
  • Loading branch information
zainhoda authored Dec 15, 2023
2 parents 1bde822 + 0e4c0a5 commit 8364f3d
Show file tree
Hide file tree
Showing 58 changed files with 243 additions and 56 deletions.
2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-azure-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-azure-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-azure-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-standard-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-standard-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-standard-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-vanna-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-openai-vanna-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-other-llm-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-other-llm-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/bigquery-other-llm-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-azure-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-azure-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-azure-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-standard-chromadb.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-standard-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-vanna-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-openai-vanna-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-other-llm-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-other-llm-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/other-database-other-llm-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-azure-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-azure-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-azure-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-standard-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-standard-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-standard-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-vanna-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-openai-vanna-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-other-llm-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-other-llm-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/postgres-other-llm-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-azure-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-azure-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-azure-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-standard-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-standard-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-standard-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-vanna-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-openai-vanna-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-other-llm-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-other-llm-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/snowflake-other-llm-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-azure-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-azure-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-azure-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-standard-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-standard-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-standard-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-vanna-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-openai-vanna-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-other-llm-chromadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-other-llm-other-vectordb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion notebooks/sqlite-other-llm-vannadb.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/vanna/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def add_ddl(self, ddl: str, **kwargs) -> str:

return status.id

def add_documentation(self, documentation: str, **kwargs) -> str:
def add_documentation(self, doc: str, **kwargs) -> str:
"""
Adds documentation to the model's training data
Expand Down
Empty file added src/vanna/vannadb/__init__.py
Empty file.
187 changes: 187 additions & 0 deletions src/vanna/vannadb/vannadb_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
from ..base import VannaBase
from ..types import (
QuestionSQLPair,
StatusWithId,
StringData,
DataFrameJSON,
Status,
TrainingData,
Question,
)
from io import StringIO
import pandas as pd
import requests
import json
import dataclasses

class VannaDB_VectorStore(VannaBase):
def __init__(self, vanna_model: str, vanna_api_key: str, config=None):
VannaBase.__init__(self, config=config)

self._model = vanna_model
self._api_key = vanna_api_key

self._endpoint = (
"https://ask.vanna.ai/rpc"
if config is None or "endpoint" not in config
else config["endpoint"]
)
self._unauthenticated_endpoint = (
"https://ask.vanna.ai/unauthenticated_rpc"
if config is None or "unauthenticated_endpoint" not in config
else config["unauthenticated_endpoint"]
)
self.related_training_data = {}

def _unauthenticated_rpc_call(self, method, params):
headers = {
"Content-Type": "application/json",
}
data = {
"method": method,
"params": [self._dataclass_to_dict(obj) for obj in params],
}

response = requests.post(
self._unauthenticated_endpoint, headers=headers, data=json.dumps(data)
)
return response.json()

def _rpc_call(self, method, params):
if method != "list_orgs":
headers = {
"Content-Type": "application/json",
"Vanna-Key": self._api_key,
"Vanna-Org": self._model,
}
else:
headers = {
"Content-Type": "application/json",
"Vanna-Key": self._api_key,
"Vanna-Org": "demo-tpc-h",
}

data = {
"method": method,
"params": [self._dataclass_to_dict(obj) for obj in params],
}

response = requests.post(self._endpoint, headers=headers, data=json.dumps(data))
return response.json()

def _dataclass_to_dict(self, obj):
return dataclasses.asdict(obj)

def generate_embedding(self, data: str, **kwargs) -> list[float]:
# This is done server-side
pass

def add_question_sql(self, question: str, sql: str, **kwargs) -> str:
if "tag" in kwargs:
tag = kwargs["tag"]
else:
tag = "Manually Trained"

params = [QuestionSQLPair(question=question, sql=sql, tag=tag)]

d = self._rpc_call(method="add_sql", params=params)

if "result" not in d:
raise Exception("Error adding question and SQL pair", d)

status = StatusWithId(**d["result"])

return status.id

def add_ddl(self, ddl: str, **kwargs) -> str:
params = [StringData(data=ddl)]

d = self._rpc_call(method="add_ddl", params=params)

if "result" not in d:
raise Exception("Error adding DDL", d)

status = StatusWithId(**d["result"])

return status.id

def add_documentation(self, doc: str, **kwargs) -> str:
params = [StringData(data=doc)]

d = self._rpc_call(method="add_documentation", params=params)

if "result" not in d:
raise Exception("Error adding documentation", d)

status = StatusWithId(**d["result"])

return status.id

def get_training_data(self, **kwargs) -> pd.DataFrame:
params = []

d = self._rpc_call(method="get_training_data", params=params)

if "result" not in d:
return None

# Load the result into a dataclass
training_data = DataFrameJSON(**d["result"])

df = pd.read_json(StringIO(training_data.data))

return df

def remove_training_data(self, id: str, **kwargs) -> bool:
params = [StringData(data=id)]

d = self._rpc_call(method="remove_training_data", params=params)

if "result" not in d:
raise Exception(f"Error removing training data")

status = Status(**d["result"])

if not status.success:
raise Exception(f"Error removing training data: {status.message}")

return status.success

def get_related_training_data_cached(self, question: str) -> TrainingData:
params = [Question(question=question)]

d = self._rpc_call(method="get_related_training_data", params=params)

if "result" not in d:
return None

# Load the result into a dataclass
training_data = TrainingData(**d["result"])

self.related_training_data[question] = training_data

return training_data

def get_similar_question_sql(self, question: str, **kwargs) -> list:
if question in self.related_training_data:
training_data = self.related_training_data[question]
else:
training_data = self.get_related_training_data_cached(question)

return training_data.questions

def get_related_ddl(self, question: str, **kwargs) -> list:
if question in self.related_training_data:
training_data = self.related_training_data[question]
else:
training_data = self.get_related_training_data_cached(question)

return training_data.ddl

def get_related_documentation(self, question: str, **kwargs) -> list:
if question in self.related_training_data:
training_data = self.related_training_data[question]
else:
training_data = self.get_related_training_data_cached(question)

return training_data.documentation

0 comments on commit 8364f3d

Please sign in to comment.