2024-10-03 01:53:37 +00:00
|
|
|
from typesense.exceptions import TypesenseClientError, ObjectAlreadyExists
|
2024-07-19 00:04:51 +00:00
|
|
|
|
2024-10-03 01:53:37 +00:00
|
|
|
from utils.typesense_client import client
|
|
|
|
|
|
|
|
# Create a collection
|
|
|
|
try:
|
|
|
|
client.collections.create({
|
|
|
|
'name': 'social_media_posts',
|
|
|
|
'fields': [
|
|
|
|
{'name': 'id', 'type': 'string'},
|
|
|
|
{'name': 'network', 'type': 'string', 'facet': True},
|
|
|
|
{'name': 'type', 'type': 'string', 'facet': True},
|
|
|
|
{'name': 'index', 'type': 'string', 'facet': True},
|
|
|
|
{'name': 'chemin', 'type': 'string'},
|
|
|
|
{'name': 'texte', 'type': 'string'},
|
|
|
|
{'name': 'creation_timestamp', 'type': 'int64'},
|
|
|
|
{
|
|
|
|
"name" : "embedding",
|
|
|
|
"type" : "float[]",
|
|
|
|
"embed": {
|
|
|
|
"from": [
|
|
|
|
"texte"
|
|
|
|
],
|
|
|
|
"model_config": {
|
|
|
|
"model_name": "ts/multilingual-e5-small"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
'default_sorting_field': 'creation_timestamp'
|
|
|
|
})
|
|
|
|
print("Collection 'social_media_posts' created successfully.")
|
|
|
|
except TypesenseClientError as e:
|
|
|
|
if e==ObjectAlreadyExists:
|
|
|
|
print("Collection 'social_media_posts' already exists. Skipping creation.")
|
|
|
|
else:
|
|
|
|
print(f"Error creating collection: {str(e)}")
|
|
|
|
raise
|
2024-07-19 00:04:51 +00:00
|
|
|
|
|
|
|
|