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

Fixed Chromadb not deleting documents #110

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions tests/view_chromadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,49 @@

def main():
chroma_path = get_or_make_chroma_path()
search = sys.argv[1]
search_collections(chroma_path, search)
view_collections(chroma_path)
# search = "nural networks"
# search_collections(chroma_path, search)

# view_by_channel_id("")
# delete_stuff()

def view_collections(chroma_path):
chroma_client = chromadb.PersistentClient(path=chroma_path)
collection = chroma_client.get_collection(name="subEmbeddings")
# print(collection.peek())
print(collection.peek())
print(collection.count())


def view_by_channel_id(channel_id):
chroma_path = get_or_make_chroma_path()
chroma_client = chromadb.PersistentClient(path=chroma_path)

collection = chroma_client.get_collection(name="subEmbeddings")


# collection.get({
# include: [ "documents" ]
# })

# chroma_res = collection.query(
# query_texts=["networks"],
# n_results=5,
# where={"channel_id": channel_id})

# pprint(chroma_res)



def delete_stuff():
chroma_path = get_or_make_chroma_path()
chroma_client = chromadb.PersistentClient(path=chroma_path)
collection = chroma_client.get_collection(name="subEmbeddings")

collection.delete(
where={"channel_id": "UCF0ZSm2AmSkJ2b2sLMlgLFg"}
)

def search_collections(chroma_path, text):
chroma_client = chromadb.PersistentClient(path=chroma_path)
collection = chroma_client.get_collection(name="subEmbeddings")
Expand Down
8 changes: 5 additions & 3 deletions yt_fts/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def get_channel_name_from_video_id(video_id):
def delete_channel(channel_id):

from .utils import check_ss_enabled
from .vector_search import delte_channel_from_chroma_db
from .vector_search import delete_channel_from_chroma

conn = sqlite3.connect(get_db_path())
cur = conn.cursor()
Expand All @@ -167,13 +167,15 @@ def delete_channel(channel_id):
cur.execute("DELETE FROM Subtitles WHERE video_id IN (SELECT video_id FROM Videos WHERE channel_id = ?)", (channel_id,))

cur.execute("DELETE FROM Videos WHERE channel_id = ?", (channel_id,))

if check_ss_enabled(channel_id):
delete_channel_from_chroma(channel_id)

cur.execute("DELETE FROM SemanticSearchEnabled WHERE channel_id = ?", (channel_id,))

conn.commit()
conn.close()

if check_ss_enabled(channel_id):
delte_channel_from_chroma_db(channel_id)


def get_channel_id_from_rowid(rowid):
Expand Down
8 changes: 6 additions & 2 deletions yt_fts/vector_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ def print_vector_search_results(res):



def delte_channel_from_chroma_db(channel_id):
def delete_channel_from_chroma(channel_id):
chroma_path = get_or_make_chroma_path()
chroma_client = chromadb.PersistentClient(path=chroma_path)
collection = chroma_client.get_collection(name="subEmbeddings")
collection.delete(where={"channel_id": channel_id})

print(f"deleting channel {channel_id} from chroma")
collection.delete(
where={"channel_id": channel_id}
)