Methods
call(user, queryopt, filtersopt, document_idsopt, top_n_keywordsopt, top_n_natural_languageopt, date_fromopt, date_untilopt) → {Promise.<Object>}
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
user |
string | The ID of the user accessing the Soffos API. Soffos assumes that the owner of the api is an application (app) and that app has users. Soffos API will accept any string. | ||
query |
object |
<optional> |
null | Required when top_n_natural_language is set above 0. The text to be used to match passages from ingested documents. This could be anything from a very specific natural language question to a simple cobination of words for keyword search. It can also be set as null for only-filtering searches. |
filters |
object |
<optional> |
null | The filters field can be used to narrow down the search to only the documents meeting certain metadata-based criteria, or even returning all the filtered documents when query is left null. It is catering only for the metadata provided in the meta field when ingesting a document. Other important filters such as document_ids, date_from and date_until are provided as top level fields. Filters are defined as nested dictionaries. The keys of the dictionaries can be a logical operator ("$and", "$or", "$not"), a comparison operator ("$eq", "$in", "$gt", "$gte", "$lt", "$lte") or a metadata field name. Logical operator keys have a dictionary of metadata field names and/or logical operators as their value. Metadata field names have a dictionary of comparison operators as their value. Comparison operator keys accept a single values or lists as their values. Lists can be compared with the with the "$in" operator against single values, or with the "$eq" operator against other lists in which case the set of values of each list is compared and order does not matter. If no logical operator is given, "$and" is used as the default operation. If no comparison operator is specified, "$eq" (or "$in" if the comparison value is a list) is used as the default operation. |
document_ids |
Array.<string> |
<optional> |
null | Passing document IDs will confine the search to those documents. |
top_n_keywords |
number |
<optional> |
5 | The number of document passages to be retrieved using keyword search. The relevancy is calculated algorithmically based on the frequency of the query words in the ingested passages. Setting this to 0 disables the keyword search. When query is left null while top_n_keywords is larger than 0, it will simply filter the documents based on the rest of the fields like date or metadata. All matched passages will be returned, therefore the actual value of top_n_keywords does not make a difference, so long it is larger than 0. |
top_n_natural_language |
number |
<optional> |
5 | The number of document passages to be retrieved using Machine Learning-based semantic search. Setting this to 0 disables the semantic search. |
date_from |
string |
<optional> |
null | Filters passages to those ingested at or after the specified ISO-8601 formatted date. |
date_until |
string |
<optional> |
null | Filters passages to those ingested before the specified ISO-8601 formatted date. |
- Source:
Returns:
passages - dictionary list
List of passages. Each passage contains the following data:
content: The raw text of the passage.
document_id: Origin document's ID.
created_at: Ingestion datetime.
name: Origin document's name.
scores: Dictionary containing the matching score of this passage to the query for each method that matched it.
meta: Dictionary with the metadata that were provided when the passage's origin document was ingested.
List of passages. Each passage contains the following data:
content: The raw text of the passage.
document_id: Origin document's ID.
created_at: Ingestion datetime.
name: Origin document's name.
scores: Dictionary containing the matching score of this passage to the query for each method that matched it.
meta: Dictionary with the metadata that were provided when the passage's origin document was ingested.
- Type
- Promise.<Object>
Example
import { SoffosServices } from "soffosai";
const my_apiKey = "Token <put your api key here>";
const service = new SoffosServices.DocumentsSearchService({apiKey:my_apiKey});
let response = await service.call(
"client 987654321", null, null, ["0d059b3bf66b4ecfa124c175a6d3cd45"]
);
console.log(JSON.stringify(response, null, 2));
// returns this if document_id exists and you own the document
// {
// "passages": [
// {
// "content": "Genetic evidence suggests that dogs descended directly from wolves (Canis) and that the now-extinct wolf lineages that produced dogs branched off from the line that produced modern living wolves sometime between 27,000 and 40,000 years ago. The timing and location of dog domestication is a matter of debate. There is strong genetic evidence,
// however, that the first domestication events occurred somewhere in northern Eurasia between 14,000 and 29,000 years ago.",
// "created_at": "2023-09-13T09:38:00.807895",
// "document_id": "0d059b3bf66b4ecfa124c175a6d3cd45",
// "name": "dogs",
// "scores": [
// {
// "keyword": 0.5312093733737563
// }
// ],
// "meta": {}
// }
// ],
// "cost": {
// "api_call_cost": 0,
// "character_volume_cost": 0,
// "total_cost": 0
// },
// "charged_character_count": 0,
// "unit_price": "0.000000"
// }
setInputConfigs(name, queryopt, filtersopt, document_idsopt, top_n_keywordsopt, top_n_natural_languageopt, date_fromopt, date_untilopt)
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | Reference name of this Service. It will be used by the Pipeline to reference this Service. It will be used by the Pipeline to reference this Node. | ||
query |
object | InputConfig |
<optional> |
null | Required when top_n_natural_language is set above 0. The text to be used to match passages from ingested documents. This could be anything from a very specific natural language question to a simple cobination of words for keyword search. It can also be set as null for only-filtering searches. |
filters |
object | InputConfig |
<optional> |
null | The filters field can be used to narrow down the search to only the documents meeting certain metadata-based criteria, or even returning all the filtered documents when query is left null. It is catering only for the metadata provided in the meta field when ingesting a document. Other important filters such as document_ids, date_from and date_until are provided as top level fields. Filters are defined as nested dictionaries. The keys of the dictionaries can be a logical operator ("$and", "$or", "$not"), a comparison operator ("$eq", "$in", "$gt", "$gte", "$lt", "$lte") or a metadata field name. Logical operator keys have a dictionary of metadata field names and/or logical operators as their value. Metadata field names have a dictionary of comparison operators as their value. Comparison operator keys accept a single values or lists as their values. Lists can be compared with the with the "$in" operator against single values, or with the "$eq" operator against other lists in which case the set of values of each list is compared and order does not matter. If no logical operator is given, "$and" is used as the default operation. If no comparison operator is specified, "$eq" (or "$in" if the comparison value is a list) is used as the default operation. |
document_ids |
Array.<string> | InputConfig |
<optional> |
null | Passing document IDs will confine the search to those documents. |
top_n_keywords |
number | InputConfig |
<optional> |
5 | The number of document passages to be retrieved using keyword search. The relevancy is calculated algorithmically based on the frequency of the query words in the ingested passages. Setting this to 0 disables the keyword search. When query is left null while top_n_keywords is larger than 0, it will simply filter the documents based on the rest of the fields like date or metadata. All matched passages will be returned, therefore the actual value of top_n_keywords does not make a difference, so long it is larger than 0. |
top_n_natural_language |
number | InputConfig |
<optional> |
5 | The number of document passages to be retrieved using Machine Learning-based semantic search. Setting this to 0 disables the semantic search. |
date_from |
string | InputConfig |
<optional> |
null | Filters passages to those ingested at or after the specified ISO-8601 formatted date. |
date_until |
string | InputConfig |
<optional> |
null | Filters passages to those ingested before the specified ISO-8601 formatted date. |
- Source: