-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Vector package #2172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Vector package #2172
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a191f55
Extract graphrag-vectors package
natoverse 37bf60c
Merge branch 'v3/main' into vector-package
natoverse 6957a4d
Simplify vector factory usage and config defaults
natoverse 720d9ff
Update factory integ initializers
natoverse 6c8122e
Fix mock patch
natoverse 5183414
Format
natoverse 58883fd
Register vector stores in tests
natoverse 2bce7b8
Set a default vector store name
natoverse 19dc48a
Update vector readme
natoverse 431079f
Remove impls from init
natoverse 212f62d
Move some validation into impls
natoverse 7fa9a90
Remove index_prefix
natoverse 495c071
Move duplicate method to base class
natoverse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # GraphRAG Vectors | ||
|
|
||
| Vector store implementations for GraphRAG. | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ### Using the utility function (recommended) | ||
|
|
||
| ```python | ||
| from graphrag_vectors import ( | ||
| create_vector_store, | ||
| VectorStoreType, | ||
| IndexSchema, | ||
| ) | ||
|
|
||
| # Create a vector store using the convenience function | ||
| store_config = VectorStoreConfig( | ||
| type="lancedb", | ||
| db_uri="lance" | ||
| ) | ||
|
|
||
| schema_config = IndexSchema( | ||
| index_name="my_index", | ||
| vector_size=1536, | ||
| ) | ||
|
|
||
| vector_store = create_vector_store( | ||
| config=store_config | ||
| index_schema=schema_config, | ||
| ) | ||
|
|
||
| vector_store.connect() | ||
| vector_store.create_index() | ||
| ``` | ||
|
|
||
| ### Using the factory directly | ||
|
|
||
| ```python | ||
| from graphrag_vectors import ( | ||
| VectorStoreFactory, | ||
| vector_store_factory, | ||
| VectorStoreType, | ||
| IndexSchema, | ||
| ) | ||
|
|
||
| # Create a vector store using the factory | ||
| schema_config = IndexSchema( | ||
| index_name="my_index", | ||
| vector_size=1536, | ||
| ) | ||
|
|
||
| vector_store = vector_store_factory.create( | ||
| VectorStoreType.LanceDB, | ||
| { | ||
| "index_schema": schema_config, | ||
| "db_uri": "./lancedb" | ||
| } | ||
| ) | ||
|
|
||
| vector_store.connect() | ||
| vector_store.create_index() | ||
| ``` | ||
|
|
||
| ## Supported Vector Stores | ||
|
|
||
| - **LanceDB**: Local vector database | ||
| - **Azure AI Search**: Azure's managed search service with vector capabilities | ||
| - **Azure Cosmos DB**: Azure's NoSQL database with vector search support | ||
|
|
||
| ## Custom Vector Store | ||
|
|
||
| You can register custom vector store implementations: | ||
|
|
||
| ```python | ||
| from graphrag_vectors import VectorStore, register_vector_store, create_vector_store | ||
|
|
||
| class MyCustomVectorStore(VectorStore): | ||
| def __init__(self, my_param): | ||
| self.my_param = my_param | ||
|
|
||
| def connect(self): | ||
| # Implementation | ||
| pass | ||
|
|
||
| def create_index(self): | ||
| # Implementation | ||
| pass | ||
|
|
||
| # ... implement other required methods | ||
|
|
||
| # Register your custom implementation | ||
| register_vector_store("my_custom_store", MyCustomVectorStore) | ||
|
|
||
| # Use your custom vector store | ||
| config = VectorStoreConfig( | ||
| type="my_custom_store", | ||
| my_param="something" | ||
| ) | ||
| custom_store = create_vector_store( | ||
| config=config, | ||
| index_schema=schema_config, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Vector stores are configured using: | ||
| - `VectorStoreConfig`: baseline parameters for the store | ||
| - `IndexSchema`: Schema configuration for the specific index to create/connect to (index name, field names, vector size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright (c) 2024 Microsoft Corporation. | ||
| # Licensed under the MIT License | ||
|
|
||
| """GraphRAG vector store implementations.""" | ||
|
|
||
| from graphrag_vectors.index_schema import IndexSchema | ||
| from graphrag_vectors.types import TextEmbedder | ||
| from graphrag_vectors.vector_store import ( | ||
| VectorStore, | ||
| VectorStoreDocument, | ||
| VectorStoreSearchResult, | ||
| ) | ||
| from graphrag_vectors.vector_store_config import VectorStoreConfig | ||
| from graphrag_vectors.vector_store_factory import ( | ||
| VectorStoreFactory, | ||
| create_vector_store, | ||
| register_vector_store, | ||
| vector_store_factory, | ||
| ) | ||
| from graphrag_vectors.vector_store_type import VectorStoreType | ||
|
|
||
| __all__ = [ | ||
| "IndexSchema", | ||
| "TextEmbedder", | ||
| "VectorStore", | ||
| "VectorStoreConfig", | ||
| "VectorStoreDocument", | ||
| "VectorStoreFactory", | ||
| "VectorStoreSearchResult", | ||
| "VectorStoreType", | ||
| "create_vector_store", | ||
| "register_vector_store", | ||
| "vector_store_factory", | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.