This model is the
GGUF q8_0 (8-bit quantized) variant of the
gemma-300m-electrical-electronics-ir family, fine-tuned from
unsloth/embeddinggemma-300m for dense Information Retrieval (IR) in the electrical and electronics engineering domain. This build offers a near-lossless quality at roughly
half the size of the f16 GGUF (~329 MB vs ~612 MB), making it ideal for deployments where high accuracy and moderate memory footprint are both important.
The model was trained on the
disham993/ElectricalElectronicsIR dataset — 20,000 question-passage pairs covering electrical engineering, electronics, power systems, and communications.
Load this model in
LM Studio and use it via the built-in OpenAI-compatible server:
1from openai import OpenAI
2
3client = OpenAI(base_url="http://127.0.0.1:1234/v1", api_key="lm-studio")
4
5texts = [
6 "What is impedance matching?",
7 "Impedance matching maximises power transfer by equalising source and load impedance.",
8 "An LLC resonant converter achieves zero-voltage switching using an LC tank circuit.",
9]
10
11response = client.embeddings.create(
12 model="text-embedding-electrical-embeddinggemma-ir",
13 input=texts,
14)
15
16for item in response.data:
17 print(f"[{item.index}] dim={len(item.embedding)} first5={item.embedding[:5]}")
1# Install dependencies
2pip install huggingface_hub
3CMAKE_ARGS="-DGGML_CUDA=on" FORCE_CMAKE=1 pip install llama-cpp-python # (For NVIDIA GPU acceleration)
1import torch
2import torch.nn.functional as F
3from huggingface_hub import hf_hub_download, HfApi
4from llama_cpp import Llama
5
6class DummyModelCardData:
7 def set_evaluation_metrics(self, *args, **kwargs): pass
8
9class GGUFEmbeddingWrapper:
10 def __init__(self, repo_id):
11 self.repo_id = repo_id
12 # Automatically detect the GGUF file in the repo
13 api = HfApi()
14 files = api.list_repo_files(repo_id)
15 gguf_file = next((f for f in files if f.endswith('.gguf')), None)
16 if not gguf_file: raise ValueError(f"No .gguf file found in disham993/electrical-electronics-gemma-ir_q8_0")
17
18 print(f"Downloading/Using {gguf_file} from disham993/electrical-electronics-gemma-ir_q8_0...")
19 model_path = hf_hub_download(repo_id=repo_id, filename=gguf_file)
20
21 self.llm = Llama(
22 model_path=model_path,
23 embedding=True, # CRITICAL: Required for dense extraction
24 n_gpu_layers=-1, # Offload completely to GPU (Optional)
25 n_ctx=1024, # Constrain context window
26 verbose=False
27 )
28 self.dtype = torch.float16
29 self.model_card_data = DummyModelCardData() # Bypasses evaluator metadata crashes
30
31 def encode(self, sentences, batch_size=None, **kwargs):
32 convert_to_tensor = kwargs.pop('convert_to_tensor', True)
33 if isinstance(sentences, str): sentences = [sentences]
34
35 # Handling list of dicts for corpus evaluations
36 if isinstance(sentences, list) and len(sentences) > 0 and isinstance(sentences[0], dict):
37 sentences = [(doc.get("title", "") + " " + doc.get("text", "")).strip() for doc in sentences]
38
39 embeddings = []
40 for text in sentences:
41 res = self.llm.create_embedding(text)
42 embeddings.append(res['data'][0]['embedding'])
43
44 tensors = torch.tensor(embeddings, dtype=torch.float32)
45 if convert_to_tensor:
46 if torch.cuda.is_available(): tensors = tensors.cuda()
47 return tensors
48 return tensors.cpu().numpy()
49
50 # Dynamic alias interceptor to satisfy strict evaluator engines
51 def __getattr__(self, name):
52 if name.startswith("encode_"):
53 def wrapper(*args, **kwargs):
54 kwargs['convert_to_tensor'] = True
55 return self.encode(*args, **kwargs)
56 return wrapper
57 raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
58
59
60# === SEMANTIC SEARCH EXAMPLE ===
61if __name__ == "__main__":
62 # Boot the wrapper dynamically against this Hub Repo
63 model = GGUFEmbeddingWrapper("disham993/electrical-electronics-gemma-ir_q8_0")
64
65 query = "How do transformers step up voltage?"
66
67 # A miniature corpus of 10 engineering documents
68 documents = [
69 "Ohm's law defines the relationship between voltage, current, and resistance.",
70 "AC circuits use alternating current which changes direction periodically.",
71 "A step-up transformer has more turns on its secondary coil than its primary, increasing voltage.",
72 "Capacitors store electrical energy in an electric field.",
73 "Inductors resist changes in electric current passing through them.",
74 "Transformers operate on Faraday's law of induction to transfer energy between circuits.",
75 "Diodes allow current to pass in only one direction.",
76 "Voltage is the electric potential difference between two points.",
77 "A step-down transformer decreases voltage for safe residential use.",
78 "Power is the rate at which electrical energy is transferred by a circuit."
79 ]
80
81 print("Embedding query and documents...")
82 query_emb = model.encode(query)
83 doc_embs = model.encode(documents)
84
85 similarities = F.cosine_similarity(query_emb, doc_embs)
86 top_3_idx = torch.topk(similarities, k=3).indices.tolist()
87
88 print(f"\n--- Top 3 Documents for Query: '{query}' ---")
89 for rank, idx in enumerate(top_3_idx, 1):
90 print(f"Rank {rank} (Score: {similarities[idx]:.4f}) | {documents[idx]}")
While this model performs exceptionally well in the electrical and electronics engineering domain, it is not designed for use in other domains. Additionally, it may:
This model is intended for research, educational, and production IR applications in the electrical engineering domain.
For the complete fine-tuning and evaluation pipeline — from data loading to GGUF export — refer to the
GitHub repository and the notebooks
Finetuning_EmbeddingGemma_EEIR_RTX_5090.ipynb and
Evaluate_All_Models.ipynb.
1@misc{electrical-embeddinggemma-ir,
2 author = {disham993},
3 title = {Electrical \& Electronics Engineering Embedding Models},
4 year = {2026},
5 howpublished = {\url{https://huggingface.co/collections/disham993/electrical-and-electronics-engineering-embedding-models}},
6}