Skip to content

Commit

Permalink
db updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hk669 committed Jun 14, 2024
1 parent 811a27a commit 11b13c4
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions chroma/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import chromadb
import random

# Recommendations
def recommend(user_details, repos):
recommendations =[]

# starting a database
client = chromadb.Client()

collection = client.get_or_create_collection("projects")

# iterate through every project of the user
projects = list(repos.values())
for project in projects:
document = f"{project['full_name']} : {project['description']}"

# add the data to the DB
collection.add(
documents = [document],
ids = [project['full_name']],
)

for user_proj in user_details:
new_doc = f"{user_proj['project_name']} : {user_proj['description']}"
results = collection.query(
query_texts = [new_doc],
n_results = 4,
)
try:
# recommending the repos in random
recommended_proj_id = random.choice(results['ids'][0])
recommendations.append(f"https://www.github.com/{recommended_proj_id}")

# if not found any repo "no repos found"
except IndexError:
print(f"No recommendations found for projects{user_proj['project_name']}")
continue
return recommendations


0 comments on commit 11b13c4

Please sign in to comment.