MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / generate_embeddings

Method generate_embeddings

core/src/embeddings/python_bridge.rs:129–160  ·  view source on GitHub ↗
(
        &self,
        request: EmbeddingRequest,
    )

Source from the content-addressed store, hash-verified

127 }
128
129 async fn generate_embeddings(
130 &self,
131 request: EmbeddingRequest,
132 ) -> GraphBitResult<EmbeddingResponse> {
133 let python_instance = Arc::clone(&self.python_instance);
134 let model = self.model.clone();
135
136 Python::with_gil(|py| {
137 // Convert input to appropriate format
138 let texts = request.input.as_texts();
139
140 // Call Python method: embed(model, text, **kwargs) for single text
141 // or embed_many(model, texts, **kwargs) for multiple texts
142 let result = if texts.len() == 1 {
143 // Single text - call embed(model, text)
144 python_instance
145 .call_method(py, "embed", (model.clone(), texts[0]), None)
146 .map_err(|e| GraphBitError::llm(format!("Python embed call failed: {e}")))?
147 } else {
148 // Multiple texts - call embed_many(model, texts)
149 let texts_vec: Vec<String> = texts.iter().map(|s| s.to_string()).collect();
150 python_instance
151 .call_method(py, "embed_many", (model.clone(), texts_vec), None)
152 .map_err(|e| {
153 GraphBitError::llm(format!("Python embed_many call failed: {e}"))
154 })?
155 };
156
157 // Parse the response
158 self.parse_python_response(py, result)
159 })
160 }
161
162 async fn get_embedding_dimensions(&self) -> GraphBitResult<usize> {
163 // Make a test request to determine dimensions

Callers 1

Calls 5

cloneMethod · 0.80
as_textsMethod · 0.80
lenMethod · 0.80
to_stringMethod · 0.80
parse_python_responseMethod · 0.45

Tested by

no test coverage detected