Server Mode¶
Run LORG as a REST API server to integrate with other applications.
Starting the Server¶
With options:
Server Output¶
Lorg server running on port 3000
Health check: http://localhost:3000/health
Search endpoint: http://localhost:3000/search
API Endpoints¶
Health Check¶
Check if the server is running:
Response:
Search¶
Perform an AI-powered search:
POST /search
Content-Type: application/json
{
"query": "What is machine learning?",
"model": "gpt-4o-mini",
"maxResults": 5
}
Parameters:
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
query | string | Yes | - | Search query |
model | string | No | gpt-4o-mini | OpenAI model |
maxResults | number | No | 5 | Max results |
Response:
{
"answer": "Machine learning is a subset of AI...",
"knowledgeGraph": {
"entities": ["machine learning", "AI", "algorithms"],
"relationships": [...]
},
"keywords": ["machine learning", "AI", "algorithms"],
"results": [
{
"answer": "...",
"source": "https://example.com",
"score": 0.95,
"content": "...",
"title": "Introduction to ML"
}
],
"tokenCount": 1523
}
Usage Examples¶
cURL¶
# Health check
curl http://localhost:3000/health
# Search
curl -X POST http://localhost:3000/search \
-H "Content-Type: application/json" \
-d '{"query": "What is quantum computing?"}'
JavaScript (fetch)¶
const response = await fetch('http://localhost:3000/search', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: 'What is quantum computing?',
maxResults: 5
})
});
const results = await response.json();
console.log(results.answer);
Python (requests)¶
import requests
response = requests.post(
'http://localhost:3000/search',
json={
'query': 'What is quantum computing?',
'maxResults': 5
}
)
results = response.json()
print(results['answer'])
Error Responses¶
Missing Query¶
Status Code: 400
Server Error¶
Status Code: 500
Deployment¶
Docker¶
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD ["npx", "lorg", "server"]
Build and run:
Process Manager (PM2)¶
Systemd Service¶
Create /etc/systemd/system/lorg.service:
[Unit]
Description=LORG Search API
After=network.target
[Service]
Type=simple
User=lorg
Environment=OPENAI_API_KEY=sk-your-key
ExecStart=/usr/bin/npx lorg server -p 3000
Restart=on-failure
[Install]
WantedBy=multi-user.target
Enable and start:
CORS¶
The server has CORS enabled by default, allowing requests from any origin.
Graceful Shutdown¶
The server handles SIGINT (Ctrl+C) gracefully:
Next Steps¶
- Library Usage - Use programmatically
- API Reference - Complete API docs