MCPcopy Create free account
hub / github.com/ScienciaLAB/document-qa / embed

Method embed

document_qa/custom_embeddings.py:32–60  ·  view source on GitHub ↗

Embed a list of texts via the configured API. Newlines are replaced with spaces before sending, since most embedding models treat them as noise. Args: text: Strings to embed. Returns: list[list[float]]: One embedding vector per input string.

(self, text: List[str])

Source from the content-addressed store, hash-verified

30 self.api_key = api_key
31
32 def embed(self, text: List[str]) -> List[List[float]]:
33 """Embed a list of texts via the configured API.
34
35 Newlines are replaced with spaces before sending, since most
36 embedding models treat them as noise.
37
38 Args:
39 text: Strings to embed.
40
41 Returns:
42 list[list[float]]: One embedding vector per input string.
43
44 Raises:
45 requests.HTTPError: If the API returns a non-2xx status.
46 """
47 # Newlines degrade embedding quality for most models
48 cleaned_text = [t.replace("\n", " ") for t in text]
49
50 payload = {"text": "\n".join(cleaned_text)}
51
52 headers = {}
53 if self.api_key:
54 headers = {"x-api-key": self.api_key}
55
56 response = requests.post(self.url, data=payload, files=[], headers=headers)
57 response.raise_for_status()
58
59 # print(response.text)
60 return response.json()
61
62 def embed_documents(self, text: List[str]) -> List[List[str]]:
63 """Embed multiple documents (LangChain interface).

Callers 3

embed_documentsMethod · 0.95
embed_queryMethod · 0.95

Calls 1

postMethod · 0.80

Tested by

no test coverage detected