- Embedded
- Python SDK
- JS/TS
Copy
Ask AI
@classmethod
from_documents(
documents: List[Document],
embedding: Union[str, Embeddings, SentenceTransformer],
**kwargs
) -> CyborgVectorStore
Parameters
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | List of LangChain Document objects |
embedding | Union[str, Embeddings, SentenceTransformer] | Embedding model or model name |
**kwargs | Any | Additional arguments passed to from_texts |
Returns
CyborgVectorStore: Initialized vector store with documents addedExample Usage
Copy
Ask AI
from langchain_core.documents import Document
from cyborgdb_core import DBConfig
# Create documents
documents = [
Document(
page_content="Introduction to natural language processing",
metadata={"source": "nlp_guide.pdf", "page": 1}
),
Document(
page_content="Tokenization and text preprocessing",
metadata={"source": "nlp_guide.pdf", "page": 15}
),
Document(
page_content="Word embeddings and semantic similarity",
metadata={"source": "nlp_guide.pdf", "page": 42}
)
]
# Create store from documents
store = CyborgVectorStore.from_documents(
documents=documents,
embedding="sentence-transformers/all-mpnet-base-v2",
index_name="nlp_documents",
index_key=CyborgVectorStore.generate_key(save=True),
api_key="your-api-key",
index_location=DBConfig("memory"),
config_location=DBConfig("memory")
)
Copy
Ask AI
@classmethod
from_documents(
documents: List[Document],
embedding: Union[str, Embeddings, SentenceTransformer],
**kwargs
) -> CyborgVectorStore
Parameters
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | List of LangChain Document objects |
embedding | Union[str, Embeddings, SentenceTransformer] | Embedding model or model name |
**kwargs | Any | Additional arguments passed to from_texts (includes base_url, api_key, etc.) |
Returns
CyborgVectorStore: Initialized vector store with documents addedExample Usage
Copy
Ask AI
from langchain_core.documents import Document
documents = [
Document(
page_content="Introduction to natural language processing",
metadata={"source": "nlp_guide.pdf", "page": 1}
),
Document(
page_content="Tokenization and text preprocessing",
metadata={"source": "nlp_guide.pdf", "page": 15}
)
]
store = CyborgVectorStore.from_documents(
documents=documents,
embedding="sentence-transformers/all-mpnet-base-v2",
index_name="nlp_documents",
index_key=CyborgVectorStore.generate_key(save=True),
api_key="your-api-key",
base_url="http://localhost:8000"
)
Copy
Ask AI
static fromDocuments(
documents: Document[],
embeddings: EmbeddingsInterface,
config: CyborgVectorStoreConfig
): Promise<CyborgVectorStore>
Parameters
| Parameter | Type | Description |
|---|---|---|
documents | Document[] | Array of LangChain Document objects |
embeddings | EmbeddingsInterface | LangChain embeddings instance |
config | CyborgVectorStoreConfig | Configuration object with baseUrl, apiKey, indexName, indexKey, etc. |
Returns
Promise<CyborgVectorStore>: Initialized vector store with documents addedExample Usage
Copy
Ask AI
import { CyborgVectorStore } from 'cyborgdb';
import { OpenAIEmbeddings } from '@langchain/openai';
import { Document } from '@langchain/core/documents';
const documents = [
new Document({
pageContent: "Introduction to natural language processing",
metadata: { source: "nlp_guide.pdf", page: 1 }
}),
new Document({
pageContent: "Tokenization and text preprocessing",
metadata: { source: "nlp_guide.pdf", page: 15 }
})
];
const store = await CyborgVectorStore.fromDocuments(
documents,
new OpenAIEmbeddings(),
{
baseUrl: "http://localhost:8000",
apiKey: "your-api-key",
indexName: "nlp_documents",
indexKey: CyborgVectorStore.generateKey()
}
);