rahul27474's picture
v1.2 card + pip wheel
7e35eeb verified
|
Raw History Blame Contribute Delete
5.04 kB
# 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).