-
Notifications
You must be signed in to change notification settings - Fork 731
Move Qdrant to the cloud version #320
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
76 changes: 23 additions & 53 deletions
76
premium/eagle-eye/crowd-eagle-eye/crowd/eagle_eye/sync.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,34 @@ | ||
| from pprint import pprint as pp | ||
| from crowd.eagle_eye.apis.vector_api import VectorAPI | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole file is temporary |
||
| from crowd.eagle_eye.apis.embed_api import EmbedAPI | ||
| from crowd.eagle_eye.models import Vector, Payload | ||
| import json | ||
| import pinecone | ||
| import os | ||
| from qdrant_client.http import models | ||
|
|
||
|
|
||
| import dotenv | ||
| found = dotenv.find_dotenv(".env.sync") | ||
| dotenv.load_dotenv(found) | ||
|
|
||
| vector_out = VectorAPI(do_init=False, cloud=False) | ||
| print("Vector out initialised. It has {} vectors".format(vector_out.count())) | ||
| vector_in = VectorAPI(do_init=True, cloud=True) | ||
| print("Vector in initialised") | ||
|
|
||
| pinecone.init(api_key=os.environ.get("PINECONE_API_KEY"), environment="us-east-1-aws") | ||
| index = pinecone.Index("crowddev-prod") | ||
| filters = [ | ||
| {"platform": {"$in": ["hacker_news"]}, "timestamp": {"$gt": 1666681782}}, | ||
| {"platform": {"$in": ["devto"]}, "timestamp": {"$gt": 1666681782}} | ||
| ] | ||
|
|
||
| for filter in filters: | ||
| query_response = index.query( | ||
| top_k=10000, | ||
| include_values=False, | ||
| include_metadata=True, | ||
| vector=[0.0] * 2048, | ||
| filter=filter | ||
| ) | ||
|
|
||
| print('Number of results from Pinecone:', len(query_response['matches'])) | ||
|
|
||
| vectors = [] | ||
|
|
||
| vectorAPI = VectorAPI(do_init=True) | ||
| embedAPI = EmbedAPI() | ||
| number = vector_out.count() | ||
| offset = None | ||
|
|
||
| for i, match in enumerate(query_response['matches']): | ||
| if i and i % 100 == 0: | ||
| vectorAPI.upsert(vectors) | ||
| vectors = [] | ||
| print('Processing match', i) | ||
| print('Number of vectors in Qdrant:', vectorAPI.count()) | ||
| while True: | ||
| vectors = vector_out.scroll(offset) | ||
|
|
||
| text = match['metadata']['text'] | ||
| if match['metadata']['platform'] == 'hacker_news': | ||
| if len(match['metadata']['text']) > 200: | ||
| text = match['metadata']['url'] | ||
| vectors_to_add = [ | ||
| models.PointStruct( | ||
| id=vector.id, | ||
| payload=vector.payload, | ||
| vector=vector.vector, | ||
| ) for vector in vectors[0] | ||
| ] | ||
| vector_in.upsert(vectors_to_add, processed=True) | ||
|
|
||
| sourceId_with_platform = match['metadata']['sourceId'] | ||
| sourceId = sourceId_with_platform[sourceId_with_platform.find(':') + 1:] | ||
| payload = Payload( | ||
| id=sourceId, | ||
| platform=match['metadata']['platform'], | ||
| title=match['metadata']['title'], | ||
| username=match['metadata']['username'], | ||
| timestamp=match['metadata']['timestamp'], | ||
| destination_url=match['metadata']['destination_url'], | ||
| url=match['metadata']['url'], | ||
| text=text, | ||
| postAttributes=json.loads(match['metadata'].get('postAttributes', {})), | ||
| userAttributes=json.loads(match['metadata'].get('userAttributes', {})) | ||
| ) | ||
| combined = f'{match["metadata"]["title"]} {text}' | ||
| vector = Vector(sourceId, payload, combined, embedAPI.embed_one(combined)) | ||
| vectors.append(vector) | ||
| offset = vectors[-1] | ||
| if not offset: | ||
| break | ||
| print(f"Synced {vector_in.count()} of {number} vectors") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check will be removed. I need this only for syncing after merge