I want to train my Discovery collection where I have already uploaded over 200 documents. I uploaded these documents through the GUI. Looking through the Discovery documentation, I know that I have will have to make API calls to train my collection since the training API has not been exposed through the GUI yet. As part of the training API calls I need to include a document that looks like this:
{
"natural_language_query": "{natural_language_query}",
"filter": "{filter_definition}"
"examples": [
{
"document_id": "{document_id_1}",
"cross_reference": "{cross_reference_1}",
"relevance": 0
},
{
"document_id": "{document_id_2}",
"cross_reference": "{cross_reference_2}",
"relevance": 0
}
]
}
My question is how should I get the documentIds for the documents that I have already uploaded? Is there a way to find this through the GUI? Or perhaps an API call that will return something like:
{
"document_name" = "MyDocument1",
"documentId" = "the_document_id_for_MyDocument1"
},
...
{
"document_name" = "MyDocumentN",
"documentId" = "the_document_id_for_MyDocumentN"
}
Or would the only way to get the documentIds would be to create a new collection and upload all of the documents through API calls directly and track the documentIds as I get them back?
Using the GUI, perform the following steps:
Input term(_id) in the "Group query results (Aggregation)"
textbox.
Under "Fields to return", select "Specify" to input
extracted_metadata
Note, that query and filter inputs should remain empty
Related
I have a functional prototype of an app that does the following :
A user calls a page on an app that creates a basic record for an object in a Firestore DB collection
A Firebase Function gets triggered by the "create" event
The function calls a GraphQL endpoint with a (pretty dense) query
The return of the query contains arrays of data that I want to feed back in the form of sub-collection in Firebase (and not nested arrays) for the same object
As of now and for the purpose of my initial tests, I run "for" loops that scan the data provided through the query and write those to the DB.
I am looking at saving on response times and Firestore usage metrics by optimising the code and would do with some help.
Here is an example of what I get back from the GraphQL queries :
{
"data": {
"enrichObjectQuery": {
"guid": "itemRef",
"oneOfTheDataElements": [
{
"date": "2022-01-31",
"value": 15
},
{
"date": "2022-07-31",
"value": 18
},
{
"date": "2022-12-16",
"value": 12
}
]
}
}
}
And here is an example of the code I use to inject data into Firestore. I rushed into doing something functional but I find the overall execution time to be long. The architecture is of course far from being optimal but I am pretty sure my code is part of the problem.
This is just an example and I have several of these for different data elements. Hope I did not mess anything up by making a generic example.
// enrich an object
for (let i = 0; i < data.enrichObjectQuery.oneOfTheDataElements.length; i++) {
const date = new Date(data.enrichObjectQuery.oneOfTheDataElements[i].date);
const timestamp = admin.firestore.Timestamp.fromDate(date);
db.collection("enrichObjectQuery")
.doc(data.enrichObjectQuery.guid)
.collection("oneOfTheDataElements")
.doc(data
. enrichObjectQuery.guid+data
. enrichObjectQuery.oneOfTheDataElements[i].date)
.set({
date: timestamp,
value: data.enrichObjectQuery.oneOfTheDataElements[i].value,
}, {merge: true});
}
Basically, it is doing what it is expected to do at this point.
I am now looking at optimising/refactoring all this to have the fastest and lightest code as possible... and looking for suggestions! My idea would be to avoid "loops" and inject directly an array as a sub-collection in Firestore but I am not sure to see how to do this.
(As you have probably guessed by now, I am bit of a beginner in this)
I'm looking for a way to add/remove data from an ArrayValue field, via the Firestore REST API.
I'm able to send the following PATCH request, to set all values of an array fields in a document, via the following:
Request Url
/v1beta1/projects/MY_APP/databases/(default)/documents/MY_COLLECTION/MY_DOCUMENT_ID?updateMask.fieldPaths=document_array&key=MY_KEY
Request Body
{
"fields" : {
"document_array" : {
"arrayValue" : {
"values" : [
{ "stringValue" : "item_value_0" },
{ "stringValue" : "item_value_1" }
]
}
}
}
}
As expected, the document with id MY_DOCUMENT_ID in collection MY_COLLECTION updates so that the document_array field is populated with strings:
['item_value_0', 'item_value_1'].
Using the REST APIs PATCH method, I would like to add/remove/update/manipulate ArrayValue fields in my document MY_DOCUMENT_ID (ie as outlined in this question).
Is this possible? If so, how?
Thanks in advance
It's not possible today. You could file a feature request stating what you want (it's been asked before).
Dolibarr has a module for restful APIs.
The API explorer seems to show all the CRUD tasks for each module like orders, stock and customer.
But to CREATE a record, the sample VALUE for the POST method shows as:
{
"request_data": [
"string"
]
}
What are the specific field attributes that should go in here?
Where can I look up the field requirements?
You should take a look at the attributes of the Commande class:
https://github.com/Dolibarr/dolibarr/blob/develop/htdocs/commande/class/commande.class.php
The object should be something like this :
{
"date_commande" : "0000-00-00 00:00:00",
"date_livraison" : "0000-00-00 00:00:00",
"attribute3": "and so on"
}
When you need a parameter like
{ "request_data": [ "string" ] } for a POST API, all you have to do is to call the similar API to get a record (so the same API with the GET method). The result can be cut and paste to be used to create a new record (just change the id and ref in the answer retreived by the GET).
Can anyone tell me why when I use DataExplorer for CosmoDb DB I get the following:
{
"id": "d502b51a-e70a-40f1-9285-3861880b8d90",
"Version": 1,
...
}
But when I use Robomongo I get:
{
"Version" : 1,
...
}
minus the id?
Thanks
I tried to repro your scenario but it all worked correctly.
The Mongo document in Portal Data Explorer:
The Mongo document in Robo 3T:
They both have the id property.
Are you applying Projections on Robomongo / Robo 3T?
At this moment cosmodb works separately SQL API and Mongo API, each one has different implementation, SQL API use JSON and Mongo use BSON, you need to be clear this while you are creating the document.
If you create the document with a BSON-based tool like Robo3t for example, you are going to get something like this:
{
"_id": {
"$oid": "5be0d98b9cdcce3c6ce0f6b8"
},
"name": "Name",
"id": "5be0d98b9cdcce3c6ce0f6b8",
...
}
Instead, if you create your document with JSON-based like Data Explorer, you are going to get this:
{
"name": "Name",
"id": "6c5c05b4-dfce-32a5-0779-e30821e6c510",
...
}
As you can see, BSON-based needs that _id and inside $oid be implemented to works right, while JSON-based only id is required. So, you need to add the properties while you save the document (see below) or open it with the right tool, as Matias Quaranta recommend, use Azure Storage Explorer or even Data Explorer to get both protocols properly.
Also, if you use a system to create the document and you want to use BSON format, You need to add the $oid, for example in core net is something like this:
public bool TryGetMemberSerializationInfo(string memberName, out BsonSerializationInfo serializationInfo)
{
switch (memberName)
{
case "Id":
serializationInfo = new BsonSerializationInfo("_id", new ObjectIdSerializer(), typeof(ObjectId));
return true;
case "Name":
serializationInfo = new BsonSerializationInfo("name", new StringSerializer(), typeof(string));
return true;
default:
serializationInfo = null;
return false;
}
}
I am trying to write a REST Api using CakePHP 3.
I have two tables Documents and DocumentImages, when I send POST request with body:
{
"description": "Short Desc.",
"company_id": 2,
"department_id": 3,
"status": 0,
"document_images":[
{
"base64" : "xyz"
},
{
"base64" : "abc"
}
]
}
It saves both to Documents and DocumentImages and makes the document_id of images as it must be.
Now, I need to do something after saving the document and before saving the images, however beforeSave function in images never be called, so it saves both of the entities in DocumentsController.
What can I do for catch the event after the document saved but before the images save?
By the way, if anyone suggest a solution using CRUD I will be very appreciate.