Copy
---
title: 최적화 및 양자화된 Embedder를 사용한 문서 임베딩
---
Quantized Embedder를 사용하여 모든 문서를 임베딩합니다.
embedder는 [optimum-intel](https://github.com/huggingface/optimum-intel.git)과 [IPEX](https://github.com/intel/intel-extension-for-pytorch)를 사용하여 생성된 최적화된 모델을 기반으로 합니다.
예제 텍스트는 [SBERT](https://www.sbert.net/docs/pretrained_cross-encoders.html)를 기반으로 합니다.
```python
from langchain_community.embeddings import QuantizedBiEncoderEmbeddings
model_name = "Intel/bge-small-en-v1.5-rag-int8-static"
encode_kwargs = {"normalize_embeddings": True} # set True to compute cosine similarity
model = QuantizedBiEncoderEmbeddings(
model_name=model_name,
encode_kwargs=encode_kwargs,
query_instruction="Represent this sentence for searching relevant passages: ",
)
Copy
loading configuration file inc_config.json from cache at
INCConfig {
"distillation": {},
"neural_compressor_version": "2.4.1",
"optimum_version": "1.16.2",
"pruning": {},
"quantization": {
"dataset_num_samples": 50,
"is_static": true
},
"save_onnx_model": false,
"torch_version": "2.2.0",
"transformers_version": "4.37.2"
}
Using `INCModel` to load a TorchScript model will be deprecated in v1.15.0, to load your model please use `IPEXModel` instead.
Copy
question = "How many people live in Berlin?"
Copy
documents = [
"Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.",
"Berlin is well known for its museums.",
]
Copy
doc_vecs = model.embed_documents(documents)
Copy
Batches: 100%|██████████| 1/1 [00:00<00:00, 4.18it/s]
Copy
query_vec = model.embed_query(question)
Copy
import torch
Copy
doc_vecs_torch = torch.tensor(doc_vecs)
Copy
query_vec_torch = torch.tensor(query_vec)
Copy
query_vec_torch @ doc_vecs_torch.T
Copy
tensor([0.7980, 0.6529])
Copy
---
<Callout icon="pen-to-square" iconType="regular">
[Edit the source of this page on GitHub.](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/text_embedding/optimum_intel.mdx)
</Callout>
<Tip icon="terminal" iconType="regular">
[Connect these docs programmatically](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
</Tip>