Created
August 1, 2023 14:47
-
-
Save srbhr/d6061a5cb53e5051696e33b0531a7d3f to your computer and use it in GitHub Desktop.
Resume Matcher Cohere Embeddings Integration with Qdrant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """Resume-Matcher-Cohere-Embeddings-Alpha.ipynb | |
| Automatically generated by Colaboratory. | |
| """ | |
| !pip install cohere --quiet | |
| !pip install qdrant-client --quiet | |
| COHERE_API_KEY = "API_KEY" | |
| QDRANT_API_KEY = "API_KEY" | |
| import cohere | |
| cohere_client = cohere.Client(COHERE_API_KEY) | |
| embeddings = cohere_client.embed( | |
| texts=["A test sentence"], | |
| model="large", | |
| ) | |
| vector_size = len(embeddings.embeddings[0]) | |
| vector_size | |
| from qdrant_client import QdrantClient | |
| from qdrant_client import models | |
| from qdrant_client.http import models as rest | |
| from qdrant_client.http.models import Batch | |
| qdrant_client = QdrantClient( | |
| "https://test-test-test", | |
| prefer_grpc=True, | |
| api_key="API_KEY", | |
| ) | |
| qdrant_client.recreate_collection( | |
| collection_name="resume-matcher", | |
| vectors_config=models.VectorParams( | |
| size=vector_size, | |
| distance=rest.Distance.COSINE | |
| ), | |
| ) | |
| qdrant_client.upsert( | |
| collection_name="resume-matcher", | |
| points=Batch( | |
| ids=[1], | |
| vectors=[ | |
| list(map(float, vector)) | |
| for vector in cohere_client.embed( | |
| model="large", | |
| texts=["The best vector database"], | |
| ).embeddings | |
| ], | |
| ) | |
| ) | |
| embeddings = cohere_client.embed( | |
| model="large", | |
| texts=["The best vector database"], | |
| ).embeddings | |
| first_vector = embeddings[0] | |
| query_vector = list(map(float, first_vector)) | |
| hits = qdrant_client.search( | |
| collection_name="resume-matcher", | |
| query_vector=query_vector, | |
| limit=3 | |
| ) | |
| for hit in hits: | |
| print(hit.payload, "score:", hit.score) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment