Skip to main content

Search Records

The Search Records API enables powerful semantic search of your database records with optional filtering. Results are always returned with the most relevant records first.

tip

This API uses AI language model embeddings to understand the meaning behind your search queries, not just matching keywords. When you search for "innovative solutions," it can find records about "groundbreaking approaches" or "creative answers" because it understands these concepts are related. Think of it as searching by meaning rather than exact words, similar to how humans understand context and meaning, unlike traditional search engines that primarily rely on exact keyword matching.

POST /v1/databases/{id}/search

Path Parameters

ParameterTypeRequiredDescription
idstringYesThe ID of your Lightfeed database

Request Body

The search API supports a simplified structure with separate fields for semantic search and filtering:

{
"search": {
"text": "innovative AI solutions",
"threshold": 0.2
},
"filter": {
"condition": "AND",
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"condition": "OR",
"rules": [
{
"column": "employees",
"operator": "greater_than",
"value": 100
},
{
"column": "funding_amount",
"operator": "greater_than",
"value": 1000000
}
]
}
]
},
"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
},
"pagination": {
"limit": 100,
"cursor": "0.23_1234"
}
}

Example Requests

This example shows how to perform a basic semantic search without any filters.

curl -X POST "https://api.lightfeed.ai/v1/databases/your-database-id/search" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"search": {
"text": "innovative AI solutions",
},
}'

Search with Filtering and Time Range

This example shows how to combine semantic search with filtering and time range constraints.

curl -X POST "https://api.lightfeed.ai/v1/databases/your-database-id/search" \
-H "x-api-key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"search": {
"text": "innovative AI solutions",
"threshold": 0.2
},
"filter": {
"condition": "AND",
"rules": [
{
"column": "industry",
"operator": "equals",
"value": "Finance"
},
{
"condition": "OR",
"rules": [
{
"column": "employees",
"operator": "greater_than",
"value": 100
},
{
"column": "funding_amount",
"operator": "greater_than",
"value": 1000000
}
]
}
]
},
"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
},
"pagination": {
"limit": 100
}
}'

Request Parameters

Search Object (Required)

The semantic search parameters to find records similar to your query text using vector embeddings.

"search": {
"text": "innovative AI solutions",
"threshold": 0.2
}
ParameterTypeRequiredDescription
textstringYesThe text to search for semantically
thresholdnumberNoMinimum relevance score threshold (0-1), default: 0.2. Lower values return more results

How it works: Semantic search converts your query text into a vector embedding and compares it with the embeddings of records in your database. The relevance score ranges from 0 to 1, where values closer to 1 indicate higher relevance. For most use cases, a threshold of 0.2 provides a good balance between precision and recall.

Filter Object (Optional)

Defines filtering conditions to apply to the records after semantic search. Filter uses a logical group structure:

"filter": {
"condition": "AND", // Optional, defaults to "AND" if not specified
"rules": [
// Array of field comparisons or nested logical groups
]
}

Field Comparison Rule

ParameterTypeRequiredDescription
columnstringYesDatabase column name to filter on
operatorstringYesComparison operator to use
valueanyYes*Value to compare against

*Not required for is_empty and is_not_empty operators.

Available Operators:

OperatorDescriptionExample Value Type
equalsExact matchString, Number, Boolean
not_equalsNot an exact matchString, Number, Boolean
greater_thanGreater than valueNumber
less_thanLess than valueNumber
greater_than_or_equalsGreater than or equal to valueNumber
less_than_or_equalsLess than or equal to valueNumber
containsString contains substringString
not_containsString does not contain substringString
starts_withString starts with substringString
ends_withString ends with substringString
is_emptyField is empty or nullNo value needed
is_not_emptyField is not empty or nullNo value needed

Logical Group Rule

ParameterTypeRequiredDescription
conditionstringNoLogical operator to apply: "AND" or "OR". Defaults to "AND"
rulesarrayYesArray of field comparisons or nested logical groups

Time Range (Optional)

Filter results based on the last seen time of records. If not specified, all records are included regardless of timestamp.

"time_range": {
"start_time": "2024-01-01T00:00:00Z",
"end_time": "2024-12-31T23:59:59Z"
}
ParameterTypeRequiredDescription
start_timestringNoISO 8601 timestamp for the start of the range
end_timestringNoISO 8601 timestamp for the end of the range

Pagination (Optional)

Control the number of results returned and navigate through large result sets.

"pagination": {
"limit": 100,
"cursor": "0.23_1234"
}
ParameterTypeRequiredDescription
limitnumberNoMaximum number of results to return (default: 50, max: 100)
cursorstringNoCursor for pagination (from previous response)

Example Response

{
"results": [
{
"id": 1345,
"relevance_score": 0.3,
"data": {
"company_name": "Acme Inc.",
"industry": "Finance",
"website": "https://acme.com",
"employees": 250,
"funding_amount": 5000000,
"is_public": false
},
"timestamps": {
"first_seen_time": "2022-03-15T14:22:13Z",
"last_changed_time": "2024-07-02T09:45:30Z",
"last_seen_time": "2024-10-01T18:30:45Z"
}
}
// Additional results...
],
"pagination": {
"limit": 100,
"next_cursor": "0.23_1234",
"has_more": true
}
}

Response Structure

The response will contain a list of records matching your search criteria, sorted by relevance score (most relevant first).

FieldTypeDescription
resultsarrayList of matching records
paginationobjectInformation for continued querying

Pagination Object

FieldTypeDescription
limitnumberThe requested limit parameter value from the original request
next_cursorstringToken to use for fetching the next page
has_morebooleanIndicates whether more results are available

Record Object

Each record in the results array has the following structure:

FieldTypeDescription
idnumberUnique identifier for the record
relevance_scorenumberRanges from 0 to 1, where values closer to 1 indicate higher relevance (only present if semantic search is applied)
dataobjectThe record's structured data
timestampsobjectTiming information for the record

Tips and Best Practices

Combining Search and Filters

When using both semantic search and filters, the API simultaneously evaluates both criteria to find the most relevant results that also match your filtering conditions. This integrated approach ensures optimal results that satisfy both semantic relevance and your specific filtering requirements.

  • Use natural language phrases rather than single keywords for better results
  • Start with a lower threshold (e.g., 0.2) and increase it if you get too many irrelevant results
  • Be specific in your search text to improve precision

Use the Right API

  • Use this Search API when you need to find records based on semantic relevance to text queries
  • Use the Filter API when you only need to filter records by exact criteria without semantic search