Skip to content
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

Knowledge backend #737

Closed
wants to merge 48 commits into from
Closed

Knowledge backend #737

wants to merge 48 commits into from

Conversation

Tarraann
Copy link
Collaborator

@Tarraann Tarraann commented Jul 12, 2023

Description

Related Issues

Solution and Design

Test Plan

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Docs update

Checklist

  • My pull request is atomic and focuses on a single change.
  • I have read the contributing guide and my code conforms to the guidelines.
  • I have documented my changes clearly and comprehensively.
  • I have added the required tests.

@codecov
Copy link

codecov bot commented Jul 12, 2023

Codecov Report

Patch coverage: 35.24% and project coverage change: -2.31 ⚠️

Comparison is base (2cff734) 58.49% compared to head (4cccc8c) 56.18%.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #737      +/-   ##
==========================================
- Coverage   58.49%   56.18%   -2.31%     
==========================================
  Files         146      159      +13     
  Lines        5847     6491     +644     
  Branches      604      660      +56     
==========================================
+ Hits         3420     3647     +227     
- Misses       2284     2701     +417     
  Partials      143      143              
Impacted Files Coverage Δ
superagi/helper/pinecone_helper.py 16.94% <16.94%> (ø)
superagi/helper/qdrant_helper.py 16.94% <16.94%> (ø)
superagi/controllers/vector_db.py 23.21% <23.21%> (ø)
superagi/controllers/knowledge.py 27.64% <27.64%> (ø)
superagi/controllers/vector_db_index.py 29.78% <29.78%> (ø)
superagi/helper/knowledge_helper.py 38.46% <38.46%> (ø)
superagi/models/knowledge.py 42.42% <42.42%> (ø)
superagi/models/vector_db.py 56.41% <56.41%> (ø)
superagi/models/knowledge_config.py 59.09% <59.09%> (ø)
superagi/models/vector_db_index_collection.py 60.71% <60.71%> (ø)
... and 3 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

depends_on = None


def upgrade() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do u need this migration?

depends_on = None


def upgrade() -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this migration?

sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('marketplace_state',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont even create this table if u are dropping later.

Copy link
Collaborator

@TransformerOptimus TransformerOptimus Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table name should be knowledges, vector_dbs


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('knowledge',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all tables names should be plural.


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('knowledge_config',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it knowledge_configs

# ### commands auto generated by Alembic - please adjust! ###
op.create_table('knowledge_config',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('knowledge_id', sa.Integer(), nullable=True),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id, knowledge_id, key cant be nullable.

sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('vector_db_index_collection',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be vector_db_indexes. index_collection does not make sense.

name, vector_db_id can't be nullable

router = APIRouter()


@router.get("/get/list")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marketplace/list

@router.get("/user/list")
def get_user_knowledge_list(Authorize: AuthJWT = Depends(), organisation = Depends(get_user_organisation)):
organisation_id = organisation.id
marketplace_organisation_id = int(get_config("MARKETPLACE_ORGANISATION_ID"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic does not seem right. local one cant even fetch MARKETPLACE_ORGANISATION_ID. In local nobody sets MARKETPLACE_ORGANISATION_ID

from superagi.helper.auth import get_user_organisation
router = APIRouter()
@router.get("/get/list")
def handle_marketplace_operations_list():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the method.

pinecone = []
qdrant = []
for vector in vector_dbs:
indices = db.session.query(VectorIndexCollection).filter(VectorIndexCollection.vector_db_id == vector["id"]).all()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a right pattern to call sql inside a loop

qdrant = []
for vector in vector_dbs:
indices = db.session.query(VectorIndexCollection).filter(VectorIndexCollection.vector_db_id == vector["id"]).all()
for index in indices:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a right pattern to call sql inside a loop

from superagi.models.knowledge_config import KnowledgeConfig
from superagi.models.index_config import VectorIndexConfig

class KnowledgeHelper:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper classes does not make sense. Create a new package knowledge and restructure the classes.


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('vector_index_config',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to vector_index_configs.

added_indices = new_indices_names - existing_indices_names
for index in added_indices:
vector_index = VectorIndexCollection.add_vector_index(db.session, existing_index, vector_db_id)
if vector_db.db_type == "Pinecone":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cant have if else for each db type can we have better structure.

from superagi.models.vector_db_config import VectordbConfig
from qdrant_client import models, QdrantClient

class QdrantHelper:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have these vector dbs in the vector_dbs. These classes does not make sense.


@classmethod
def delete_vector_index_config(cls, session, vector_index_id):
session.query(VectorIndexConfig).filter(VectorIndexConfig.vector_index_id == vector_index_id).delete()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no element found delete might throw exception

knowledge_details = dbhelper.get_knowledge_details(knowledge)
query_knowledge = KnowledgeToolHelper()

if knowledge_details["knowledge_vector_db_type"] == "Pinecone":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get a better way than if else

description = Column(String)
summary = Column(String)
readme = Column(String)
index_id = Column(Integer)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector_db_index_id

from superagi.models.base_model import DBBaseModel


class VectorIndexConfig(DBBaseModel):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean up the file_name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vector_db_index_configs

Copy link
Contributor

@DMTarmey DMTarmey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers

Copy link
Contributor

@DMTarmey DMTarmey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers

@nborthy nborthy closed this Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants