File size: 1,863 Bytes
76b352a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: Gemischtes Hack Embeddings
emoji: 🎙️
colorFrom: gray
colorTo: yellow
sdk: docker
app_port: 7860
pinned: false
---

# Embedding Server for Gemischtes Hack

FastAPI server hosting `intfloat/multilingual-e5-small` embeddings model on Hugging Face Spaces.

## Setup

1. Create a new HF Space: https://huggingface.co/new-space
   - Name: `gemischtes-hack-embed`
   - License: MIT
   - SDK: Docker

2. Clone this Space to your machine (or manually upload files)

3. The Docker container will:
   - Install dependencies from `requirements.txt`
   - Load the `multilingual-e5-small` model
   - Expose FastAPI on port 7860

4. Once deployed, the Space URL will be available at:
   `https://{your-username}-gemischtes-hack-embed.hf.space`

## API

### POST /embed
Generate embeddings for text.

```bash
curl -X POST https://{your-username}-gemischtes-hack-embed.hf.space/embed \
  -H "Content-Type: application/json" \
  -d '{"text": "Was ist Gemischtes Hack?"}'
```

Response:
```json
{
  "embedding": [0.123, -0.456, ..., 0.789]  // 384-dim vector
}
```

### GET /health
Check server status.

### GET /
View API info.

## Notes

- First request takes ~10-30 seconds (model loading + HF Spaces cold start)
- Subsequent requests take ~500ms
- Space auto-sleeps after 48 hours of inactivity
- Max 2 vCPU / 16 GB RAM (free tier)

## Integration

Update `web/src/lib/embed.ts`:

```typescript
const HF_SPACE_URL = "https://{your-username}-gemischtes-hack-embed.hf.space";

async function embedLocal(text: string): Promise<number[]> {
  const response = await fetch(`${HF_SPACE_URL}/embed`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ text }),
  });

  if (!response.ok) {
    throw new Error(`Embed error: ${response.status}`);
  }

  const data = await response.json();
  return data.embedding;
}
```