File size: 5,037 Bytes
7e35eeb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# hinglish-embed

Text embeddings for **Hinglish** (`bhai refund kab aayega`), **Hindi** (`रिफंड कब आएगा`) and **English**, in one `pip install`.

- Runs on a normal CPU. It needs no GPU, no PyTorch and no API key.
- One query takes ~11 ms, and the model is a 38 MB download.
- It comes with ready-made helpers for search, FAQ bots, duplicate detection and RAG.

The model is [rahul27474/hinglish-embed-small](https://huggingface.co/rahul27474/hinglish-embed-small). You can try it in the browser on the [demo page](https://huggingface.co/spaces/rahul27474/hinglish-embed-small-demo).

## Install

```bash
pip install https://huggingface.co/rahul27474/hinglish-embed-small/resolve/main/python/hinglish_embed-0.1.0-py3-none-any.whl
```

The first run downloads the model once, about 38 MB. After that it works offline.

## Search in 3 lines

```python
from hinglish_embed import HinglishEmbed

model = HinglishEmbed()
index = model.index(["UPI payment fail hone par paise 3-5 din me wapas aate hain.",
                     "Order return karne ke liye app me 'My Orders' kholo.",
                     "बिजली बिल ज्यादा आने पर मीटर रीडिंग चेक करें।"])
print(index.search("bhai upi se paise kat gaye", k=2))
```

To avoid re-embedding the documents every time, save the index with `index.save("faq.npz")` and load it later with `Index.load("faq.npz", model)`.

## FAQ / support chatbot

```python
faq = model.faq({
    "refund kab aayega":            "Refund 5-7 working days me aapke account me aa jayega.",
    "order cancel kaise kare":      "My Orders > Cancel par tap karein.",
    "delivery late kyun hai":       "Aapka order 2 din me deliver hoga.",
})
print(faq.ask("mera paisa wapas kab milega", default="Sorry, agent se baat karein."))
```

## Duplicate questions or tickets

```python
tickets = ["app crash ho raha hai", "App baar baar band ho jata hai", "password reset kaise kare"]
for i, j, score in model.find_duplicates(tickets, threshold=0.80):
    print(score, tickets[i], "<->", tickets[j])
```

## Other helpers

```python
model.similarity("mera refund kab aayega", "When will I get my money back?")   # 0..1
model.is_related(a, b)                                                       # True if >= 0.72
model.best_match("paise kat gaye", ["payment issue", "delivery issue", "login issue"])
model.encode(texts, kind="passage")                                          # numpy array (n, 384)
```

**Score guide:**

- Sentence vs sentence (`similarity`, FAQ, duplicates): 0.72 and above usually means related, and 0.80 and above usually means the same question.
- Query vs document (`search`): relevant documents usually score 0.70–0.90. A document below 0.60 is almost never relevant, so you can drop it with `index.search(q, min_score=0.6)`.

These are guides, not guarantees, so check them on a few of your own examples.

## RAG with LangChain

```bash
pip install "hinglish-embed[langchain] @ https://huggingface.co/rahul27474/hinglish-embed-small/resolve/main/python/hinglish_embed-0.1.0-py3-none-any.whl"
```

```python
from hinglish_embed.langchain import HinglishEmbeddings
from langchain_core.vectorstores import InMemoryVectorStore   # or Chroma, FAISS, Qdrant, ...

store = InMemoryVectorStore.from_texts(my_texts, HinglishEmbeddings())
docs = store.similarity_search("emi kaise band kare", k=3)
```

## RAG with LlamaIndex

```python
from llama_index.core import Settings
from hinglish_embed.llamaindex import HinglishEmbedding
Settings.embed_model = HinglishEmbedding()
```

## As an API server (n8n, Flowise, Dify, any language)

```bash
hinglish-embed serve --port 8000            # add --host 0.0.0.0 --api-key SECRET to expose it
```

This gives you an OpenAI-compatible endpoint at `http://localhost:8000/v1/embeddings`. Any tool that accepts an "OpenAI embeddings base URL" can use it:

```python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
client.embeddings.create(model="hinglish-embed-query", input=["refund kab aayega"])
```

The `model` field picks how the text is embedded:

- `hinglish-embed-query` (the default) is for questions and short texts.
- `hinglish-embed-passage` is for documents you search over.

## Command line

```bash
hinglish-embed similar "mera refund kab aayega" "When will I get my money back?"
hinglish-embed search faq.txt "paise kat gaye"        # one document per line
hinglish-embed dupes tickets.txt --threshold 0.80
```

## JavaScript / browser

You don't need this package for JavaScript. Use transformers.js directly:

```js
import { pipeline } from '@huggingface/transformers';
const embed = await pipeline('feature-extraction', 'rahul27474/hinglish-embed-small', { dtype: 'q8' });
const out = await embed(['query: refund kab aayega'], { pooling: 'mean', normalize: true });
```

## License

The code is MIT and the model is MIT. The model was fine-tuned and vocab-trimmed from `intfloat/multilingual-e5-small` (MIT).